我正在使用javer 3.10.0。我有一个类型为A的实体对象,该对象在Javers上提交保存类型为B的片段。
class A {
List<B> b;
}
class B {
String status;
List<C> typeCList;
}
对于列表比较算法,我正在使用AS_SET。 现在假设我的列表已经有5个类型B的值 在列表中添加新的(第6个)值时,Javers将为B类型的片段保存6个快照(添加5个更新,并添加1个),但是对于5个更新,差异日志中没有变化。 在检查源代码时,对于所有5个旧快照,ChangedCdoSnapshotsFactory :: isCdoChanged返回true,因为所有旧快照均具有UnmodifiableSet,而新快照的TypeCList具有ValueObject的ArrayList
现在为什么差异日志和快照有区别?即使没有更改,这也会创建快照。
如果没有如下所示的差异日志,我们也可以删除更改的快照
public Commit create(String author, Map<String, String> properties, Object currentVersion){
Validate.argumentsAreNotNull(author, currentVersion);
CommitMetadata commitMetadata = newCommitMetadata(author, properties);
LiveGraph currentGraph = liveGraphFactory.createLiveGraph(currentVersion);
ObjectGraph<CdoSnapshot> latestSnapshotGraph = snapshotGraphFactory.createLatest(currentGraph.globalIds());
List<CdoSnapshot> changedCdoSnapshots =
changedCdoSnapshotsFactory.create(currentGraph.cdos(), latestSnapshotGraph.cdos(), commitMetadata);
Diff diff = diffFactory.create(latestSnapshotGraph, currentGraph, Optional.of(commitMetadata));
// Removing changed snapshot if there is no change in the diff
Set<GlobalId> changedGlobalIds = diff.getChanges().stream().map(c -> c.getAffectedGlobalId()).collect(Collectors.toSet());
Iterator<CdoSnapshot> iterator = changedCdoSnapshots.iterator();
while (iterator.hasNext()) {
CdoSnapshot changedSnapshot = iterator.next();
if (!changedGlobalIds.contains(changedSnapshot.getGlobalId())) {
iterator.remove();
}
}
return new Commit(commitMetadata, changedCdoSnapshots, diff);
}