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, Tomohiko Ozawa
-
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.voidDelete all aggregates of a given type.<T> voidDelete all aggregates identified by their aggregate roots.<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> List<T>Load all aggregates of a given type.<T> Page<T>Deprecated, for removal: This API element is subject to removal in a future version.since 4.0.<T> List<T>Load all aggregates of a given type, sorted.<T> List<T>Execute aSELECTquery and convert the resulting items to aListthat is sorted.<T> Page<T>Deprecated, for removal: This API element is subject to removal in a future version.since 4.0.<T> List<T>findAllById(Iterable<?> ids, Class<T> domainType) Load all aggregates of a given type that are identified by the given ids.<T> @Nullable TLoad an aggregate from the database.<T> Optional<T>Execute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.Returns theJdbcConverter.Return theDataAccessStrategy<T> RowMapper<? extends T>getRowMapper(Class<T> type) <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> 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 aSELECTquery 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> Tupdate(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
@Deprecated(since="4.0", forRemoval=true) <T> Page<T> findAll(Class<T> domainType, Pageable pageable) Deprecated, for removal: This API element is subject to removal in a future version.since 4.0. UsefindAll(Class, Sort)together withcount(Class)to construct results of typePage.The API design is conflicts regarding pagination information. Also, pagination is primarily a feature of the repository and not the template API.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 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
Execute aSELECTquery and convert the resulting items to aListthat 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 aSELECTquery 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
@Deprecated(since="4.0", forRemoval=true) <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable) Deprecated, for removal: This API element is subject to removal in a future version.since 4.0. UsefindAll(Query, Class)together withcount(Query, Class)to construct results of typePage. The API design is conflicts regarding pagination information. Also, pagination is primarily a feature of the repository and not the template API. -
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.
-
getConverter
JdbcConverter getConverter()Returns theJdbcConverter.- Returns:
- the
JdbcConverter.
-
getDataAccessStrategy
DataAccessStrategy getDataAccessStrategy()Return theDataAccessStrategy- Returns:
- the
DataAccessStrategy
-
getRowMapper
Return aRowMapperthat can map rows of aResultSetto instances of the specifiedtype. The row mapper supports entity callbacks and lifecycle events if enabled and configured on the underlying template instance.- Type Parameters:
T-- Parameters:
type- type of the entity to map.- Returns:
- a row mapper for the given type.
- Since:
- 4.0
-