Class TemporalRepositoryImpl<T,​ID>

java.lang.Object
org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
dev.claudio.jpatemporal.repository.impl.TemporalRepositoryImpl<T,​ID>
All Implemented Interfaces:
TemporalRepository<T,​ID>, org.springframework.data.jpa.repository.JpaRepository<T,​ID>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>, org.springframework.data.jpa.repository.support.JpaRepositoryImplementation<T,​ID>, org.springframework.data.repository.CrudRepository<T,​ID>, org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>, org.springframework.data.repository.PagingAndSortingRepository<T,​ID>, org.springframework.data.repository.query.QueryByExampleExecutor<T>, org.springframework.data.repository.Repository<T,​ID>

@NoRepositoryBean public class TemporalRepositoryImpl<T,​ID> extends org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID> implements TemporalRepository<T,​ID>
Default implementation of the TemporalRepository interface.

This implementation extends SimpleJpaRepository overriding the required methods so that all save/delete queries don't remove data from the database and instead use "from" and "to date" attributes to keep track of what's been delete and what's current. Find/exist queries are also overridden in order for them to use those same attributes and return only the current data.

  • Field Summary

    Fields inherited from interface dev.claudio.jpatemporal.repository.TemporalRepository

    MAX_INSTANT
  • Constructor Summary

    Constructors
    Constructor
    Description
    TemporalRepositoryImpl​(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,​ID> entityInformation, javax.persistence.EntityManager em)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
     
    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.
    void
    delete​(T entity)
     
    void
     
    void
     
    void
    deleteAllInBatch​(Iterable<T> entities)
     
    void
    deleteById​(ID id)
     
    protected int
    deleteById​(ID id, Instant currentTime)
     
    protected int
    deleteByIds​(Set<ID> ids, Instant currentTime)
     
    void
    deleteInBatch​(Iterable<T> entities)
    Deprecated.
    boolean
    existsById​(ID id)
     
    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)
    *************************************************************************************************************** ********************************** JpaRepository ****************************************************************************************************************
    findById​(ID id, Instant asOfInstant)
    *************************************************************************************************************** ********************************** TemporalRepository ****************************************************************************************************************
    Optional<org.springframework.data.history.Revision<Integer,​T>>
    *************************************************************************************************************** ********************************** RevisionRepository ****************************************************************************************************************
    Optional<org.springframework.data.history.Revision<Integer,​T>>
    findRevision​(ID id, Integer revisionNumber)
     
    org.springframework.data.history.Revisions<Integer,​T>
     
    org.springframework.data.domain.Page<org.springframework.data.history.Revision<Integer,​T>>
    findRevisions​(ID id, org.springframework.data.domain.Pageable pageable)
     
    protected List<org.springframework.data.history.Revision<Integer,​T>>
     
    protected <S extends T>
    javax.persistence.TypedQuery<Long>
    getCountQuery​(org.springframework.data.jpa.domain.Specification<S> spec, Class<S> domainClass)
     
    protected ID
    getIdFromEntity​(T entity)
    *************************************************************************************************************** ********************************** Other non-overridden methods *****************************************************************************************************************
    getOne​(ID id)
    Deprecated.
    protected <S extends T>
    javax.persistence.TypedQuery<S>
    getQuery​(org.springframework.data.jpa.domain.Specification<S> spec, Class<S> domainClass, org.springframework.data.domain.Sort sort)
     
    protected javax.persistence.criteria.Predicate
    inIdPredicate​(Iterable<ID> ids, javax.persistence.criteria.Root<? extends T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
     
    protected org.springframework.data.jpa.domain.Specification<T>
    inIdSpec​(Iterable<ID> ids)
    *************************************************************************************************************** ********************************** Predicates and Specifications *****************************************************************************************************************
    <S extends T>
    S
    save​(S entity)
     
    protected javax.persistence.criteria.Predicate
    toAndFromPredicate​(Instant asOfInstant, javax.persistence.criteria.Root<? extends T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
     
    protected org.springframework.data.jpa.domain.Specification<T>
     

    Methods inherited from class org.springframework.data.jpa.repository.support.SimpleJpaRepository

    count, count, deleteAll, deleteAll, deleteAllById, exists, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findAll, findOne, findOne, flush, getById, getCountQuery, getDomainClass, getQuery, getQuery, getQuery, getQueryHints, getRepositoryMethodMetadata, readPage, readPage, saveAll, saveAllAndFlush, saveAndFlush, setEscapeCharacter, setRepositoryMethodMetadata

    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.repository.CrudRepository

    deleteAll, deleteAll, deleteAllById

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

    findAll, findAll, findAll, findAll, flush, getById, 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
  • Constructor Details

    • TemporalRepositoryImpl

      public TemporalRepositoryImpl(org.springframework.data.jpa.repository.support.JpaEntityInformation<T,​ID> entityInformation, javax.persistence.EntityManager em)
  • Method Details

    • findById

      public Optional<T> findById(@NonNull ID id, @NonNull Instant asOfInstant)
      *************************************************************************************************************** ********************************** TemporalRepository ****************************************************************************************************************
      Specified by:
      findById in interface TemporalRepository<T,​ID>
      Parameters:
      id - must not be null.
      asOfInstant - must not be null.
      Returns:
      the entity with the given id or Optional#empty() if none found.
    • findAllById

      public List<T> findAllById(@NonNull Iterable<ID> ids, Instant asOfInstant)
      Description copied from interface: TemporalRepository
      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.

      Specified by:
      findAllById in interface TemporalRepository<T,​ID>
      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.
    • findAll

      public List<T> findAll(@NonNull Instant asOfInstant)
      Description copied from interface: TemporalRepository
      Returns all instances of the type T at the given asOfInstant.
      Specified by:
      findAll in interface TemporalRepository<T,​ID>
      Parameters:
      asOfInstant - must not be null.
      Returns:
      all entities
    • findAll

      public List<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, @NonNull Instant asOfInstant)
      Description copied from interface: TemporalRepository
      Returns all entities matching the given Specification at the given asOfInstant.
      Specified by:
      findAll in interface TemporalRepository<T,​ID>
      Parameters:
      spec - can be null.
      asOfInstant - must not be null.
      Returns:
      never null.
    • count

      public long count(@NonNull Instant asOfInstant)
      Description copied from interface: TemporalRepository
      Returns the number of entities available at the given asOfInstant.
      Specified by:
      count in interface TemporalRepository<T,​ID>
      Parameters:
      asOfInstant - must not be null.
      Returns:
      the number of entities.
    • count

      public long count(org.springframework.data.jpa.domain.Specification<T> spec, @NonNull Instant asOfInstant)
      Description copied from interface: TemporalRepository
      Returns the number of instances that the given Specification will return at the given asOfInstant.
      Specified by:
      count in interface TemporalRepository<T,​ID>
      Parameters:
      spec - the Specification to count instances for. Can be null.
      asOfInstant - must not be null.
      Returns:
      the number of instances.
    • findById

      @NonNull public Optional<T> findById(@NonNull ID id)
      *************************************************************************************************************** ********************************** JpaRepository ****************************************************************************************************************
      Specified by:
      findById in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      findById in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • existsById

      public boolean existsById(@NonNull ID id)
      Specified by:
      existsById in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      existsById in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • findAllById

      @NonNull public List<T> findAllById(@NonNull Iterable<ID> ids)
      Specified by:
      findAllById in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Specified by:
      findAllById in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
      Overrides:
      findAllById in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • getOne

      @NonNull @Deprecated public T getOne(@NonNull ID id)
      Deprecated.
      Specified by:
      getOne in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
      Overrides:
      getOne in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • count

      public long count()
      Specified by:
      count in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      count in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • save

      @NonNull @Transactional public <S extends T> S save(@NonNull S entity)
      Specified by:
      save in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      save in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • deleteById

      @NonNull public void deleteById(@NonNull ID id)
      Specified by:
      deleteById in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      deleteById in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • delete

      public void delete(@NonNull T entity)
      Specified by:
      delete in interface org.springframework.data.repository.CrudRepository<T,​ID>
      Overrides:
      delete in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • deleteAllInBatch

      public void deleteAllInBatch()
      Specified by:
      deleteAllInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
      Overrides:
      deleteAllInBatch in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • deleteAllInBatch

      public void deleteAllInBatch(@NonNull Iterable<T> entities)
      Specified by:
      deleteAllInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
      Overrides:
      deleteAllInBatch in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • deleteAllByIdInBatch

      public void deleteAllByIdInBatch(@NonNull Iterable<ID> ids)
      Specified by:
      deleteAllByIdInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
      Overrides:
      deleteAllByIdInBatch in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • deleteInBatch

      @Deprecated public void deleteInBatch(@NonNull Iterable<T> entities)
      Deprecated.
      Specified by:
      deleteInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,​ID>
    • getQuery

      @NonNull protected <S extends T> javax.persistence.TypedQuery<S> getQuery(org.springframework.data.jpa.domain.Specification<S> spec, @NonNull Class<S> domainClass, @NonNull org.springframework.data.domain.Sort sort)
      Overrides:
      getQuery in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • getCountQuery

      @NonNull protected <S extends T> javax.persistence.TypedQuery<Long> getCountQuery(org.springframework.data.jpa.domain.Specification<S> spec, @NonNull Class<S> domainClass)
      Overrides:
      getCountQuery in class org.springframework.data.jpa.repository.support.SimpleJpaRepository<T,​ID>
    • findLastChangeRevision

      @NonNull public Optional<org.springframework.data.history.Revision<Integer,​T>> findLastChangeRevision(@NonNull ID id)
      *************************************************************************************************************** ********************************** RevisionRepository ****************************************************************************************************************
      Specified by:
      findLastChangeRevision in interface org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
    • findRevisions

      @NonNull public org.springframework.data.history.Revisions<Integer,​T> findRevisions(@NonNull ID id)
      Specified by:
      findRevisions in interface org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
    • findRevisions

      @NonNull public org.springframework.data.domain.Page<org.springframework.data.history.Revision<Integer,​T>> findRevisions(@NonNull ID id, @NonNull org.springframework.data.domain.Pageable pageable)
      Specified by:
      findRevisions in interface org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
    • findRevision

      @NonNull public Optional<org.springframework.data.history.Revision<Integer,​T>> findRevision(@NonNull ID id, @NonNull Integer revisionNumber)
      Specified by:
      findRevision in interface org.springframework.data.repository.history.RevisionRepository<T,​ID,​Integer>
    • inIdSpec

      @NonNull protected org.springframework.data.jpa.domain.Specification<T> inIdSpec(@NonNull Iterable<ID> ids)
      *************************************************************************************************************** ********************************** Predicates and Specifications *****************************************************************************************************************
    • inIdPredicate

      @NonNull protected javax.persistence.criteria.Predicate inIdPredicate(@NonNull Iterable<ID> ids, javax.persistence.criteria.Root<? extends T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • toAndFromSpecification

      @NonNull protected org.springframework.data.jpa.domain.Specification<T> toAndFromSpecification(Instant asOfInstant)
    • toAndFromPredicate

      @NonNull protected javax.persistence.criteria.Predicate toAndFromPredicate(Instant asOfInstant, javax.persistence.criteria.Root<? extends T> root, javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • getIdFromEntity

      protected ID getIdFromEntity(T entity)
      *************************************************************************************************************** ********************************** Other non-overridden methods *****************************************************************************************************************
    • deleteById

      protected int deleteById(ID id, Instant currentTime)
    • deleteByIds

      protected int deleteByIds(Set<ID> ids, Instant currentTime)
    • findRevisionsList

      protected List<org.springframework.data.history.Revision<Integer,​T>> findRevisionsList(@NonNull ID id)