Вы можете достичь этого в Javers, если вы отобразите Page
class как ValueObject
, а затем, если будете использовать Shadow query.Также вы должны фиксировать Document
все время:
@Entity
class Document {
@Id String name
@OneToMany List<Page> pages
@Override
String toString() {
"Document $name, pages:$pages"
}
}
@org.javers.core.metamodel.annotation.ValueObject
@Entity
@ToString
class Page {
@Id Long number
@ManyToOne Document document
String header
@Override
String toString() {
"Page $number, $header"
}
}
def "should treat Document as aggregate"(){
given:
def javers = JaversBuilder.javers().build()
def doc = new Document(name:"1", pages: [new Page(header:"a"), new Page(header:"b")])
javers.commit("author", doc)
when:
doc = new Document(name:"1", pages: [new Page(header:"a"), new Page(header:"ccc")])
javers.commit("author", doc)
def shadows = javers.findShadows(QueryBuilder.byClass(Document).build())
then:
shadows
shadows.forEach{s -> println(s.commitMetadata.commitDate.toString() + " " + s.get())}
}
вывод:
23:25:47.297 [main] INFO org.javers.core.Javers - Commit(id:1.0, snapshots:3, author:author, changes - NewObject:3), done in 56 millis (diff:45, persist:11)
23:25:47.315 [main] INFO org.javers.core.Javers - Commit(id:2.0, snapshots:1, author:author, changes - ValueChange:1), done in 17 millis (diff:17, persist:0)
23:25:47.337 [main] DEBUG org.javers.JQL - SHALLOW query: 4 snapshots loaded (entities: 1, valueObjects: 3)
23:25:47.358 [main] DEBUG org.javers.JQL - queryForShadows executed:
2019-04-08T23:25:47.298618 Document 1, pages:[Page null, a, Page null, ccc]
2019-04-08T23:25:47.275570 Document 1, pages:[Page null, a, Page null, b]