public class JaversBuilder extends AbstractContainerBuilder
Javers javers = JaversBuilder.javers().build();To build a JaVers instance with Entity type registered:
Javers javers = JaversBuilder.javers() .registerEntity(MyEntity.class) .build();
Modifier and Type | Field | Description |
---|---|---|
static org.slf4j.Logger |
logger |
Modifier | Constructor | Description |
---|---|---|
protected |
JaversBuilder() |
use static factory method
javers() |
Modifier and Type | Method | Description |
---|---|---|
protected Javers |
assembleJaversInstance() |
|
Javers |
build() |
|
static JaversBuilder |
javers() |
|
<T> JaversBuilder |
registerCustomComparator(CustomPropertyComparator<T,?> comparator,
java.lang.Class<T> customType) |
Registers a custom property comparator for a given Custom Type.
|
JaversBuilder |
registerEntities(java.lang.Class<?>... entityClasses) |
|
JaversBuilder |
registerEntity(java.lang.Class<?> entityClass) |
Registers an
EntityType . |
JaversBuilder |
registerEntity(EntityDefinition entityDefinition) |
Registers an
EntityType . |
JaversBuilder |
registerIgnoredClass(java.lang.Class<?> ignoredClass) |
Marks given class as ignored by JaVers.
|
JaversBuilder |
registerJaversRepository(JaversRepository repository) |
|
JaversBuilder |
registerJsonAdvancedTypeAdapter(JsonAdvancedTypeAdapter adapter) |
INCUBATING
For complex structures like Multimap |
JaversBuilder |
registerType(ClientsClassDefinition clientsClassDefinition) |
Generic version of
registerEntity(EntityDefinition) and
registerValueObject(ValueObjectDefinition) |
JaversBuilder |
registerValue(java.lang.Class<?> valueClass) |
Registers a simple value type (see
ValueType ). |
<T> JaversBuilder |
registerValue(java.lang.Class<T> valueClass,
CustomValueComparator<T> customValueComparator) |
Registers a
ValueType with a custom comparator to be used instead of
default Object.equals(Object) . |
JaversBuilder |
registerValueGsonTypeAdapter(java.lang.Class valueType,
com.google.gson.TypeAdapter nativeAdapter) |
|
JaversBuilder |
registerValueObject(java.lang.Class<?> valueObjectClass) |
Registers a
ValueObjectType . |
JaversBuilder |
registerValueObject(ValueObjectDefinition valueObjectDefinition) |
Registers a
ValueObjectType . |
JaversBuilder |
registerValueObjects(java.lang.Class<?>... valueObjectClasses) |
|
JaversBuilder |
registerValueTypeAdapter(JsonTypeAdapter typeAdapter) |
Registers a
ValueType and its custom JSON adapter. |
<T> JaversBuilder |
registerValueWithCustomToString(java.lang.Class<T> valueClass,
java.util.function.Function<T,java.lang.String> toString) |
For complex
ValueType classes that are used as Entity Id. |
JaversBuilder |
scanTypeName(java.lang.Class userType) |
Register your class with @
TypeName annotation
in order to use it in all kinds of JQL queries. |
JaversBuilder |
withCommitIdGenerator(CommitIdGenerator commitIdGenerator) |
CommitIdGenerator.SYNCHRONIZED_SEQUENCE — for non-distributed applications
CommitIdGenerator.RANDOM — for distributed applications
SYNCHRONIZED_SEQUENCE is used by default. |
JaversBuilder |
withDateTimeProvider(DateProvider dateProvider) |
DateProvider providers current util for
Commit.getCommitDate() . |
JaversBuilder |
withListCompareAlgorithm(ListCompareAlgorithm algorithm) |
Choose between two algorithms for comparing list: ListCompareAlgorithm.SIMPLE
or ListCompareAlgorithm.LEVENSHTEIN_DISTANCE.
|
JaversBuilder |
withMappingStyle(MappingStyle mappingStyle) |
Default style is
MappingStyle.FIELD . |
JaversBuilder |
withNewObjectsSnapshot(boolean newObjectsSnapshot) |
When enabled,
Javers.compare(Object oldVersion, Object currentVersion)
generates additional 'Snapshots' of new objects (objects added in currentVersion graph). |
JaversBuilder |
withObjectAccessHook(ObjectAccessHook objectAccessHook) |
|
JaversBuilder |
withPackagesToScan(java.lang.String packagesToScan) |
Comma separated list of packages.
Allows you to registerType all your classes with @ TypeName annotation
in order to use them in all kinds of JQL queries(without getting TYPE_NAME_NOT_FOUND exception). |
JaversBuilder |
withPrettyPrint(boolean prettyPrint) |
choose between JSON pretty or concise printing style, i.e.
|
JaversBuilder |
withPrettyPrintDateFormats(JaversCoreProperties.PrettyPrintDateFormats prettyPrintDateFormats) |
|
JaversBuilder |
withProperties(JaversCoreProperties javersProperties) |
|
JaversBuilder |
withTypeSafeValues(boolean typeSafeValues) |
Switch on when you need a type safe serialization for
heterogeneous collections like List, List<Object>.
|
addComponent, addModule, addModule, bindComponent, bootContainer, getComponents, getContainer, getContainerComponent, removeComponent
protected JaversBuilder()
javers()
public static JaversBuilder javers()
public Javers build()
protected Javers assembleJaversInstance()
public JaversBuilder registerJaversRepository(JaversRepository repository)
public JaversBuilder registerEntity(java.lang.Class<?> entityClass)
EntityType
. DiffIgnore
annotations to mark ignored properties.
public JaversBuilder registerValueObject(java.lang.Class<?> valueObjectClass)
ValueObjectType
. DiffIgnore
annotations to mark ignored properties.
public JaversBuilder registerEntity(EntityDefinition entityDefinition)
EntityType
. Entity
annotation.
EntityDefinition
is EntityDefinitionBuilder
,
for example:
javersBuilder.registerEntity( EntityDefinitionBuilder.entityDefinition(Person.class) .withIdPropertyName("id") .withTypeName("Person") .withIgnoredProperties("notImportantProperty","transientProperty") .build());For simple cases, you can use
EntityDefinition
constructors,
for example:
javersBuilder.registerEntity( new EntityDefinition(Person.class, "login") );
public JaversBuilder registerType(ClientsClassDefinition clientsClassDefinition)
registerEntity(EntityDefinition)
and
registerValueObject(ValueObjectDefinition)
public JaversBuilder registerValueObject(ValueObjectDefinition valueObjectDefinition)
ValueObjectType
. ValueObject
annotations.
ValueObjectDefinition
is ValueObjectDefinitionBuilder
.
For example:
javersBuilder.registerValueObject(ValueObjectDefinitionBuilder.valueObjectDefinition(Address.class) .withIgnoredProperties(ignoredProperties) .withTypeName(typeName) .build();For simple cases, you can use
ValueObjectDefinition
constructors,
for example:
javersBuilder.registerValueObject( new ValueObjectDefinition(Address.class, "ignored") );
public JaversBuilder withPackagesToScan(java.lang.String packagesToScan)
TypeName
annotation
in order to use them in all kinds of JQL queriespackagesToScan
- e.g. "my.company.domain.person, my.company.domain.finance"public JaversBuilder scanTypeName(java.lang.Class userType)
TypeName
annotation
in order to use it in all kinds of JQL queries.
withPackagesToScan(String)
to scan all your classes.
Javers.getTypeMapping(Type)
public JaversBuilder registerValue(java.lang.Class<?> valueClass)
ValueType
).
Value
annotation.
Object.equals(Object)
.
If you don't want to use it,
registerType a custom value comparator with registerValue(Class, CustomValueComparator)
.public <T> JaversBuilder registerValue(java.lang.Class<T> valueClass, CustomValueComparator<T> customValueComparator)
ValueType
with a custom comparator to be used instead of
default Object.equals(Object)
.
Object.hashCode()
,
it is not used when given Value type is:
BigDecimal.equals(Object)
.
If you want to compare them in the smarter way, ignoring trailing zeros:
javersBuilder.registerValue(BigDecimal.class, (a,b) -> a.compareTo(b) == 0);
public <T> JaversBuilder registerValueWithCustomToString(java.lang.Class<T> valueClass, java.util.function.Function<T,java.lang.String> toString)
ValueType
classes that are used as Entity Id.
toString
function that will be used for creating
GlobalId
for Entities,
instead of default ReflectionUtil.reflectiveToString(Object)
.
class Entity { @Id Point id String data } class Point { double x double y String myToString() { "("+ (int)x +"," +(int)y + ")" } } def "should use custom toString function for complex Id"(){ given: Entity entity = new Entity( id: new Point(x: 1/3, y: 4/3)) when: "default reflectiveToString function" def javers = JaversBuilder.javers().build() GlobalId id = javers.getTypeMapping(Entity).createIdFromInstance(entity) then: id.value() == "com.mypackage.Entity/0.3333333333,1.3333333333" when: "custom toString function" javers = JaversBuilder.javers() .registerValueWithCustomToString(Point, {it.myToString()}).build() id = javers.getTypeMapping(Entity).createIdFromInstance(entity) then: id.value() == "com.mypackage.Entity/(0,1)" }For
ValueType
you can register both
custom toString
function and CustomValueComparator
.toString
- should return String value of a given objectValueType
,
registerValue(Class, CustomValueComparator)
public JaversBuilder registerIgnoredClass(java.lang.Class<?> ignoredClass)
DiffIgnore
annotation.DiffIgnore
public JaversBuilder registerValueTypeAdapter(JsonTypeAdapter typeAdapter)
ValueType
and its custom JSON adapter.
public JaversBuilder registerJsonAdvancedTypeAdapter(JsonAdvancedTypeAdapter adapter)
public JaversBuilder registerValueGsonTypeAdapter(java.lang.Class valueType, com.google.gson.TypeAdapter nativeAdapter)
ValueType
and its custom native
Gson adapter.
TypeAdapter
s implemented.TypeAdapter
public JaversBuilder withTypeSafeValues(boolean typeSafeValues)
typeSafeValues
- default falseJsonConverterBuilder.typeSafeValues(boolean)
public JaversBuilder withPrettyPrint(boolean prettyPrint)
{ "value": 5 }
{"value":5}
prettyPrint
- default truepublic JaversBuilder registerEntities(java.lang.Class<?>... entityClasses)
public JaversBuilder registerValueObjects(java.lang.Class<?>... valueObjectClasses)
public JaversBuilder withMappingStyle(MappingStyle mappingStyle)
MappingStyle.FIELD
.public JaversBuilder withCommitIdGenerator(CommitIdGenerator commitIdGenerator)
CommitIdGenerator.SYNCHRONIZED_SEQUENCE
— for non-distributed applications
CommitIdGenerator.RANDOM
— for distributed applications
public JaversBuilder withNewObjectsSnapshot(boolean newObjectsSnapshot)
Javers.compare(Object oldVersion, Object currentVersion)
generates additional 'Snapshots' of new objects (objects added in currentVersion graph).
public JaversBuilder withObjectAccessHook(ObjectAccessHook objectAccessHook)
public <T> JaversBuilder registerCustomComparator(CustomPropertyComparator<T,?> comparator, java.lang.Class<T> customType)
CustomType
.T
- Custom TypeCustomType
,
CustomPropertyComparator
public JaversBuilder withListCompareAlgorithm(ListCompareAlgorithm algorithm)
algorithm
- ListCompareAlgorithm.SIMPLE is used by defaultpublic JaversBuilder withDateTimeProvider(DateProvider dateProvider)
Commit.getCommitDate()
.
public JaversBuilder withPrettyPrintDateFormats(JaversCoreProperties.PrettyPrintDateFormats prettyPrintDateFormats)
public JaversBuilder withProperties(JaversCoreProperties javersProperties)