public class Javers
extends java.lang.Object
JaversBuilder provided with your domain model configuration.
Javers javers = JaversBuilder.javers().build(); Diff diff = javers.compare(oldVersion, currentVersion);
| Constructor and Description |
|---|
Javers(DiffFactory diffFactory,
TypeMapper typeMapper,
JsonConverter jsonConverter,
CommitFactory commitFactory,
JaversExtendedRepository repository,
SnapshotDiffer snapshotDiffer)
JaVers instance should be constructed by
JaversBuilder |
| Modifier and Type | Method and Description |
|---|---|
Commit |
commit(java.lang.String author,
java.lang.Object currentVersion)
Persists current version of given domain object in JaVers repository.
|
Diff |
compare(java.lang.Object oldVersion,
java.lang.Object currentVersion)
JaVers core function,
deeply compares two arbitrary complex objects graphs.
|
java.util.List<Change> |
getChangeHistory(GlobalIdDTO globalId,
int limit)
Changes history (diff sequence) of given object,
in reverse chronological order.
|
JsonConverter |
getJsonConverter() |
Optional<CdoSnapshot> |
getLatestSnapshot(GlobalIdDTO globalId)
Latest snapshot of given object
or Optional#EMPTY if object is not versioned.
|
java.util.List<CdoSnapshot> |
getStateHistory(GlobalIdDTO globalId,
int limit)
Snapshots (historical versions) of given object,
in reverse chronological order.
|
IdBuilder |
idBuilder() |
Diff |
initial(java.lang.Object newDomainObject)
Initial diff is a kind of snapshot of given domain objects graph.
|
<T> T |
processChangeList(java.util.List<Change> changes,
ChangeProcessor<T> changeProcessor)
Generic purpose method for processing a changes list.
|
java.lang.String |
toJson(Diff diff)
Diff serialized to pretty JSON, useful if you are not using
JaversRepository |
public Javers(DiffFactory diffFactory, TypeMapper typeMapper, JsonConverter jsonConverter, CommitFactory commitFactory, JaversExtendedRepository repository, SnapshotDiffer snapshotDiffer)
JaversBuilderpublic Commit commit(java.lang.String author, java.lang.Object currentVersion)
Persists current version of given domain object in JaVers repository. JaVers applies commit() to given object and all objects navigable from it. You can capture state of arbitrary complex objects graph with single commit() call.
currentVersion - Standalone object or handle to objects graphpublic Diff compare(java.lang.Object oldVersion, java.lang.Object currentVersion)
JaVers core function, deeply compares two arbitrary complex objects graphs.
To calculate diff, just provide two versions of the
same object or handles to two versions of the same objects graph.
The handle could be a root of an aggregate, tree root
or any node in an objects graph from where all other nodes are navigable.
This function is used for ad-hoc objects comparing.
In order to use data auditing feature, call commit(String, Object).
Diffs can be converted to JSON with toJson(Diff).
public Diff initial(java.lang.Object newDomainObject)
compare(Object, Object)public java.lang.String toJson(Diff diff)
JaversRepositorypublic IdBuilder idBuilder()
public java.util.List<CdoSnapshot> getStateHistory(GlobalIdDTO globalId, int limit)
javers.getStateHistory(InstanceIdDTO.instanceId("bob", Person.class), 5);
globalId - given object IDlimit - choose reasonable limitpublic Optional<CdoSnapshot> getLatestSnapshot(GlobalIdDTO globalId)
javers.getStateHistory(InstanceIdDTO.instanceId("bob", Person.class), 5);
public java.util.List<Change> getChangeHistory(GlobalIdDTO globalId, int limit)
javers.getChangeHistory(InstanceIdDTO.instanceId("bob", Person.class), 5);
globalId - given object IDlimit - choose reasonable limitpublic JsonConverter getJsonConverter()
public <T> T processChangeList(java.util.List<Change> changes, ChangeProcessor<T> changeProcessor)
ChangeProcessor.result().
ChangeProcessor.onCommit(CommitMetadata)
is called only for first occurrence ChangeProcessor.onAffectedObject(GlobalId)
is called only for first occurrence
List<Change> changes = javers.getChangeHistory(...); String changeLog = javers.processChangeList(changes, new SimpleTextChangeLog()); System.out.println( changeLog );
SimpleTextChangeLog