Class JdbcAggregateTemplate
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
ConstructorDescriptionJdbcAggregateTemplate
(ApplicationContext publisher, RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplate
givenApplicationContext
,RelationalMappingContext
andDataAccessStrategy
.JdbcAggregateTemplate
(ApplicationEventPublisher publisher, RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplate
givenApplicationEventPublisher
,RelationalMappingContext
andDataAccessStrategy
. -
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
.<S> void
delete
(S 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.<S> void
deleteById
(Object id, Class<S> 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> 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 aSELECT
query and convert the resulting items to aIterable
that is sorted.<T> Page<T>
<T> Iterable<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 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> T
save
(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.void
setEntityCallbacks
(EntityCallbacks entityCallbacks) Sets the callbacks to be invoked on life cycle events.void
setEntityLifecycleEventsEnabled
(boolean enabled) Configure whether lifecycle events such asAfterSaveEvent
,BeforeSaveEvent
, etc. should be published or whether emission should be suppressed.<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.<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, wait
Methods inherited from interface org.springframework.data.jdbc.core.JdbcAggregateOperations
delete, deleteAll
-
Constructor Details
-
JdbcAggregateTemplate
public JdbcAggregateTemplate(ApplicationContext publisher, RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplate
givenApplicationContext
,RelationalMappingContext
andDataAccessStrategy
.- Parameters:
publisher
- must not be null.context
- must not be null.dataAccessStrategy
- must not be null.- Since:
- 1.1
-
JdbcAggregateTemplate
public JdbcAggregateTemplate(ApplicationEventPublisher publisher, RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy) Creates a newJdbcAggregateTemplate
givenApplicationEventPublisher
,RelationalMappingContext
andDataAccessStrategy
.- 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
-true
to enable entity lifecycle events;false
to disable entity lifecycle events.- Since:
- 3.0
- See Also:
-
save
public <T> T save(T instance) Description copied from interface:JdbcAggregateOperations
Saves an instance of an aggregate, including all the members of the aggregate.- Specified by:
save
in 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:JdbcAggregateOperations
Saves all aggregate instances, including all the members of each aggregate instance.- Specified by:
saveAll
in 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:
insert
in 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:JdbcAggregateOperations
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.
- Specified by:
insertAll
in 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:
update
in 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:JdbcAggregateOperations
Updates all aggregate instances, including all the members of each aggregate instance.- Specified by:
updateAll
in 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:JdbcAggregateOperations
Counts the number of aggregates of a given type.- Specified by:
count
in 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
Description copied from interface:JdbcAggregateOperations
Counts the number of aggregates of a given type that match the givenquery
.- Specified by:
count
in 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
Description copied from interface:JdbcAggregateOperations
Determine whether there are aggregates that match theQuery
- Specified by:
exists
in 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:JdbcAggregateOperations
Checks if an aggregate identified by type and id exists in the database.- Specified by:
existsById
in 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:JdbcAggregateOperations
Load an aggregate from the database.- Specified by:
findById
in 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:JdbcAggregateOperations
Load all aggregates of a given type, sorted.- Specified by:
findAll
in 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:JdbcAggregateOperations
Load a page of (potentially sorted) aggregates of a given type.- Specified by:
findAll
in 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
Description copied from interface:JdbcAggregateOperations
Execute aSELECT
query and convert the resulting item to an entity ensuring exactly one result.- Specified by:
findOne
in 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
Description copied from interface:JdbcAggregateOperations
Execute aSELECT
query and convert the resulting items to aIterable
that is sorted.- Specified by:
findAll
in 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
Description copied from interface:JdbcAggregateOperations
Returns aPage
of entities matching the givenQuery
. In case no match could be found, an emptyPage
is returned.- Specified by:
findAll
in interfaceJdbcAggregateOperations
- Parameters:
query
- must not be null.domainType
- the entity type must not be null.pageable
- can be null.- Returns:
- a
Page
of entities matching the givenExample
.
-
findAll
Description copied from interface:JdbcAggregateOperations
Load all aggregates of a given type.- Specified by:
findAll
in 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:JdbcAggregateOperations
Load all aggregates of a given type that are identified by the given ids.- Specified by:
findAllById
in 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:JdbcAggregateOperations
Delete an aggregate identified by its aggregate root.- Specified by:
delete
in interfaceJdbcAggregateOperations
- Type Parameters:
S
- the type of the aggregate root.- Parameters:
aggregateRoot
- to delete. Must not benull
.
-
deleteById
Description copied from interface:JdbcAggregateOperations
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.- Specified by:
deleteById
in 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:JdbcAggregateOperations
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.- Specified by:
deleteAllById
in 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:JdbcAggregateOperations
Delete all aggregates of a given type.- Specified by:
deleteAll
in interfaceJdbcAggregateOperations
- Parameters:
domainType
- type of the aggregate roots to be deleted. Must not benull
.
-
deleteAll
Description copied from interface:JdbcAggregateOperations
Delete all aggregates identified by their aggregate roots.- Specified by:
deleteAll
in interfaceJdbcAggregateOperations
- Type Parameters:
T
- the type of the aggregate roots.- Parameters:
instances
- to delete. Must not benull
.
-