Package org.javers.repository.jql
Class QueryBuilder
java.lang.Object
org.javers.repository.jql.QueryBuilder
Fluent API for building
JqlQuery,
executed with Javers.findChanges(JqlQuery) and Javers.findSnapshots(JqlQuery)-
Method Summary
Modifier and TypeMethodDescriptionandProperty(String propertyName) Deprecated.static QueryBuilderQuery for selecting changes (or snapshots) made on any object.build()Only snapshots committed by a given author.byAuthorLikeIgnoreCase(String authorFragment) Only snapshots committed by a partially matching author name, ignoring case.static QueryBuilderQuery for selecting changes (or snapshots) made on any object (Entity or ValueObject) of given classes.static QueryBuilderbyGlobalId(GlobalIdDTO globalId) Deprecated.static QueryBuilderbyInstance(Object instance) Query for selecting changes (or snapshots) made on a concrete Entity instance.static QueryBuilderbyInstanceId(Object localId, Class entityClass) Query for selecting Changes, Snapshots or Shadows for a given Entity instance.static QueryBuilderbyInstanceId(Object localId, String typeName) Query for selecting Changes, Snapshots or Shadows for a given Entity instance, identified by its type name.static QueryBuilderbyValueObject(Class ownerEntityClass, String path) Query for selecting changes (or snapshots) made on all ValueObjects at given path, owned by any instance of given Entity.static QueryBuilderbyValueObjectId(Object ownerLocalId, Class ownerEntityClass, String path) Query for selecting changes (or snapshots) made on a concrete ValueObject (so a ValueObject owned by a concrete Entity instance).delegates tofrom(LocalDateTime)with MIDNIGHTfrom(LocalDateTime from) Limits to snapshots created after this date or exactly at this date.fromInstant(Instant fromInstant) Limits to snapshots created after this UTC date or exactly at this UTC date.fromVersion(long fromVersion) Only snapshots with a version greater than or equal to (>=) a given version.limit(int limit) Limits the number of Snapshots or Shadows to be fetched from a JaversRepository.skip(int skip) Sets the number of Snapshots or Shadows to skip.
Use skip() and limit() for paging.snapshotQueryLimit(Integer snapshotQueryLimit) Should be changed only to improve performance of Shadow queries. Please do not confused it withlimit(int).delegates toto(LocalDateTime)with MIDNIGHTto(LocalDateTime to) Limits to snapshots created before this date or exactly at this date.toCommitId(CommitId commitId) Only snapshots created before this commit or exactly in this commit.Limits to snapshots created before this UTC date or exactly at this UTC date.toVersion(long toVersion) Only snapshots with a version less than or equal to (<=) a given version.withChangedProperty(String propertyName) Only snapshots with changes on a given property.withChangedPropertyIn(String... propertyNames) Only snapshots with changes on one or more properties from a given list.Only for Snapshot and Changes queries.withChildValueObjects(boolean aggregate) Only for Snapshot and Changes queries, seewithChildValueObjects()withCommitId(BigDecimal commitId) Delegates towithCommitId(CommitId)withCommitId(CommitId commitId) Only snapshots created in a given commit.withCommitIds(Collection<BigDecimal> commitIds) Only snapshots created in given commits.withCommitProperty(String name, String value) Only snapshots with a given commit property.withCommitPropertyIn(String name, Collection<String> values) Only snapshots with a given commit property having any of given values.
Equivalent to SQL clause: WHERE property_value IN ('value1', ...)
If this method is called multiple times, all given conditions must match.withCommitPropertyLike(String name, String valueFragment) Only snapshots with a given commit property partially containing a given value, ignoring case.
Equivalent to SQL clause: WHERE lower(property_value) LIKE lower('%valueFragment%')
If this method is called multiple times -- all given conditions must match.Deprecated.withNewObjectChanges(boolean newObjectChanges) Deprecated.SelectsShadowScope.COMMIT_DEEPfor Shadow queries.Deprecated.withScopeCommitDeepPlus(int maxGapsToFill) Deprecated.renamed towithScopeDeepPlus(int)()}SelectsShadowScope.DEEP_PLUSwithmaxGapsToFilldefaulted to 10.withScopeDeepPlus(int maxGapsToFill) SelectsShadowScope.DEEP_PLUSwith givenmaxGapsToFill.withShadowScope(ShadowScope shadowScope) Choose between shallow, child-value-object, commit-deep or deep+ query scopes.Deprecated.withSnapshotType(SnapshotType snapshotType) Selects only snapshots with a given type: initial, update or terminal.Selects only updating snapshots (without initial ones).withVersion(long version) Only snapshots with a given version.
-
Method Details
-
anyDomainObject
Query for selecting changes (or snapshots) made on any object.
For example, last changes committed on any object can be fetched with:javers.findChanges( QueryBuilder.anyDomainObject().build() );
- Since:
- 2.0
-
byClass
Query for selecting changes (or snapshots) made on any object (Entity or ValueObject) of given classes.
For example, last changes on any object of MyClass.class:javers.findChanges( QueryBuilder.byClass(MyClass.class).build() );
-
byInstanceId
Query for selecting Changes, Snapshots or Shadows for a given Entity instance.
For example, last Changes on "bob" Person:javers.findChanges( QueryBuilder.byInstanceId("bob", Person.class).build() );- Parameters:
localId- Value of an Id-property. When an Entity has Composite-Id (more than one Id-property) —localIdshould beMap<String, Object>with Id-property name to value pairs.- See Also:
-
byInstanceId
Query for selecting Changes, Snapshots or Shadows for a given Entity instance, identified by its type name.
For example, last Changes on "bob" Person:javers.findChanges( QueryBuilder.byInstanceId("bob", "Person").build() );- Parameters:
localId- Value of an Id-property. When an Entity has Composite-Id (more than one Id-property) —localIdshould beMap<String, Object>with Id-property name to value pairs.- See Also:
-
byInstance
Query for selecting changes (or snapshots) made on a concrete Entity instance.
For example, last changes on "bob" Person:javers.findChanges( QueryBuilder.byInstanceId(new Person("bob")).build() ); -
byValueObject
Query for selecting changes (or snapshots) made on all ValueObjects at given path, owned by any instance of given Entity.
See path parameter hints inbyValueObjectId(Object, Class, String). -
byValueObjectId
public static QueryBuilder byValueObjectId(Object ownerLocalId, Class ownerEntityClass, String path) Query for selecting changes (or snapshots) made on a concrete ValueObject (so a ValueObject owned by a concrete Entity instance).
Path parameter is a relative path from owning Entity instance to ValueObject that you are looking for.
When ValueObject is just a property, use propertyName. For example:class Employee { @Id String name; Address primaryAddress; } ... javers.findChanges( QueryBuilder.byValueObjectId("bob", Employee.class, "primaryAddress").build() );When ValueObject is stored in a List, use propertyName and list index separated by "/", for example:class Employee { @Id String name; List<Address> addresses; } ... javers.findChanges( QueryBuilder.byValueObjectId("bob", Employee.class, "addresses/0").build() );When ValueObject is stored as a Map value, use propertyName and map key separated by "/", for example:class Employee { @Id String name; Map<String,Address> addressMap; } ... javers.findChanges( QueryBuilder.byValueObjectId("bob", Employee.class, "addressMap/HOME").build() ); -
byGlobalId
Deprecated. -
withChangedProperty
Only snapshots with changes on a given property.- See Also:
-
withChangedPropertyIn
Only snapshots with changes on one or more properties from a given list.- See Also:
-
withNewObjectChanges
Deprecated.Since Javers 6.0 this method is deprecated and has no effect.
Since Javers 6.0, thenewObjectChangesflag is renamed toinitialChangesand can be set only on a Javers instance level, seeJaversBuilder.withInitialChanges(boolean). -
withNewObjectChanges
Deprecated.Since Javers 6.0 this method is deprecated and has no effect.
Since Javers 6.0, thenewObjectChangesflag is renamed toinitialChangesand can be set only on a Javers instance level, seeJaversBuilder.withInitialChanges(boolean). -
withSnapshotType
Selects only snapshots with a given type: initial, update or terminal.
Typical use case:javers.findSnapshots(QueryBuilder.byClass(SnapshotEntity) .withChangedProperty("someProperty") .withSnapshotTypeUpdate().build()) -
withSnapshotTypeUpdate
Selects only updating snapshots (without initial ones). -
withChildValueObjects
Only for Snapshot and Changes queries, seewithChildValueObjects()- Since:
- 2.1
-
withChildValueObjects
Only for Snapshot and Changes queries. When enabled, selects all child ValueObjects owned by selected Entities.
This switch has no effect on Shadow queries because Shadows are always loaded together with their child ValueObjects (seeShadowScope.CHILD_VALUE_OBJECT).- Since:
- 2.1
- See Also:
-
snapshotQueryLimit
Should be changed only to improve performance of Shadow queries. Please do not confused it withlimit(int).
Works only withJavers.findShadows(JqlQuery)andJavers.findShadowsAndStream(JqlQuery).
Limits the number of Snapshots to be fetched from a JaversRepository in a single DB query
— 100 by default.- Throws:
JaversException- MALFORMED_JQL if used withJavers.findSnapshots(JqlQuery)orJavers.findChanges(JqlQuery)
-
limit
Limits the number of Snapshots or Shadows to be fetched from a JaversRepository. By default, the limit is set to 100.
There are four types of JQL query output: List of Changes, List of Snapshots, Stream of Shadows, and List of Shadows. The limit() filter affects all of them, but in a different way:
Javers.findSnapshots(JqlQuery)—limit()works intuitively, it's the maximum size of a returned list.Javers.findChanges(JqlQuery)—limit()is applied to the Snapshots query, which underlies the Changes query. The size of the returned list can be greater thanlimit(), because, typically a difference between any two Snapshots consists of many atomic Changes.Javers.findShadows(JqlQuery)—limit()is applied to Shadows, it limits the size of the returned list. The underlying Snapshots query uses its own limit —snapshotQueryLimit(Integer). Since one Shadow might be reconstructed from many Snapshots, whensnapshotQueryLimit()is hit, Javers repeats a given Shadow query to load a next frame of Shadows until required limit is reached.-
Javers.findShadowsAndStream(JqlQuery)—limit()works like infindShadows(), it limits the size of the returned stream. The main difference is that the stream is lazy loaded and subsequent frame queries are executed gradually, during the stream consumption.
-
skip
-
from
Limits to snapshots created after this date or exactly at this date.- See Also:
-
fromInstant
Limits to snapshots created after this UTC date or exactly at this UTC date. -
to
Limits to snapshots created before this date or exactly at this date. -
toInstant
Limits to snapshots created before this UTC date or exactly at this UTC date. -
withCommitId
Only snapshots created in a given commit. -
withCommitId
Delegates towithCommitId(CommitId) -
withCommitIds
Only snapshots created in given commits. -
toCommitId
Only snapshots created before this commit or exactly in this commit. -
from
delegates tofrom(LocalDateTime)with MIDNIGHT -
to
delegates toto(LocalDateTime)with MIDNIGHT -
withCommitProperty
Only snapshots with a given commit property.
If this method is called multiple times, all given conditions must match. -
withCommitPropertyIn
Only snapshots with a given commit property having any of given values.
Equivalent to SQL clause: WHERE property_value IN ('value1', ...)
If this method is called multiple times, all given conditions must match. -
withCommitPropertyLike
Only snapshots with a given commit property partially containing a given value, ignoring case.
Equivalent to SQL clause: WHERE lower(property_value) LIKE lower('%valueFragment%')
If this method is called multiple times -- all given conditions must match. -
withVersion
Only snapshots with a given version.- See Also:
-
fromVersion
Only snapshots with a version greater than or equal to (>=) a given version.- See Also:
-
toVersion
Only snapshots with a version less than or equal to (<=) a given version.- See Also:
-
withShadowScope
Choose between shallow, child-value-object, commit-deep or deep+ query scopes.
The wider the scope, the more object shadows are loaded to the resulting graph.
Default scope isShadowScope.SHALLOW.
Read more about query scopes inJavers.findShadows(JqlQuery)javadoc.
Only for Shadow queries.- Since:
- 3.2
- See Also:
-
withScopeCommitDeep
SelectsShadowScope.COMMIT_DEEPfor Shadow queries.
Read about query scopes inJavers.findShadows(JqlQuery)javadoc.- Since:
- 3.5
- See Also:
-
withScopeDeepPlus
SelectsShadowScope.DEEP_PLUSwithmaxGapsToFilldefaulted to 10.
Read more about query scopes inJavers.findShadows(JqlQuery)javadoc.
Only for Shadow queries.- Since:
- 3.5
- See Also:
-
withScopeDeepPlus
SelectsShadowScope.DEEP_PLUSwith givenmaxGapsToFill.
Read more about Shadow query scopes, profiling, and runtime statistics inJavers.findShadows(JqlQuery)javadoc.
Only for Shadow queries.- Parameters:
maxGapsToFill- Limits the number of referenced entity Shadows to be eagerly loaded. The limit is global for a query. When it is exceeded, references to other entities are nulled. Collections of entities may not be fully loaded.- Since:
- 3.5
- See Also:
-
withScopeCommitDeepPlus
Deprecated.renamed towithScopeDeepPlus()()} -
withScopeCommitDeepPlus
Deprecated.renamed towithScopeDeepPlus(int)()} -
byAuthor
Only snapshots committed by a given author.- Since:
- 2.0
-
byAuthorLikeIgnoreCase
Only snapshots committed by a partially matching author name, ignoring case.
Equivalent to SQL clause: WHERE lower(author) LIKE lower('%authorFragment%') -
build
-
withShadowScopeDeep
Deprecated.renamed towithScopeCommitDeep() -
andProperty
Deprecated.renamed towithChangedProperty(String)
-
withScopeDeepPlus()()}