org.springframework.data.jdbc.core.convert

## Class DelegatingDataAccessStrategy

- java.lang.Object
- - org.springframework.data.jdbc.core.convert.DelegatingDataAccessStrategy

All Implemented Interfaces:
  DataAccessStrategy, RelationResolver

    public class DelegatingDataAccessStrategy
    extends Object
    implements DataAccessStrategy

Delegates all method calls to an instance set after construction. This is useful for `DataAccessStrategy`s with cyclic dependencies.

Since:
  1.1
Author:
  Jens Schauder, Tyler Van Gorder, Milan Milanov, Myeonghyeon Lee

### Constructor Summary

Constructors
Constructor and Description
`DelegatingDataAccessStrategy()`

### Method Summary

All Methods Instance Methods Concrete Methods
`<T> void` `acquireLockAll(LockMode lockMode, Class<T> domainType)` Acquire a lock on all aggregates of the given domain type.
`<T> void` `acquireLockById(Object id, LockMode lockMode, Class<T> domainType)` Acquire a lock on the aggregate specified by id.
`long` `count(Class<?> domainType)` Counts the rows in the table representing the given domain type.
`void` `delete(Object id, Class<?> domainType)` Deletes a single row identified by the id, from the table identified by the domainType.
`void` `delete(Object rootId, PersistentPropertyPath<RelationalPersistentProperty> propertyPath)` Deletes all entities reachable via propertyPath from the instance identified by rootId.
`<T> void` `deleteAll(Class<T> domainType)` Deletes all entities of the given domain type.
`void` `deleteAll(PersistentPropertyPath<RelationalPersistentProperty> propertyPath)` Deletes all entities reachable via propertyPath from any instance.
`<T> void` `deleteWithVersion(Object id, Class<T> domainType, Number previousVersion)` Deletes a single entity from the database and enforce optimistic record locking using the version property.
`<T> boolean` `existsById(Object id, Class<T> domainType)` returns if a row with the given id exists for the given type.
`<T> Iterable<T>` `findAll(Class<T> domainType)` Loads all entities of the given type.
`<T> Iterable<T>` `findAll(Class<T> domainType, Pageable pageable)` Loads all entities of the given type, paged and sorted.
`<T> Iterable<T>` `findAll(Class<T> domainType, Sort sort)` Loads all entities of the given type, sorted.
`<T> Iterable<T>` `findAllById(Iterable<?> ids, Class<T> domainType)` Loads all entities that match one of the ids passed as an argument.
`Iterable<Object>` `findAllByPath(Identifier identifier, PersistentPropertyPath<? extends RelationalPersistentProperty> path)` Finds all entities reachable via path.
`<T> T` `findById(Object id, Class<T> domainType)` Loads a single entity identified by type and id.
`<T> Object` `insert(T instance, Class<T> domainType, Identifier identifier)` Inserts a the data of a single entity.
`void` `setDelegate(DataAccessStrategy delegate)` Must be called exactly once before calling any of the other methods.
`<S> boolean` `update(S instance, Class<S> domainType)` Updates the data of a single entity in the database.
`<S> boolean` `updateWithVersion(S instance, Class<S> domainType, Number nextVersion)` Updates the data of a single entity in the database and enforce optimistic record locking using the `previousVersion` property.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DelegatingDataAccessStrategy

    public DelegatingDataAccessStrategy()

### Method Detail

#### insert

    public <T> Object insert(T instance,
                             Class<T> domainType,
                             Identifier identifier)

Description copied from interface: `DataAccessStrategy`
Inserts a the data of a single entity. Referenced entities don't get handled.

Specified by:
  `insert` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of the instance.
Parameters:
  `instance` - the instance to be stored. Must not be `null`.
  `domainType` - the type of the instance. Must not be `null`.
  `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 a `Map` or `List`.
Returns:
  the id generated by the database if any.

#### update

    public <S> boolean update(S instance,
                              Class<S> domainType)

Description copied from interface: `DataAccessStrategy`
Updates the data of a single entity in the database. Referenced entities don't get handled.

Specified by:
  `update` in interface `DataAccessStrategy`
Type Parameters:
  `S` - the type of the instance to save.
Parameters:
  `instance` - the instance to save. Must not be `null`.
  `domainType` - the type of the instance to save. Must not be `null`.
Returns:
  whether the update actually updated a row.

#### updateWithVersion

    public <S> boolean updateWithVersion(S instance,
                                         Class<S> domainType,
                                         Number nextVersion)

Description copied from interface: `DataAccessStrategy`
Updates the data of a single entity in the database and enforce optimistic record locking using the `previousVersion` property. Referenced entities don't get handled.

The statement will be of the form : `UPDATE … SET … WHERE ID = :id and VERSION_COLUMN = :previousVersion` and throw an optimistic record locking exception if no rows have been updated.

Specified by:
  `updateWithVersion` in interface `DataAccessStrategy`
Type Parameters:
  `S` - the type of the instance to save.
Parameters:
  `instance` - the instance to save. Must not be `null`.
  `domainType` - the type of the instance to save. Must not be `null`.
  `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<RelationalPersistentProperty> propertyPath)

Description copied from interface: `DataAccessStrategy`
Deletes all entities reachable via propertyPath from the instance identified by rootId.

Specified by:
  `delete` in interface `DataAccessStrategy`
Parameters:
  `rootId` - Id of the root object on which the propertyPath is based. Must not be `null`.
  `propertyPath` - Leading from the root object to the entities to be deleted. Must not be `null`.

#### delete

    public void delete(Object id,
                       Class<?> domainType)

