Class JdbcAggregateTemplate

java.lang.Object
org.springframework.data.jdbc.core.JdbcAggregateTemplate
All Implemented Interfaces:
JdbcAggregateOperations

public class JdbcAggregateTemplate extends Object implements 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 Details

  • Method Details

    • setEntityCallbacks

      public void setEntityCallbacks(EntityCallbacks entityCallbacks)
      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 as AfterSaveEvent, 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 interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      instance - the aggregate root of the aggregate to be saved. Must not be null.
      Returns:
      the saved instance.
    • saveAll

      public <T> Iterable<T> saveAll(Iterable<T> instances)
      Description copied from interface: JdbcAggregateOperations
      Saves all aggregate instances, including all the members of each aggregate instance.
      Specified by:
      saveAll in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      instances - the aggregate roots to be saved. Must not be null.
      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 interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      instance - the aggregate root of the aggregate to be inserted. Must not be null.
      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 interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      instance - the aggregate root of the aggregate to be inserted. Must not be null.
      Returns:
      the saved instance.
    • count

      public long count(Class<?> domainType)
      Description copied from interface: JdbcAggregateOperations
      Counts the number of aggregates of a given type.
      Specified by:
      count in interface JdbcAggregateOperations
      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

      public <T> T findById(Object id, Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Load an aggregate from the database.
      Specified by:
      findById in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      id - the id of the aggregate to load. Must not be null.
      domainType - the type of the aggregate root. Must not be null.
      Returns:
      the loaded aggregate. Might return null.
    • existsById

      public <T> boolean existsById(Object id, Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Checks if an aggregate identified by type and id exists in the database.
      Specified by:
      existsById in interface JdbcAggregateOperations
      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

      public <T> Iterable<T> findAll(Class<T> domainType, Sort sort)
      Description copied from interface: JdbcAggregateOperations
      Load all aggregates of a given type, sorted.
      Specified by:
      findAll in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate roots. Must not be null.
      Parameters:
      domainType - the type of the aggregate roots. Must not be null.
      sort - the sorting information. Must not be null.
      Returns:
      Guaranteed to be not null.
    • findAll

      public <T> Page<T> findAll(Class<T> domainType, Pageable pageable)
      Description copied from interface: JdbcAggregateOperations
      Load a page of (potentially sorted) aggregates of a given type.
      Specified by:
      findAll in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate roots. Must not be null.
      Parameters:
      domainType - the type of the aggregate roots. Must not be null.
      pageable - the pagination information. Must not be null.
      Returns:
      Guaranteed to be not null.
    • selectOne

      public <T> Optional<T> selectOne(Query query, Class<T> entityClass)
      Description copied from interface: JdbcAggregateOperations
      Execute a SELECT query and convert the resulting item to an entity ensuring exactly one result.
      Specified by:
      selectOne in interface JdbcAggregateOperations
      Parameters:
      query - must not be null.
      entityClass - the entity type must not be null.
      Returns:
      exactly one result or Optional.empty() if no match found.
    • select

      public <T> Iterable<T> select(Query query, Class<T> entityClass)
      Description copied from interface: JdbcAggregateOperations
      Execute a SELECT query and convert the resulting items to a Iterable that is sorted.
      Specified by:
      select in interface JdbcAggregateOperations
      Parameters:
      query - must not be null.
      entityClass - the entity type must not be null.
      Returns:
      a non-null sorted list with all the matching results.
    • exists

      public <T> boolean exists(Query query, Class<T> entityClass)
      Description copied from interface: JdbcAggregateOperations
      Determine whether there are aggregates that match the Query
      Specified by:
      exists in interface JdbcAggregateOperations
      Parameters:
      query - must not be null.
      entityClass - the entity type must not be null.
      Returns:
      true if the object exists.
    • count

      public <T> long count(Query query, Class<T> entityClass)
      Description copied from interface: JdbcAggregateOperations
      Counts the number of aggregates of a given type that match the given query.
      Specified by:
      count in interface JdbcAggregateOperations
      Parameters:
      query - must not be null.
      entityClass - the entity type must not be null.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • select

      public <T> Page<T> select(Query query, Class<T> entityClass, Pageable pageable)
      Description copied from interface: JdbcAggregateOperations
      Returns a Page of entities matching the given Query. In case no match could be found, an empty Page is returned.
      Specified by:
      select in interface JdbcAggregateOperations
      Parameters:
      query - must not be null.
      entityClass - the entity type must not be null.
      pageable - can be null.
      Returns:
      a Page of entities matching the given Example.
    • findAll

      public <T> Iterable<T> findAll(Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Load all aggregates of a given type.
      Specified by:
      findAll in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate roots. Must not be null.
      Parameters:
      domainType - the type of the aggregate roots. 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: JdbcAggregateOperations
      Load all aggregates of a given type that are identified by the given ids.
      Specified by:
      findAllById in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate roots. Must not be null.
      Parameters:
      ids - of the aggregate roots identifying the aggregates to load. Must not be null.
      domainType - the type of the aggregate roots. Must not be null.
      Returns:
      Guaranteed to be not null.
    • delete

      public <S> void delete(S aggregateRoot, Class<S> domainType)
      Description copied from interface: JdbcAggregateOperations
      Delete an aggregate identified by its aggregate root.
      Specified by:
      delete in interface JdbcAggregateOperations
      Type Parameters:
      S - the type of the aggregate root.
      Parameters:
      aggregateRoot - to delete. Must not be null.
      domainType - the type of the aggregate root. Must not be null.
    • deleteById

      public <S> void deleteById(Object id, Class<S> domainType)
      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 interface JdbcAggregateOperations
      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 be null.
      domainType - the type of the aggregate root.
    • deleteAllById

      public <T> void deleteAllById(Iterable<?> ids, Class<T> domainType)
      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 interface JdbcAggregateOperations
      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 be null.
      domainType - the type of the aggregate root.
    • deleteAll

      public void deleteAll(Class<?> domainType)
      Description copied from interface: JdbcAggregateOperations
      Delete all aggregates of a given type.
      Specified by:
      deleteAll in interface JdbcAggregateOperations
      Parameters:
      domainType - type of the aggregate roots to be deleted. Must not be null.
    • deleteAll

      public <T> void deleteAll(Iterable<? extends T> instances, Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Delete all aggregates identified by their aggregate roots.
      Specified by:
      deleteAll in interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate roots.
      Parameters:
      instances - to delete. Must not be null.
      domainType - type of the aggregate roots to be deleted. Must not be null.