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
-
Constructor Summary
ConstructorsConstructorDescriptionJdbcAggregateTemplate
(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.<S> void
Delete an aggregate identified by it's aggregate root.void
Delete all aggregates of a given type.<S> void
deleteById
(Object id, Class<S> domainType) Deletes a single Aggregate including all entities contained in that aggregate.<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>
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> 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> T
save
(T instance) Saves an instance of an aggregate, including all the members of the aggregate.void
setEntityCallbacks
(EntityCallbacks entityCallbacks) <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.
-
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
- Parameters:
entityCallbacks
-- Since:
- 1.1
-
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.
-
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.
-
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.
-
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
.
-
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
.
-
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.
-
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
.
-
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
Description copied from interface:JdbcAggregateOperations
Delete an aggregate identified by it's aggregate root.- Specified by:
delete
in interfaceJdbcAggregateOperations
- Type Parameters:
S
- the type of the aggregate root.- Parameters:
aggregateRoot
- to delete. Must not benull
.domainType
- the type of the aggregate root. Must not benull
.
-
deleteById
Description copied from interface:JdbcAggregateOperations
Deletes a single Aggregate including all entities contained in that aggregate.- 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.
-
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
.
-