Description copied from interface: `DataAccessStrategy`
Deletes 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 = :version` and throw an optimistic record locking exception if no rows have been updated.

Specified by:
  `delete` in interface `DataAccessStrategy`
Parameters:
  `id` - the id of the row to be deleted. Must not be `null`.
  `domainType` - the type of entity to be deleted. Implicitly determines the table to operate on. Must not be `null`.

#### deleteWithVersion

    public <T> void deleteWithVersion(Object id,
                                      Class<T> domainType,
                                      Number previousVersion)

Description copied from interface: `DataAccessStrategy`
Deletes a single entity from the database and enforce optimistic record locking using the version property. Does not handle cascading deletes.

Specified by:
  `deleteWithVersion` in interface `DataAccessStrategy`
Parameters:
  `id` - the id of the row to be deleted. Must not be `null`.
  `domainType` - the type of entity to be deleted. Implicitly determines the table to operate on. Must not be `null`.
  `previousVersion` - The previous version assigned to the instance being saved.

#### deleteAll

    public <T> void deleteAll(Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Deletes all entities of the given domain type.

Specified by:
  `deleteAll` in interface `DataAccessStrategy`
Type Parameters:
  `T` - type of the domain type.
Parameters:
  `domainType` - the domain type for which to delete all entries. Must not be `null`.

#### deleteAll

    public void deleteAll(PersistentPropertyPath<RelationalPersistentProperty> propertyPath)

Description copied from interface: `DataAccessStrategy`
Deletes all entities reachable via propertyPath from any instance.

Specified by:
  `deleteAll` in interface `DataAccessStrategy`
Parameters:
  `propertyPath` - Leading from the root object to the entities to be deleted. Must not be `null`.

#### acquireLockById

    public <T> void acquireLockById(Object id,
                                    LockMode lockMode,
                                    Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Acquire a lock on the aggregate specified by id.

Specified by:
  `acquireLockById` in interface `DataAccessStrategy`
Parameters:
  `id` - the id of the entity to load. Must not be `null`.
  `lockMode` - the lock mode for select. Must not be `null`.
  `domainType` - the domain type of the entity. Must not be `null`.

#### acquireLockAll

    public <T> void acquireLockAll(LockMode lockMode,
                                   Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Acquire a lock on all aggregates of the given domain type.

Specified by:
  `acquireLockAll` in interface `DataAccessStrategy`
Parameters:
  `lockMode` - the lock mode for select. Must not be `null`.
  `domainType` - the domain type of the entity. Must not be `null`.

#### count

    public long count(Class<?> domainType)

Description copied from interface: `DataAccessStrategy`
Counts the rows in the table representing the given domain type.

Specified by:
  `count` in interface `DataAccessStrategy`
Parameters:
  `domainType` - the domain type for which to count the elements. Must not be `null`.
Returns:
  the count. Guaranteed to be not `null`.

#### findById

    public <T> T findById(Object id,
                          Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Loads a single entity identified by type and id.

Specified by:
  `findById` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of the entity.
Parameters:
  `id` - the id of the entity to load. Must not be `null`.
  `domainType` - the domain type of the entity. Must not be `null`.
Returns:
  Might return `null`.

#### findAll

    public <T> Iterable<T> findAll(Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Loads all entities of the given type.

Specified by:
  `findAll` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of entities to load.
Parameters:
  `domainType` - the type of entities to load. Must not be `null`.
Returns:
  Guaranteed to be not `null`.

#### findAllById

    public <T> Iterable<T> findAllById(Iterable<?> ids,
                                       Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
Loads 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:
  `findAllById` in interface `DataAccessStrategy`
Type Parameters:
  `T` - type of entities to load.
Parameters:
  `ids` - the Ids of the entities to load. Must not be `null`.
  `domainType` - the type of entities to load. Must not be `null`.
Returns:
  the loaded entities. Guaranteed to be not `null`.

#### findAllByPath

    public Iterable<Object> findAllByPath(Identifier identifier,
                                          PersistentPropertyPath<? extends RelationalPersistentProperty> path)

Description copied from interface: `RelationResolver`
Finds all entities reachable via path.

Specified by:
  `findAllByPath` in interface `DataAccessStrategy`
Specified by:
  `findAllByPath` in interface `RelationResolver`
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

    public <T> boolean existsById(Object id,
                                  Class<T> domainType)

Description copied from interface: `DataAccessStrategy`
returns if a row with the given id exists for the given type.

Specified by:
  `existsById` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of the entity.
Parameters:
  `id` - the id of the entity for which to check. Must not be `null`.
  `domainType` - the type of the entity to check for. Must not be `null`.
Returns:
  `true` if a matching row exists, otherwise `false`.

#### findAll

    public <T> Iterable<T> findAll(Class<T> domainType,
                                   Sort sort)

Description copied from interface: `DataAccessStrategy`
Loads all entities of the given type, sorted.

Specified by:
  `findAll` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of entities to load.
Parameters:
  `domainType` - the type of entities to load. Must not be `null`.
  `sort` - the sorting information. Must not be `null`.
Returns:
  Guaranteed to be not `null`.

#### findAll

    public <T> Iterable<T> findAll(Class<T> domainType,
                                   Pageable pageable)

Description copied from interface: `DataAccessStrategy`
Loads all entities of the given type, paged and sorted.

Specified by:
  `findAll` in interface `DataAccessStrategy`
Type Parameters:
  `T` - the type of entities to load.
Parameters:
  `domainType` - the type of entities to load. Must not be `null`.
  `pageable` - the pagination information. Must not be `null`.
Returns:
  Guaranteed to be not `null`.

#### setDelegate

    public void setDelegate(DataAccessStrategy delegate)

Must be called exactly once before calling any of the other methods.

Parameters:
  `delegate` - Must not be null