Interface JdbcAggregateOperations

All Known Implementing Classes:
JdbcAggregateTemplate

public interface JdbcAggregateOperations
Specifies operations one can perform on a database, based on an Domain Type.
Author:
Jens Schauder, Thomas Lang, Milan Milanov, Chirag Tailor, Diego Krupitza, Myeonghyeon Lee
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    count(Class<?> domainType)
    Counts the number of aggregates of a given type.
    <T> long
    count(Query query, Class<T> domainType)
    Counts the number of aggregates of a given type that match the given query.
    <T> void
    delete(T aggregateRoot)
    Delete an aggregate identified by its aggregate root.
    default <T> void
    delete(T aggregateRoot, Class<T> domainType)
    Deprecated.
    since 3.0 use delete(Object) instead
    void
    deleteAll(Class<?> domainType)
    Delete all aggregates of a given type.
    <T> void
    deleteAll(Iterable<? extends T> aggregateRoots)
    Delete all aggregates identified by their aggregate roots.
    default <T> void
    deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType)
    Deprecated.
    since 3.0 use deleteAll(Iterable) instead.
    <T> void
    deleteAllById(Iterable<?> ids, Class<T> domainType)
    Deletes all aggregates identified by their aggregate root ids.
    <T> void
    deleteById(Object id, Class<T> domainType)
    Deletes a single Aggregate including all entities contained in that aggregate.
    <T> boolean
    exists(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(Query query, Class<T> domainType)
    Execute a SELECT query and convert the resulting items to a Iterable that is sorted.
    <T> Page<T>
    findAll(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(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.
    <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.
    <T> T
    update(T instance)
    Dedicated update function.
    <T> Iterable<T>
    updateAll(Iterable<T> instances)
    Updates all aggregate instances, including all the members of each aggregate instance.
  • Method Details

    • save

      <T> T save(T instance)
      Saves an instance of an aggregate, including all the members of the aggregate.
      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.
      Throws:
      IncorrectUpdateSemanticsDataAccessException - when the instance is determined to be not new and the resulting update does not update any rows.
    • saveAll

      <T> Iterable<T> saveAll(Iterable<T> instances)
      Saves all aggregate instances, including all the members of each aggregate instance.
      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.
      Throws:
      IncorrectUpdateSemanticsDataAccessException - when at least one instance is determined to be not new and the resulting update does not update any rows.
      Since:
      3.0
    • insert

      <T> T insert(T instance)
      Dedicated insert function. This skips the test if the aggregate root is new and makes an insert.

      This is useful if the client provides an id for new aggregate roots.

      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

      <T> Iterable<T> insertAll(Iterable<T> instances)
      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.

      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.
      Since:
      3.1
    • update

      <T> T update(T instance)
      Dedicated update function. This skips the test if the aggregate root is new or not and always performs an update operation.
      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

      <T> Iterable<T> updateAll(Iterable<T> instances)
      Updates all aggregate instances, including all the members of each aggregate instance.
      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.
      Since:
      3.1
    • count

      long count(Class<?> domainType)
      Counts the number of aggregates of a given type.
      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

      <T> long count(Query query, Class<T> domainType)
      Counts the number of aggregates of a given type that match the given query.
      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.
      Since:
      3.0
    • exists

      <T> boolean exists(Query query, Class<T> domainType)
      Determine whether there are aggregates that match the Query
      Parameters:
      query - must not be null.
      domainType - the entity type must not be null.
      Returns:
      true if the object exists.
      Since:
      3.0
    • existsById

      <T> boolean existsById(Object id, Class<T> domainType)
      Checks if an aggregate identified by type and id exists in the database.
      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

      @Nullable <T> T findById(Object id, Class<T> domainType)
      Load an aggregate from the database.
      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.
    • findAllById

      <T> Iterable<T> findAllById(Iterable<?> ids, Class<T> domainType)
      Load all aggregates of a given type that are identified by the given ids.
      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.
    • findAll

      <T> Iterable<T> findAll(Class<T> domainType)
      Load all aggregates of a given type.
      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.
    • findAll

      <T> Iterable<T> findAll(Class<T> domainType, Sort sort)
      Load all aggregates of a given type, sorted.
      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.
      Since:
      2.0
    • findAll

      <T> Page<T> findAll(Class<T> domainType, Pageable pageable)
      Load a page of (potentially sorted) aggregates of a given type.
      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.
      Since:
      2.0
    • findOne

      <T> Optional<T> findOne(Query query, Class<T> domainType)
      Execute a SELECT query and convert the resulting item to an entity ensuring exactly one result.
      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.
      Throws:
      IncorrectResultSizeDataAccessException - if more than one match found.
      Since:
      3.0
    • findAll

      <T> Iterable<T> findAll(Query query, Class<T> domainType)
      Execute a SELECT query and convert the resulting items to a Iterable that is sorted.
      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.
      Throws:
      IncorrectResultSizeDataAccessException - if more than one match found.
      Since:
      3.0
    • findAll

      <T> Page<T> findAll(Query query, Class<T> domainType, Pageable pageable)
      Returns a Page of entities matching the given Query. In case no match could be found, an empty Page is returned.
      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.
      Since:
      3.0
    • deleteById

      <T> void deleteById(Object id, Class<T> domainType)
      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.

      Type Parameters:
      T - 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

      <T> void deleteAllById(Iterable<?> ids, Class<T> domainType)
      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.

      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.
    • delete

      <T> void delete(T aggregateRoot)
      Delete an aggregate identified by its aggregate root.
      Type Parameters:
      T - the type of the aggregate root.
      Parameters:
      aggregateRoot - to delete. Must not be null.
    • delete

      @Deprecated(since="3.0") default <T> void delete(T aggregateRoot, Class<T> domainType)
      Deprecated.
      since 3.0 use delete(Object) instead
      Delete an aggregate identified by its aggregate root.
      Type Parameters:
      T - 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.
      Throws:
      OptimisticLockingFailureException - when T has a version attribute and the version attribute of the provided entity does not match the version attribute in the database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.
    • deleteAll

      void deleteAll(Class<?> domainType)
      Delete all aggregates of a given type.
      Parameters:
      domainType - type of the aggregate roots to be deleted. Must not be null.
    • deleteAll

      <T> void deleteAll(Iterable<? extends T> aggregateRoots)
      Delete all aggregates identified by their aggregate roots.
      Type Parameters:
      T - the type of the aggregate roots.
      Parameters:
      aggregateRoots - to delete. Must not be null.
    • deleteAll

      @Deprecated(since="3.0") default <T> void deleteAll(Iterable<? extends T> aggregateRoots, Class<T> domainType)
      Deprecated.
      since 3.0 use deleteAll(Iterable) instead.
      Delete all aggregates identified by their aggregate roots.
      Type Parameters:
      T - the type of the aggregate roots.
      Parameters:
      aggregateRoots - to delete. Must not be null.
      domainType - type of the aggregate roots to be deleted. Must not be null.
      Throws:
      OptimisticLockingFailureException - when T has a version attribute and for at least on entity the version attribute of the entity does not match the version attribute in the database, or when there is no aggregate root with matching id. In other cases a NOOP delete is silently ignored.