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)
Deep compare
JaVers core function,
deeply compares two arbitrary complex object graphs.
|
<T> Diff |
compareCollections(java.util.Collection<T> oldVersion,
java.util.Collection<T> currentVersion,
java.lang.Class<T> itemClass)
Deeply compares two collections.
|
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.
|
<T extends JaversType> |
getTypeMapping(java.lang.reflect.Type clientsType)
Use JaversTypes, if you want to:
- describe your class in the context of JaVers domain model mapping, - use JaVers Reflection API to conveniently access your object properties (instead of awkward java.lang.reflect API). |
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)
To calculate a diff, just provide two versions of the
same Domain Object (Entity or ValueObject)
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 Domain Object graph from where all other nodes are navigable.
Object.equals(Object). compare() 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) or pretty-printed with Diff.prettyPrint()
<T> Diff compareCollections(java.util.Collection<T> oldVersion, java.util.Collection<T> currentVersion, java.lang.Class<T> itemClass)
compare(Object, Object).
List<Person> oldList = ... List<Person> newList = ... Diff diff = javers.compareCollections(oldList, newList, Person.class);
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.
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)
<T extends JaversType> T getTypeMapping(java.lang.reflect.Type clientsType)
class Person {
@Id int id;
@Transient String notImportantField;
String name;
}
Calling
System.out.println( javers.getTypeMapping(Person.class).prettyPrint() );prints:
EntityType{
baseType: org.javers.core.examples.Person
managedProperties:
Field int id; //declared in: Person
Field String name; //declared in: Person
idProperty: login
}
Property access example.
You can list object property values using Property abstraction.
Javers javers = JaversBuilder.javers().build();
ManagedType jType = javers.getTypeMapping(Person.class);
Person person = new Person("bob", "Uncle Bob");
System.out.println("Bob's properties:");
for (Property p : jType.getProperties()){
Object value = p.get(person);
System.out.println( "property:" + p.getName() + ", value:" + value );
}
prints:
Bob's properties: property:login, value:bob property:name, value:Uncle Bob
IdBuilder idBuilder()