Interface TemporalRepository<T,ID>
- Type Parameters:
T- the type of the entity to handleID- the type of the entity's identifier (referenced byUniqueKey
- 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
FieldsModifier and TypeFieldDescriptionstatic InstantThe date 99999999-01-01T00:00:00.000Z which is far into the future representing "infinity" time. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the number of entities available at the givenasOfInstant.longReturns the number of instances that the givenSpecificationwill return at the givenasOfInstant.Returns all instances of the typeTat the givenasOfInstant.Returns all entities matching the givenSpecificationat the givenasOfInstant.findAllById(Iterable<ID> ids, Instant asOfInstant)Returns all instances of the typeTwith the givenidsat the givenasOfInstant.Retrieves an entity by itsidsat the givenasOfInstant.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, findAll, findAll, findAllById, flush, getById, getOne, saveAll, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
count, findAll, findAll, findAll, findOneMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findOneMethods inherited from interface org.springframework.data.repository.history.RevisionRepository
findLastChangeRevision, findRevision, findRevisions, findRevisions
-
Field Details
-
MAX_INSTANT
The date 99999999-01-01T00:00:00.000Z which is far into the future representing "infinity" time. This is used byToDateto denote that an entity is current and has not been deleted.
-
-
Method Details
-
findById
Retrieves an entity by itsidsat the givenasOfInstant.- 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
Returns all instances of the typeTwith the givenidsat the givenasOfInstant.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 toidsare 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 givenidsor one of its items is null.
-
findAll
Returns all instances of the typeTat the givenasOfInstant.- 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 givenSpecificationat the givenasOfInstant.- Parameters:
spec- can be null.asOfInstant- must not be null.- Returns:
- never null.
-
count
Returns the number of entities available at the givenasOfInstant.- 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 givenSpecificationwill return at the givenasOfInstant.- Parameters:
spec- theSpecificationto count instances for. Can be null.asOfInstant- must not be null.- Returns:
- the number of instances.
-