Module spring.data.jdbc
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
-
Method Summary
Modifier and TypeMethodDescriptionlongCounts the number of aggregates of a given type.<T> longCounts the number of aggregates of a given type that match the givenquery.<T> voiddelete(T aggregateRoot) Delete an aggregate identified by its aggregate root.default <T> voidDeprecated.voidDelete all aggregates of a given type.<T> voidDelete all aggregates identified by their aggregate roots.default <T> voidDeprecated.since 3.0 usedeleteAll(Iterable)instead.<T> voiddeleteAllById(Iterable<?> ids, Class<T> domainType) Deletes all aggregates identified by their aggregate root ids.<T> voiddeleteById(Object id, Class<T> domainType) Deletes a single Aggregate including all entities contained in that aggregate.<T> booleanDetermine whether there are aggregates that match theQuery<T> booleanexistsById(Object id, Class<T> domainType) Checks if an aggregate identified by type and id exists in the database.<T> Iterable<T>Load all aggregates of a given type.<T> Page<T>Load a page of (potentially sorted) aggregates of a given type.<T> Iterable<T>Load all aggregates of a given type, sorted.<T> Iterable<T>Execute aSELECTquery and convert the resulting items to aIterablethat is sorted.<T> Page<T>findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable) Returns aPageof entities matching the givenQuery.<T> Iterable<T>findAllById(Iterable<?> ids, Class<T> domainType) Load all aggregates of a given type that are identified by the given ids.<T> TLoad an aggregate from the database.<T> Optional<T>Execute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.<T> Tinsert(T instance) Dedicated insert function.<T> Iterable<T>Inserts all aggregate instances, including all the members of each aggregate instance.<T> Tsave(T instance) Saves an instance of an aggregate, including all the members of the aggregate.<T> Iterable<T>Saves all aggregate instances, including all the members of each aggregate instance.<T> Tupdate(T instance) Dedicated update function.<T> Iterable<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.
-
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.
-
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
-
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
<T> Optional<T> findOne(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Execute aSELECTquery 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
<T> Iterable<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Execute aSELECTquery and convert the resulting items to aIterablethat 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
-
findAll
<T> Page<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable) -
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.
-
delete
Deprecated.since 3.0 usedelete(Object)insteadDelete an aggregate identified by its aggregate root.- Type Parameters:
T- the type of the aggregate root.- Parameters:
aggregateRoot- to delete. Must not benull.domainType- the type of the aggregate root. Must not benull.- Throws:
OptimisticLockingFailureException- when T has a version attribute and the version attribute of the provided entity does not match the version attribute in the database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
-
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.
-
deleteAll
@Deprecated(since="3.0") default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType) Deprecated.since 3.0 usedeleteAll(Iterable)instead.Delete all aggregates identified by their aggregate roots.- Type Parameters:
T- the type of the aggregate roots.- Parameters:
aggregateRoots- to delete. Must not benull.domainType- type of the aggregate roots to be deleted. Must not benull.- Throws:
OptimisticLockingFailureException- when T has a version attribute and for at least on entity the version attribute of the entity does not match the version attribute in the database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
-
delete(Object)instead