Module spring.data.jdbc
Class DelegatingDataAccessStrategy
java.lang.Object
org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy
- All Implemented Interfaces:
DataAccessStrategy,RelationResolver
Delegates all method calls to an instance set after construction. This is useful for
DataAccessStrategys with
cyclic dependencies.- Since:
- 1.1
- Author:
- Jens Schauder, Tyler Van Gorder, Milan Milanov, Myeonghyeon Lee, Chirag Tailor, Diego Krupitza, Sergey Korotaev
-
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescription<T> voidacquireLockAll(org.springframework.data.relational.core.sql.LockMode lockMode, Class<T> domainType) Acquire a lock on all aggregates of the given domain type.<T> voidacquireLockById(Object id, org.springframework.data.relational.core.sql.LockMode lockMode, Class<T> domainType) Acquire a lock on the aggregate specified by id.longCounts the rows in the table representing the given domain type.<T> longCounts the rows in the table representing the given probe type, that match the givenquery.voidDeletes multiple rows identified by the ids, from the table identified by the domainType.voiddelete(Iterable<Object> rootIds, PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Deletes all entities reachable via propertyPath from the instances identified by rootIds.voidDeletes a single row identified by the id, from the table identified by the domainType.voiddelete(Object rootId, PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Deletes all entities reachable via propertyPath from the instance identified by rootId.<T> voidDeletes all entities of the given domain type.voiddeleteAll(PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Deletes all entities reachable via propertyPath from any instance.<T> voiddeleteWithVersion(Object id, Class<T> domainType, Number previousVersion) Deletes a single entity from the database and enforce optimistic record locking using the version property.<T> booleanDetermine whether there is an aggregate of typedomainTypethat matches the providedQuery.<T> booleanexistsById(Object id, Class<T> domainType) returns if a row with the given id exists for the given type.<T> Iterable<T>Loads all entities of the given type.<T> Iterable<T>Loads all entities of the given type, paged and sorted.<T> Iterable<T>Loads all entities of the given type, sorted.<T> Iterable<T>Execute aSELECTquery and convert the resulting items to aIterable.<T> Iterable<T>findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable) Execute aSELECTquery and convert the resulting items to aIterable.<T> Iterable<T>findAllById(Iterable<?> ids, Class<T> domainType) Loads all entities that match one of the ids passed as an argument.findAllByPath(Identifier identifier, PersistentPropertyPath<? extends org.springframework.data.relational.core.mapping.RelationalPersistentProperty> path) Finds all entities reachable via path.<T> TLoads a single entity identified by type and id.<T> Optional<T>Execute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.<T> Object[]insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, org.springframework.data.relational.core.conversion.IdValueSource idValueSource) Inserts the data of multiple entities.<T> Objectinsert(T instance, Class<T> domainType, Identifier identifier, org.springframework.data.relational.core.conversion.IdValueSource idValueSource) Inserts the data of a single entity.voidsetDelegate(DataAccessStrategy delegate) Deprecated, for removal: This API element is subject to removal in a future version.<T> Stream<T>Loads all entities of the 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.<S> booleanUpdates the data of a single entity in the database.<S> booleanupdateWithVersion(S instance, Class<S> domainType, Number nextVersion) Updates the data of a single entity in the database and enforce optimistic record locking using thepreviousVersionproperty.
-
Constructor Details
-
DelegatingDataAccessStrategy
public DelegatingDataAccessStrategy() -
DelegatingDataAccessStrategy
-
-
Method Details
-
insert
public <T> Object insert(T instance, Class<T> domainType, Identifier identifier, org.springframework.data.relational.core.conversion.IdValueSource idValueSource) Description copied from interface:DataAccessStrategyInserts the data of a single entity. Referenced entities don't get handled.- Specified by:
insertin interfaceDataAccessStrategy- Type Parameters:
T- the type of the instance.- Parameters:
instance- the instance to be stored. Must not benull.domainType- the type of the instance. Must not benull.identifier- information about data that needs to be considered for the insert but which is not part of the entity. Namely, references back to a parent entity and key/index columns for entities that are stored in aMaporList.idValueSource- theIdValueSourcefor the insert.- Returns:
- the id generated by the database if any.
-
insert
public <T> Object[] insert(List<InsertSubject<T>> insertSubjects, Class<T> domainType, org.springframework.data.relational.core.conversion.IdValueSource idValueSource) Description copied from interface:DataAccessStrategyInserts the data of multiple entities.- Specified by:
insertin interfaceDataAccessStrategy- Type Parameters:
T- the type of the instance.- Parameters:
insertSubjects- the subjects to be inserted, where each subject contains the instance and its identifier. Must not benull.domainType- the type of the instance. Must not benull.idValueSource- theIdValueSourcefor the insert.- Returns:
- the ids corresponding to each record that was inserted, if ids were generated. If ids were not generated,
elements will be
null.
-
update
Description copied from interface:DataAccessStrategyUpdates the data of a single entity in the database. Referenced entities don't get handled.- Specified by:
updatein interfaceDataAccessStrategy- Type Parameters:
S- the type of the instance to save.- Parameters:
instance- the instance to save. Must not benull.domainType- the type of the instance to save. Must not benull.- Returns:
- whether the update actually updated a row.
-
updateWithVersion
Description copied from interface:DataAccessStrategyUpdates the data of a single entity in the database and enforce optimistic record locking using thepreviousVersionproperty. Referenced entities don't get handled.The statement will be of the form :
UPDATE … SET … WHERE ID = :id and VERSION_COLUMN = :previousVersionand throw an optimistic record locking exception if no rows have been updated.- Specified by:
updateWithVersionin interfaceDataAccessStrategy- Type Parameters:
S- the type of the instance to save.- Parameters:
instance- the instance to save. Must not benull.domainType- the type of the instance to save. Must not benull.nextVersion- The previous version assigned to the instance being saved.- Returns:
- whether the update actually updated a row.
-
delete
public void delete(Object rootId, PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Description copied from interface:DataAccessStrategyDeletes all entities reachable via propertyPath from the instance identified by rootId.- Specified by:
deletein interfaceDataAccessStrategy- Parameters:
rootId- Id of the root object on which the propertyPath is based. Must not benull.propertyPath- Leading from the root object to the entities to be deleted. Must not benull.
-
delete
public void delete(Iterable<Object> rootIds, PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Description copied from interface:DataAccessStrategyDeletes all entities reachable via propertyPath from the instances identified by rootIds.- Specified by:
deletein interfaceDataAccessStrategy- Parameters:
rootIds- Ids of the root objects on which the propertyPath is based. Must not benullor empty.propertyPath- Leading from the root object to the entities to be deleted. Must not benull.
-
delete
Description copied from interface:DataAccessStrategyDeletes a single row identified by the id, from the table identified by the domainType. Does not handle cascading deletes.The statement will be of the form :
DELETE FROM … WHERE ID = :id and VERSION_COLUMN = :versionand throw an optimistic record locking exception if no rows have been updated.- Specified by:
deletein interfaceDataAccessStrategy- Parameters:
id- the id of the row to be deleted. Must not benull.domainType- the type of entity to be deleted. Implicitly determines the table to operate on. Must not benull.
-
delete
Description copied from interface:DataAccessStrategyDeletes multiple rows identified by the ids, from the table identified by the domainType. Does not handle cascading deletes.The statement will be of the form :
DELETE FROM … WHERE ID IN (:ids)and throw an optimistic record locking exception if no rows have been updated.- Specified by:
deletein interfaceDataAccessStrategy- Parameters:
ids- the ids of the rows to be deleted. Must not benull.domainType- the type of entity to be deleted. Implicitly determines the table to operate on. Must not benull.
-
deleteWithVersion
Description copied from interface:DataAccessStrategyDeletes a single entity from the database and enforce optimistic record locking using the version property. Does not handle cascading deletes.- Specified by:
deleteWithVersionin interfaceDataAccessStrategy- Parameters:
id- the id of the row to be deleted. Must not benull.domainType- the type of entity to be deleted. Implicitly determines the table to operate on. Must not benull.previousVersion- The previous version assigned to the instance being saved.
-
deleteAll
Description copied from interface:DataAccessStrategyDeletes all entities of the given domain type.- Specified by:
deleteAllin interfaceDataAccessStrategy- Type Parameters:
T- type of the domain type.- Parameters:
domainType- the domain type for which to delete all entries. Must not benull.
-
deleteAll
public void deleteAll(PersistentPropertyPath<org.springframework.data.relational.core.mapping.RelationalPersistentProperty> propertyPath) Description copied from interface:DataAccessStrategyDeletes all entities reachable via propertyPath from any instance.- Specified by:
deleteAllin interfaceDataAccessStrategy- Parameters:
propertyPath- Leading from the root object to the entities to be deleted. Must not benull.
-
acquireLockById
public <T> void acquireLockById(Object id, org.springframework.data.relational.core.sql.LockMode lockMode, Class<T> domainType) Description copied from interface:DataAccessStrategyAcquire a lock on the aggregate specified by id.- Specified by:
acquireLockByIdin interfaceDataAccessStrategy- Parameters:
id- the id of the entity to load. Must not benull.lockMode- the lock mode for select. Must not benull.domainType- the domain type of the entity. Must not benull.
-
acquireLockAll
public <T> void acquireLockAll(org.springframework.data.relational.core.sql.LockMode lockMode, Class<T> domainType) Description copied from interface:DataAccessStrategyAcquire a lock on all aggregates of the given domain type.- Specified by:
acquireLockAllin interfaceDataAccessStrategy- Parameters:
lockMode- the lock mode for select. Must not benull.domainType- the domain type of the entity. Must not benull.
-
count
Description copied from interface:DataAccessStrategyCounts the rows in the table representing the given domain type.- Specified by:
countin interfaceDataAccessStrategy- Parameters:
domainType- the domain type for which to count the elements. Must not benull.- Returns:
- the count. Guaranteed to be not
null.
-
findById
Description copied from interface:DataAccessStrategyLoads a single entity identified by type and id.- Specified by:
findByIdin interfaceDataAccessStrategy- Type Parameters:
T- the type of the entity.- Parameters:
id- the id of the entity to load. Must not benull.domainType- the domain type of the entity. Must not benull.- Returns:
- Might return
null.
-
findAll
Description copied from interface:DataAccessStrategyLoads all entities of the given type.- Specified by:
findAllin interfaceDataAccessStrategy- Type Parameters:
T- the type of entities to load.- Parameters:
domainType- the type of entities to load. Must not benull.- Returns:
- Guaranteed to be not
null.
-
streamAll
Description copied from interface:DataAccessStrategyLoads all entities of the given type to aStream.- Specified by:
streamAllin interfaceDataAccessStrategy- Type Parameters:
T- the type of entities to load.- Parameters:
domainType- the type of entities to load. Must not benull.- Returns:
- Guaranteed to be not
null.
-
findAllById
Description copied from interface:DataAccessStrategyLoads all entities that match one of the ids passed as an argument. It is not guaranteed that the number of ids passed in matches the number of entities returned.- Specified by:
findAllByIdin interfaceDataAccessStrategy- 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.
-
streamAllByIds
Description copied from interface:DataAccessStrategyLoads 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.- Specified by:
streamAllByIdsin interfaceDataAccessStrategy- 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.
-
findAllByPath
public Iterable<Object> findAllByPath(Identifier identifier, PersistentPropertyPath<? extends org.springframework.data.relational.core.mapping.RelationalPersistentProperty> path) Description copied from interface:RelationResolverFinds all entities reachable via path.- Specified by:
findAllByPathin interfaceDataAccessStrategy- Specified by:
findAllByPathin interfaceRelationResolver- Parameters:
identifier- the combination of Id, map keys and list indexes that identify the parent of the entity to be loaded. Must not be null.path- the path from the aggregate root to the entities to be resolved. Must not be null.- Returns:
- guaranteed to be not null.
-
existsById
Description copied from interface:DataAccessStrategyreturns if a row with the given id exists for the given type.- Specified by:
existsByIdin interfaceDataAccessStrategy- Type Parameters:
T- the type of the entity.- Parameters:
id- the id of the entity for which to check. Must not benull.domainType- the type of the entity to check for. Must not benull.- Returns:
trueif a matching row exists, otherwisefalse.
-
findAll
Description copied from interface:DataAccessStrategyLoads all entities of the given type, sorted.- Specified by:
findAllin interfaceDataAccessStrategy- 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.
-
streamAll
Description copied from interface:DataAccessStrategyLoads all entities of the given type to aStream, sorted.- Specified by:
streamAllin interfaceDataAccessStrategy- 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.
-
findAll
Description copied from interface:DataAccessStrategyLoads all entities of the given type, paged and sorted.- Specified by:
findAllin interfaceDataAccessStrategy- Type Parameters:
T- the type of entities to load.- Parameters:
domainType- the type of entities to load. 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:DataAccessStrategyExecute aSELECTquery and convert the resulting item to an entity ensuring exactly one result.- Specified by:
findOnein interfaceDataAccessStrategy- Parameters:
query- must not be null.domainType- the type of entities. Must not benull.- Returns:
- exactly one result or
Optional.empty()if no match found.
-
findAll
public <T> Iterable<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:DataAccessStrategyExecute aSELECTquery and convert the resulting items to aIterable.- Specified by:
findAllin interfaceDataAccessStrategy- Parameters:
query- must not be null.domainType- the type of entities. Must not benull.- Returns:
- a non-null list with all the matching results.
-
streamAll
public <T> Stream<T> streamAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:DataAccessStrategyExecute aSELECTquery and convert the resulting items to aStream.- Specified by:
streamAllin interfaceDataAccessStrategy- Parameters:
query- must not be null.domainType- the type of entities. Must not benull.- Returns:
- a non-null list with all the matching results.
-
findAll
public <T> Iterable<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable) Description copied from interface:DataAccessStrategyExecute aSELECTquery and convert the resulting items to aIterable. Applies thePageableto the result.- Specified by:
findAllin interfaceDataAccessStrategy- Parameters:
query- must not be null.domainType- the type of entities. Must not be null.pageable- the pagination that should be applied. Must not be null.- Returns:
- a non-null list with all the matching results.
-
exists
public <T> boolean exists(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:DataAccessStrategyDetermine whether there is an aggregate of typedomainTypethat matches the providedQuery.- Specified by:
existsin interfaceDataAccessStrategy- Parameters:
query- must not be null.domainType- the type of entities. Must not benull.- Returns:
- true if the object exists.
-
count
public <T> long count(org.springframework.data.relational.core.query.Query query, Class<T> domainType) Description copied from interface:DataAccessStrategyCounts the rows in the table representing the given probe type, that match the givenquery.- Specified by:
countin interfaceDataAccessStrategy- Parameters:
query- the query which elements have to match.domainType- the probe type for which to count the elements. Must not benull.- Returns:
- the count. Guaranteed to be not
null.
-
setDelegate
Deprecated, for removal: This API element is subject to removal in a future version.since 3.0, useDelegatingDataAccessStrategy(DataAccessStrategy)to avoid mutable state.Must be called exactly once before calling any of the other methods.- Parameters:
delegate- Must not be null
-
DelegatingDataAccessStrategy(DataAccessStrategy)to avoid mutable state.