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 Summary

    Constructors
    Constructor
    Description
    JdbcAggregateTemplate(ApplicationContext publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy)
    Creates a new JdbcAggregateTemplate given ApplicationContext, RelationalMappingContext and DataAccessStrategy.
    JdbcAggregateTemplate(ApplicationEventPublisher publisher, org.springframework.data.relational.core.mapping.RelationalMappingContext context, JdbcConverter converter, DataAccessStrategy dataAccessStrategy)
    Creates a new JdbcAggregateTemplate given ApplicationEventPublisher, RelationalMappingContext and DataAccessStrategy.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    count(Class<?> domainType)
    Counts the number of aggregates of a given type.
    <T> long
    count(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
    Counts the number of aggregates of a given type that match the given query.
    <S> void
    delete(S aggregateRoot)
    Delete an aggregate identified by its aggregate root.
    void
    deleteAll(Class<?> domainType)
    Delete all aggregates of a given type.
    <T> void
    deleteAll(Iterable<? extends T> instances)
    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
    exists(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
    Determine whether there are aggregates that match the Query
    <T> boolean
    existsById(Object id, Class<T> domainType)
    Checks if an aggregate identified by type and id exists in the database.
    <T> Iterable<T>
    findAll(Class<T> domainType)
    Load all aggregates of a given type.
    <T> Page<T>
    findAll(Class<T> domainType, Pageable pageable)
    Load a page of (potentially sorted) aggregates of a given type.
    <T> Iterable<T>
    findAll(Class<T> domainType, Sort sort)
    Load all aggregates of a given type, sorted.
    <T> Iterable<T>
    findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
    Execute a SELECT query and convert the resulting items to a Iterable that is sorted.
    <T> Page<T>
    findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, Pageable pageable)
    Returns a Page of entities matching the given Query.
    <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
    findById(Object id, Class<T> domainType)
    Load an aggregate from the database.
    <T> Optional<T>
    findOne(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
    Execute a SELECT 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>
    insertAll(Iterable<T> instances)
    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>
    saveAll(Iterable<T> instances)
    Saves all aggregate instances, including all the members of each aggregate instance.
    void
    Sets the callbacks to be invoked on life cycle events.
    void
    Configure whether lifecycle events such as AfterSaveEvent, 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>
    updateAll(Iterable<T> instances)
    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

  • 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:
      • AbstractRelationalEvent
    • 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.
    • insertAll

      public <T> Iterable<T> insertAll(Iterable<T> instances)
      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 interface JdbcAggregateOperations
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      instances - the aggregate roots to be inserted. Must not be null.
      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 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.
    • updateAll

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

      public <T> long count(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
      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.
      domainType - the entity type must not be null.
      Returns:
      the number of instances stored in the database. Guaranteed to be not null.
    • exists

      public <T> boolean exists(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
      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.
      domainType - the entity type must not be null.
      Returns:
      true if the object exists.
    • 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.
    • 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.
    • 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.
    • findOne

      public <T> Optional<T> findOne(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Execute a SELECT query and convert the resulting item to an entity ensuring exactly one result.
      Specified by:
      findOne in interface JdbcAggregateOperations
      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

      public <T> Iterable<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType)
      Description copied from interface: JdbcAggregateOperations
      Execute a SELECT query and convert the resulting items to a Iterable that is sorted.
      Specified by:
      findAll in interface JdbcAggregateOperations
      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

      public <T> Page<T> findAll(org.springframework.data.relational.core.query.Query query, Class<T> domainType, 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:
      findAll in interface JdbcAggregateOperations
      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 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)
      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.
    • 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)
      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.