Interface TemporalRepository<T,​ID>

Type Parameters:
T - the type of the entity to handle
ID - the type of the entity's identifier (referenced by UniqueKey
All Superinterfaces:
org.springframework.data.repository.CrudRepository<T,​ID>, org.springframework.data.jpa.repository.JpaRepository<T,​ID>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>, org.springframework.data.repository.PagingAndSortingRepository<T,​ID>, org.springframework.data.repository.query.QueryByExampleExecutor<T>, org.springframework.data.repository.Repository<T,​ID>, org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
All Known Implementing Classes:
TemporalRepositoryImpl

@NoRepositoryBean public interface TemporalRepository<T,​ID> extends org.springframework.data.jpa.repository.JpaRepository<T,​ID>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>, org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
A temporal repository extension of JpaRepository, JpaSpecificationExecutor and RevisionRepository.

The repository transparently keeps audit of the data on save/delete while find/count always returns the latest data.

Audit can be retrieved using the methods defined in this interface or via RevisionRepository methods.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Instant
    The date 99999999-01-01T00:00:00.000Z which is far into the future representing "infinity" time.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    count​(Instant asOfInstant)
    Returns the number of entities available at the given asOfInstant.
    long
    count​(org.springframework.data.jpa.domain.Specification<T> spec, Instant asOfInstant)
    Returns the number of instances that the given Specification will return at the given asOfInstant.
    findAll​(Instant asOfInstant)
    Returns all instances of the type T at the given asOfInstant.
    findAll​(org.springframework.data.jpa.domain.Specification<T> spec, Instant asOfInstant)
    Returns all entities matching the given Specification at the given asOfInstant.
    findAllById​(Iterable<ID> ids, Instant asOfInstant)
    Returns all instances of the type T with the given ids at the given asOfInstant.
    findById​(ID id, Instant asOfInstant)
    Retrieves an entity by its ids at the given asOfInstant.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.jpa.repository.JpaRepository

    deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getOne, saveAll, saveAllAndFlush, saveAndFlush

    Methods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor

    count, findAll, findAll, findAll, findOne

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findOne

    Methods inherited from interface org.springframework.data.repository.history.RevisionRepository

    findLastChangeRevision, findRevision, findRevisions, findRevisions
  • Field Details

    • MAX_INSTANT

      static final Instant MAX_INSTANT
      The date 99999999-01-01T00:00:00.000Z which is far into the future representing "infinity" time. This is used by ToDate to denote that an entity is current and has not been deleted.
  • Method Details

    • findById

      Optional<T> findById(@NonNull ID id, @NonNull Instant asOfInstant)
      Retrieves an entity by its ids at the given asOfInstant.
      Parameters:
      id - must not be null.
      asOfInstant - must not be null.
      Returns:
      the entity with the given id or Optional#empty() if none found.
      Throws:
      IllegalArgumentException - if id or asOfInstant are null.
    • findAllById

      List<T> findAllById(@NonNull Iterable<ID> ids, Instant asOfInstant)
      Returns all instances of the type T with the given ids at the given asOfInstant.

      If some or all ids are not found, no entities are returned for these IDs.

      Note that the order of elements in the result is not guaranteed.

      Parameters:
      ids - must not be null nor contain any null values.
      asOfInstant - can be null in which case all of the audit related to ids are returned.
      Returns:
      guaranteed to be not null. The size can be equal or less than the number of given ids.
      Throws:
      IllegalArgumentException - in case the given ids or one of its items is null.
    • findAll

      List<T> findAll(@NonNull Instant asOfInstant)
      Returns all instances of the type T at the given asOfInstant.
      Parameters:
      asOfInstant - must not be null.
      Returns:
      all entities
    • findAll

      List<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, @NonNull Instant asOfInstant)
      Returns all entities matching the given Specification at the given asOfInstant.
      Parameters:
      spec - can be null.
      asOfInstant - must not be null.
      Returns:
      never null.
    • count

      long count(@NonNull Instant asOfInstant)
      Returns the number of entities available at the given asOfInstant.
      Parameters:
      asOfInstant - must not be null.
      Returns:
      the number of entities.
    • count

      long count(org.springframework.data.jpa.domain.Specification<T> spec, @NonNull Instant asOfInstant)
      Returns the number of instances that the given Specification will return at the given asOfInstant.
      Parameters:
      spec - the Specification to count instances for. Can be null.
      asOfInstant - must not be null.
      Returns:
      the number of instances.