java.lang.Object
org.springframework.data.jdbc.core.JdbcAggregateTemplate
- All Implemented Interfaces:
JdbcAggregateOperations
JdbcAggregateOperations implementation, storing aggregates in and obtaining them from a JDBC data store.- Author:
- Jens Schauder, Mark Paluch, Thomas Lang, Christoph Strobl, Milan Milanov, Myeonghyeon Lee, Chirag Tailor, Diego Krupitza
-
Constructor Summary
ConstructorsConstructorDescriptionJdbcAggregateTemplate(ApplicationContext publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplategivenApplicationContext,RelationalMappingContextandDataAccessStrategy.JdbcAggregateTemplate(ApplicationEventPublisher publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplategivenApplicationEventPublisher,RelationalMappingContextandDataAccessStrategy. -
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.<S> voiddelete(S 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.<S> voiddeleteById(Object id, Class<S> 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> List<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 to do just the insert of an instance of an aggregate, including all the members of the aggregate.<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.voidsetEntityCallbacks(EntityCallbacks entityCallbacks) Sets the callbacks to be invoked on life cycle events.voidsetEntityLifecycleEventsEnabled(boolean enabled) Configure whether lifecycle events such asAfterSaveEvent,BeforeSaveEvent, etc. should be published or whether emission should be suppressed.<T> Tupdate(T instance) Dedicated update function to do just an update of an instance of an aggregate, including all the members of the aggregate.<T> Iterable<T>Updates all aggregate instances, including all the members of each aggregate instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.jdbc.core.JdbcAggregateOperations
delete, deleteAll
-
Constructor Details
-
JdbcAggregateTemplate
public JdbcAggregateTemplate(ApplicationContext publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplategivenApplicationContext,RelationalMappingContextandDataAccessStrategy.- Parameters:
publisher- must not be null.context- must not be null.dataAccessStrategy- must not be null.- Since:
- 1.1
-
JdbcAggregateTemplate
public JdbcAggregateTemplate(ApplicationEventPublisher publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplategivenApplicationEventPublisher,RelationalMappingContextandDataAccessStrategy.- Parameters:
publisher- must not be null.context- must not be null.dataAccessStrategy- must not be null.
-
-
Method Details
-
setEntityCallbacks
Sets the callbacks to be invoked on life cycle events.- Parameters:
entityCallbacks- must not be null.- Since:
- 1.1
-
setEntityLifecycleEventsEnabled
public void setEntityLifecycleEventsEnabled(boolean enabled) Configure whether lifecycle events such asAfterSaveEvent,BeforeSaveEvent, etc. should be published or whether emission should be suppressed. Enabled by default.- Parameters:
enabled-trueto enable entity lifecycle events;falseto disable entity lifecycle events.- Since:
- 3.0
- See Also:
-
AbstractRelationalEvent
-
save
public <T> T save(T instance) Description copied from interface:JdbcAggregateOperationsSaves an instance of an aggregate, including all the members of the aggregate.- Specified by:
savein interfaceJdbcAggregateOperations- 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.
-
saveAll
Description copied from interface:JdbcAggregateOperationsSaves all aggregate instances, including all the members of each aggregate instance.- Specified by:
saveAllin interfaceJdbcAggregateOperations- Type Parameters:
T- the type of the aggregate root.- Parameters:
instances- the aggregate roots to be saved. Must not benull.- Returns:
- the saved instances.
-
insert
public <T> T insert(T instance) Dedicated insert function to do just the insert of an instance of an aggregate, including all the members of the aggregate.- Specified by:
insertin interfaceJdbcAggregateOperations- 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
Description copied from interface:JdbcAggregateOperationsInserts all aggregate instances, including all the members of each aggregate instance.This is useful if the client provides an id for new aggregate roots.
- Specified by:
insertAllin interfaceJdbcAggregateOperations- Type Parameters:
T- the type of the aggregate root.- Parameters:
instances- the aggregate roots to be inserted. Must not benull.- Returns:
- the saved instances.
-
update
public <T> T update(T instance) Dedicated update function to do just an update of an instance of an aggregate, including all the members of the aggregate.- Specified by:
updatein interfaceJdbcAggregateOperations- 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
Description copied from interface:JdbcAggregateOperationsUpdates all aggregate instances, including all the members of each aggregate instance.- Specified by:
updateAllin interfaceJdbcAggregateOperations- Type Parameters:
T- the type of the aggregate root.- Parameters:
instances- the aggregate roots to be inserted. Must not benull.- Returns:
- the saved instances.
-
count
Description copied from interface:JdbcAggregateOperationsCounts the number of aggregates of a given type.- Specified by:
countin interfaceJdbcAggregateOperations- 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
public <T> long count(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:JdbcAggregateOperationsCounts the number of aggregates of a given type that match the givenquery.- Specified by:
countin interfaceJdbcAggregateOperations- 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.
-
exists
public <T> boolean exists(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:JdbcAggregateOperationsDetermine whether there are aggregates that match theQuery- Specified by:
existsin interfaceJdbcAggregateOperations- Parameters:
query- must not be null.domainType- the entity type must not be null.- Returns:
- true if the object exists.
-
existsById
Description copied from interface:JdbcAggregateOperationsChecks if an aggregate identified by type and id exists in the database.- Specified by:
existsByIdin interfaceJdbcAggregateOperations- 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
Description copied from interface:JdbcAggregateOperationsLoad an aggregate from the database.- Specified by:
findByIdin interfaceJdbcAggregateOperations- 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.
-
findAll
Description copied from interface:JdbcAggregateOperationsLoad all aggregates of a given type, sorted.- Specified by:
findAllin interfaceJdbcAggregateOperations- 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.
-
findAll
Description copied from interface:JdbcAggregateOperationsLoad a page of (potentially sorted) aggregates of a given type.- Specified by:
findAllin interfaceJdbcAggregateOperations- 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.
-
findOne
public <T> Optional<T> findOne(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:JdbcAggregateOperationsExecute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.- Specified by:
findOnein interfaceJdbcAggregateOperations- 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.
-
findAll
public <T> List<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:JdbcAggregateOperationsExecute aSELECTquery and convert the resulting items to aIterablethat is sorted.- Specified by:
findAllin interfaceJdbcAggregateOperations- 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.
-
findAll
public <T> Page<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable) Description copied from interface:JdbcAggregateOperationsReturns aPageof entities matching the givenQuery. In case no match could be found, an emptyPageis returned.- Specified by:
findAllin interfaceJdbcAggregateOperations- Parameters:
query- must not be null.domainType- the entity type must not be null.pageable- can be null.- Returns:
- a
Pageof entities matching the givenExample.
-
findAll
Description copied from interface:JdbcAggregateOperationsLoad all aggregates of a given type.- Specified by:
findAllin interfaceJdbcAggregateOperations- 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.
-
findAllById
Description copied from interface:JdbcAggregateOperationsLoad all aggregates of a given type that are identified by the given ids.- Specified by:
findAllByIdin interfaceJdbcAggregateOperations- 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.
-
delete
public <S> void delete(S aggregateRoot) Description copied from interface:JdbcAggregateOperationsDelete an aggregate identified by its aggregate root.- Specified by:
deletein interfaceJdbcAggregateOperations- Type Parameters:
S- the type of the aggregate root.- Parameters:
aggregateRoot- to delete. Must not benull.
-
deleteById
Description copied from interface:JdbcAggregateOperationsDeletes 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.- Specified by:
deleteByIdin interfaceJdbcAggregateOperations- Type Parameters:
S- 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
Description copied from interface:JdbcAggregateOperationsDeletes 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.- Specified by:
deleteAllByIdin interfaceJdbcAggregateOperations- 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.
-
deleteAll
Description copied from interface:JdbcAggregateOperationsDelete all aggregates of a given type.- Specified by:
deleteAllin interfaceJdbcAggregateOperations- Parameters:
domainType- type of the aggregate roots to be deleted. Must not benull.
-
deleteAll
Description copied from interface:JdbcAggregateOperationsDelete all aggregates identified by their aggregate roots.- Specified by:
deleteAllin interfaceJdbcAggregateOperations- Type Parameters:
T- the type of the aggregate roots.- Parameters:
instances- to delete. Must not benull.
-