Interface JdbcAggregateOperations
- All Known Implementing Classes:
JdbcAggregateTemplate
public interface JdbcAggregateOperations
Specifies operations one can perform on a database, based on an Domain Type.
- Author:
- Jens Schauder, Thomas Lang, Milan Milanov, Chirag Tailor, Diego Krupitza, Myeonghyeon Lee, Sergey Korotaev
-
Method Summary
Modifier and TypeMethodDescriptionlong
Counts the number of aggregates of a given type.<T> long
Counts the number of aggregates of a given type that match the givenquery
.<T> void
delete
(T aggregateRoot) Delete an aggregate identified by its aggregate root.void
Delete all aggregates of a given type.<T> void
Delete all aggregates identified by their aggregate roots.<T> void
deleteAllById
(Iterable<?> ids, Class<T> domainType) Deletes all aggregates identified by their aggregate root ids.<T> void
deleteById
(Object id, Class<T> domainType) Deletes a single Aggregate including all entities contained in that aggregate.<T> boolean
Determine whether there are aggregates that match theQuery
<T> boolean
existsById
(Object id, Class<T> domainType) Checks if an aggregate identified by type and id exists in the database.<T> List<T>
Load all aggregates of a given type.<T> Page<T>
Load a page of (potentially sorted) aggregates of a given type.<T> List<T>
Load all aggregates of a given type, sorted.<T> List<T>
Execute aSELECT
query and convert the resulting items to aList
that is sorted.<T> Page<T>
<T> List<T>
findAllById
(Iterable<?> ids, Class<T> domainType) Load all aggregates of a given type that are identified by the given ids.<T> T
Load an aggregate from the database.<T> Optional<T>
Execute aSELECT
query and convert the resulting item to an entity ensuring exactly one result.<T> T
insert
(T instance) Dedicated insert function.<T> Iterable<T>
Inserts all aggregate instances, including all the members of each aggregate instance.<T> T
save
(T instance) Saves an instance of an aggregate, including all the members of the aggregate.<T> List<T>
Saves all aggregate instances, including all the members of each aggregate instance.<T> Stream<T>
Load all aggregates of a given type to aStream
.<T> Stream<T>
Loads all entities of the given type to aStream
, sorted.<T> Stream<T>
Execute aSELECT
query and convert the resulting items to aStream
.<T> Stream<T>
streamAllByIds
(Iterable<?> ids, Class<T> domainType) Loads all entities that match one of the ids passed as an argument to aStream
.<T> T
update
(T instance) Dedicated update function.<T> List<T>
Updates all aggregate instances, including all the members of each aggregate instance.
-
Method Details
-
save
<T> T save(T instance) Saves an instance of an aggregate, including all the members of the aggregate.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instance
- the aggregate root of the aggregate to be saved. Must not benull
.- Returns:
- the saved instance.
- Throws:
IncorrectUpdateSemanticsDataAccessException
- when the instance is determined to be not new and the resulting update does not update any rows.
-
saveAll
Saves all aggregate instances, including all the members of each aggregate instance.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instances
- the aggregate roots to be saved. Must not benull
.- Returns:
- the saved instances.
- Throws:
IncorrectUpdateSemanticsDataAccessException
- when at least one instance is determined to be not new and the resulting update does not update any rows.- Since:
- 3.0
-
insert
<T> T insert(T instance) Dedicated insert function. This skips the test if the aggregate root is new and makes an insert.This is useful if the client provides an id for new aggregate roots.
- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instance
- the aggregate root of the aggregate to be inserted. Must not benull
.- Returns:
- the saved instance.
-
insertAll
Inserts all aggregate instances, including all the members of each aggregate instance.This is useful if the client provides an id for new aggregate roots.
- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instances
- the aggregate roots to be inserted. Must not benull
.- Returns:
- the saved instances.
- Since:
- 3.1
-
update
<T> T update(T instance) Dedicated update function. This skips the test if the aggregate root is new or not and always performs an update operation.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instance
- the aggregate root of the aggregate to be inserted. Must not benull
.- Returns:
- the saved instance.
-
updateAll
Updates all aggregate instances, including all the members of each aggregate instance.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
instances
- the aggregate roots to be inserted. Must not benull
.- Returns:
- the saved instances.
- Since:
- 3.1
-
count
Counts the number of aggregates of a given type.- Parameters:
domainType
- the type of the aggregates to be counted.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null
.
-
count
Counts the number of aggregates of a given type that match the givenquery
.- Parameters:
query
- must not be null.domainType
- the entity type must not be null.- Returns:
- the number of instances stored in the database. Guaranteed to be not
null
. - Since:
- 3.0
-
exists
Determine whether there are aggregates that match theQuery
- Parameters:
query
- must not be null.domainType
- the entity type must not be null.- Returns:
- true if the object exists.
- Since:
- 3.0
-
existsById
Checks if an aggregate identified by type and id exists in the database.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
id
- the id of the aggregate root.domainType
- the type of the aggregate root.- Returns:
- whether the aggregate exists.
-
findById
Load an aggregate from the database.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
id
- the id of the aggregate to load. Must not benull
.domainType
- the type of the aggregate root. Must not benull
.- Returns:
- the loaded aggregate. Might return
null
.
-
findAllById
Load all aggregates of a given type that are identified by the given ids.- Type Parameters:
T
- the type of the aggregate roots. Must not benull
.- Parameters:
ids
- of the aggregate roots identifying the aggregates to load. Must not benull
.domainType
- the type of the aggregate roots. Must not benull
.- Returns:
- Guaranteed to be not
null
.
-
streamAllByIds
Loads all entities that match one of the ids passed as an argument to aStream
. It is not guaranteed that the number of ids passed in matches the number of entities returned.- Type Parameters:
T
- type of entities to load.- Parameters:
ids
- the Ids of the entities to load. Must not benull
.domainType
- the type of entities to load. Must not benull
.- Returns:
- the loaded entities. Guaranteed to be not
null
.
-
findAll
Load all aggregates of a given type.- Type Parameters:
T
- the type of the aggregate roots. Must not benull
.- Parameters:
domainType
- the type of the aggregate roots. Must not benull
.- Returns:
- Guaranteed to be not
null
.
-
streamAll
Load all aggregates of a given type to aStream
.- Type Parameters:
T
- the type of the aggregate roots. Must not benull
.- Parameters:
domainType
- the type of the aggregate roots. Must not benull
.- Returns:
- Guaranteed to be not
null
.
-
findAll
Load all aggregates of a given type, sorted.- Type Parameters:
T
- the type of the aggregate roots. Must not benull
.- Parameters:
domainType
- the type of the aggregate roots. Must not benull
.sort
- the sorting information. Must not benull
.- Returns:
- Guaranteed to be not
null
. - Since:
- 2.0
-
streamAll
Loads all entities of the given type to aStream
, sorted.- Type Parameters:
T
- the type of entities to load.- Parameters:
domainType
- the type of entities to load. Must not benull
.sort
- the sorting information. Must not benull
.- Returns:
- Guaranteed to be not
null
. - Since:
- 2.0
-
findAll
Load a page of (potentially sorted) aggregates of a given type.- Type Parameters:
T
- the type of the aggregate roots. Must not benull
.- Parameters:
domainType
- the type of the aggregate roots. Must not benull
.pageable
- the pagination information. Must not benull
.- Returns:
- Guaranteed to be not
null
. - Since:
- 2.0
-
findOne
Execute aSELECT
query and convert the resulting item to an entity ensuring exactly one result.- Parameters:
query
- must not be null.domainType
- the entity type must not be null.- Returns:
- exactly one result or
Optional.empty()
if no match found. - Throws:
IncorrectResultSizeDataAccessException
- if more than one match found.- Since:
- 3.0
-
findAll
Execute aSELECT
query and convert the resulting items to aList
that is sorted.- Parameters:
query
- must not be null.domainType
- the entity type must not be null.- Returns:
- a non-null sorted list with all the matching results.
- Throws:
IncorrectResultSizeDataAccessException
- if more than one match found.- Since:
- 3.0
-
streamAll
Execute aSELECT
query and convert the resulting items to aStream
.- Parameters:
query
- must not be null.domainType
- the type of entities. Must not benull
.- Returns:
- a non-null list with all the matching results.
- Throws:
IncorrectResultSizeDataAccessException
- if more than one match found.- Since:
- 3.0
-
findAll
-
deleteById
Deletes a single Aggregate including all entities contained in that aggregate.Since no version attribute is provided this method will never throw a
OptimisticLockingFailureException
. If no rows match the generated delete operation this fact will be silently ignored.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
id
- the id of the aggregate root of the aggregate to be deleted. Must not benull
.domainType
- the type of the aggregate root.
-
deleteAllById
Deletes all aggregates identified by their aggregate root ids.Since no version attribute is provided this method will never throw a
OptimisticLockingFailureException
. If no rows match the generated delete operation this fact will be silently ignored.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
ids
- the ids of the aggregate roots of the aggregates to be deleted. Must not benull
.domainType
- the type of the aggregate root.
-
delete
<T> void delete(T aggregateRoot) Delete an aggregate identified by its aggregate root.- Type Parameters:
T
- the type of the aggregate root.- Parameters:
aggregateRoot
- to delete. Must not benull
.
-
deleteAll
Delete all aggregates of a given type.- Parameters:
domainType
- type of the aggregate roots to be deleted. Must not benull
.
-
deleteAll
Delete all aggregates identified by their aggregate roots.- Type Parameters:
T
- the type of the aggregate roots.- Parameters:
aggregateRoots
- to delete. Must not benull
.
-