public interface Javers
JaversBuilder provided with your domain model configuration.
Javers javers = JaversBuilder.javers().build(); Diff diff = javers.compare(oldVersion, currentVersion);
| Modifier and Type | Method and Description |
|---|---|
Commit |
commit(java.lang.String author,
java.lang.Object currentVersion)
Persists a current state of a given domain object graph
in JaVers repository.
|
Commit |
commitShallowDelete(java.lang.String author,
java.lang.Object deleted)
Marks given object as deleted.
|
Commit |
commitShallowDeleteById(java.lang.String author,
GlobalIdDTO globalId)
The same like
commitShallowDelete(String,Object)
but deleted object is selected using globalId |
Diff |
compare(java.lang.Object oldVersion,
java.lang.Object currentVersion)
JaVers core function,
deeply compares two arbitrary complex object graphs.
|
java.util.List<Change> |
findChanges(JqlQuery query)
Queries JaversRepository for changes history (diff sequence) of given class, object or property.
|
java.util.List<CdoSnapshot> |
findSnapshots(JqlQuery query)
Queries JaversRepository for object Snapshots (historical versions).
|
java.util.List<Change> |
getChangeHistory(GlobalIdDTO globalId,
int limit)
Deprecated.
|
JsonConverter |
getJsonConverter()
If you are serializing JaVers objects like
Commit, Change, Diff or CdoSnapshot to JSON, use this JsonConverter. |
Optional<CdoSnapshot> |
getLatestSnapshot(GlobalIdDTO globalId)
Deprecated.
|
Optional<CdoSnapshot> |
getLatestSnapshot(java.lang.Object localId,
java.lang.Class entityClass)
Latest snapshot of given entity instance
or Optional#EMPTY if instance is not versioned.
|
java.util.List<CdoSnapshot> |
getStateHistory(GlobalIdDTO globalId,
int limit)
Deprecated.
|
JaversType |
getTypeMapping(java.lang.Class<?> clazz) |
IdBuilder |
idBuilder() |
Diff |
initial(java.lang.Object newDomainObject)
Initial diff is a kind of snapshot of given domain object 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)
Deprecated.
|
Commit commit(java.lang.String author, java.lang.Object currentVersion)
currentVersion - standalone object or handle to an object graphCommit commitShallowDelete(java.lang.String author, java.lang.Object deleted)
commit(String, Object), this method is shallow
and affects only given object.
deleted - object to be marked as deletedCommit commitShallowDeleteById(java.lang.String author, GlobalIdDTO globalId)
commitShallowDelete(String,Object)
but deleted object is selected using globalIdDiff compare(java.lang.Object oldVersion, java.lang.Object currentVersion)
JaVers core function, deeply compares two arbitrary complex object graphs.
To calculate a diff, just provide two versions of the
same object or handles to two versions of the same object graph.
The handle could be a root of an aggregate, tree root
or any node in an object 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).
Diff initial(java.lang.Object newDomainObject)
compare(Object, Object)java.util.List<Change> findChanges(JqlQuery query)
ValueChange, ReferenceChange, ListChange, NewObject and so on. Change class hierarchy.
javers.findChanges( QueryBuilder.byInstanceId("bob", Person.class).limit(5).build() );
Last "salary" changes of "bob" Person:
javers.findChanges( QueryBuilder.byInstanceId("bob", Person.class).andProperty("salary").build() );
Querying for ValueObject changes
javers.findChanges( QueryBuilder.byValueObjectId("bob", Person.class, "address").build() );
Last changes on Address ValueObject owned by any Person:
javers.findChanges( QueryBuilder.byValueObject(Person.class, "address").build() );Querying for any object changes by its class
javers.findChanges( QueryBuilder.byClass(MyClass.class).build() );Last "myProperty" changes on any object of MyClass.class:
javers.findChanges( QueryBuilder.byClass(Person.class).andProperty("myProperty").build() );
java.util.List<CdoSnapshot> findSnapshots(JqlQuery query)
javers.findSnapshots( QueryBuilder.byInstanceId("bob", Person.class).limit(5).build() );
For more query examples, see findChanges(JqlQuery) method.
Both methods use Javers Query Language (JQL).
So you can use the same query object to get changes and snapshots views.Optional<CdoSnapshot> getLatestSnapshot(java.lang.Object localId, java.lang.Class entityClass)
javers.getLatestSnapshot("bob", Person.class));
JsonConverter getJsonConverter()
Commit, Change, Diff or CdoSnapshot to JSON, use this JsonConverter.
For example:
javers.getJsonConverter().toJson(changes);
<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.calculateDiffs(...); String changeLog = javers.processChangeList(changes, new SimpleTextChangeLog()); System.out.println( changeLog );
SimpleTextChangeLog@Deprecated java.lang.String toJson(Diff diff)
javers.getJsonConverter().toJson(diff);
@Deprecated java.util.List<CdoSnapshot> getStateHistory(GlobalIdDTO globalId, int limit)
@Deprecated java.util.List<Change> getChangeHistory(GlobalIdDTO globalId, int limit)
@Deprecated Optional<CdoSnapshot> getLatestSnapshot(GlobalIdDTO globalId)
JaversType getTypeMapping(java.lang.Class<?> clazz)
IdBuilder idBuilder()