Class InMemoryJpaRepository<T,ID extends Comparable<? super ID>>
java.lang.Object
com.reallifedeveloper.tools.test.database.inmemory.AbstractInMemoryCrudRepository<T,ID>
com.reallifedeveloper.tools.test.database.inmemory.InMemoryJpaRepository<T,ID>
- Type Parameters:
T- the type of the entities handled by this repositoryID- the type of the entities' primary keys
- All Implemented Interfaces:
org.springframework.data.jpa.repository.JpaRepository<T,,ID> org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>,org.springframework.data.repository.CrudRepository<T,,ID> org.springframework.data.repository.ListCrudRepository<T,,ID> org.springframework.data.repository.ListPagingAndSortingRepository<T,,ID> org.springframework.data.repository.PagingAndSortingRepository<T,,ID> org.springframework.data.repository.query.QueryByExampleExecutor<T>,org.springframework.data.repository.Repository<T,ID>
public class InMemoryJpaRepository<T,ID extends Comparable<? super ID>>
extends AbstractInMemoryCrudRepository<T,ID>
implements org.springframework.data.jpa.repository.JpaRepository<T,ID>, org.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
An implementation of the Spring Data JPA
JpaRepository interface that holds entities in a map. Useful for testing.- Author:
- RealLifeDeveloper
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.jpa.repository.JpaSpecificationExecutor
org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<T> -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newInMemoryJpaRepositorywith no primary key generator.InMemoryJpaRepository(PrimaryKeyGenerator<ID> primaryKeyGenerator) Creates a newInMemoryJpaRepositorywith the provided primary key generator. -
Method Summary
Modifier and TypeMethodDescriptionlonglonglonglongvoiddeleteAllByIdInBatch(Iterable<ID> ids) voidvoiddeleteAllInBatch(Iterable<T> entities) booleanbooleanorg.springframework.data.domain.Page<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable) findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Sort sort) org.springframework.data.domain.Page<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.jpa.domain.Specification<T> countSpec, org.springframework.data.domain.Pageable pageable) <S extends T,R>
RfindBy(org.springframework.data.domain.Example<S> example, Function<org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery<S>, R> queryFunction) <S extends T,R>
RfindBy(org.springframework.data.jpa.domain.PredicateSpecification<T> spec, Function<? super org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<S>, R> queryFunction) <S extends T,R>
RfindBy(org.springframework.data.jpa.domain.Specification<T> spec, Function<? super org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<S>, R> queryFunction) voidflush()getCompositeIdClass(Object entity) Override this in concrete subclass to give the ID class representing a composite primary key for an entity, if any.getReferenceById(ID id) protected booleanOverride this in a concrete subclass to decide if a given field is an ID field of an entity.protected booleanisIdMethod(Method method) Override this in a concrete subclass to decide if a given method is a method giving the ID of an entity.Gives thePredicateSpecificationEvaluatorused by this repository.saveAllAndFlush(Iterable<S> entities) <S extends T>
SsaveAndFlush(S entity) longMethods inherited from class com.reallifedeveloper.tools.test.database.inmemory.AbstractInMemoryCrudRepository
count, count, delete, deleteAll, deleteAll, deleteAllById, deleteById, exists, existsById, finalize, findAll, findAll, findAll, findAll, findAll, findAll, findAllById, findByField, findById, findByUniqueField, findOne, getId, save, saveAll, setId, toStringMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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
deleteInBatch, findAll, findAllMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findOne
-
Constructor Details
-
InMemoryJpaRepository
public InMemoryJpaRepository()Creates a newInMemoryJpaRepositorywith no primary key generator. If an entity with anullprimary key is saved, an exception is thrown. -
InMemoryJpaRepository
Creates a newInMemoryJpaRepositorywith the provided primary key generator. If an entity with anullprimary key is saved, the generator is used to create a new primary key that is stored in the entity before saving.- Parameters:
primaryKeyGenerator- the primary key generator to use
-
-
Method Details
-
predicateSpecificationEvaluator
Gives thePredicateSpecificationEvaluatorused by this repository. This is useful for registering functions used byPredicateSpecifications, and could occasionally be useful to directly check if a predicate specification matches an entity.- Returns:
- the
PredicateSpecificationEvaluatorused by this repository.
-
deleteAllInBatch
public void deleteAllInBatch()- Specified by:
deleteAllInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
deleteAllInBatch
- Specified by:
deleteAllInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
deleteAllByIdInBatch
- Specified by:
deleteAllByIdInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
flush
public void flush()- Specified by:
flushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
saveAndFlush
- Specified by:
saveAndFlushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
saveAllAndFlush
- Specified by:
saveAllAndFlushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
getById
- Specified by:
getByIdin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
getOne
- Specified by:
getOnein interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
isIdField
Description copied from class:AbstractInMemoryCrudRepositoryOverride this in a concrete subclass to decide if a given field is an ID field of an entity.- Specified by:
isIdFieldin classAbstractInMemoryCrudRepository<T,ID extends Comparable<? super ID>> - Parameters:
field- the field to examine- Returns:
trueiffieldis an ID field,falseotherwise
-
isIdMethod
Description copied from class:AbstractInMemoryCrudRepositoryOverride this in a concrete subclass to decide if a given method is a method giving the ID of an entity.- Specified by:
isIdMethodin classAbstractInMemoryCrudRepository<T,ID extends Comparable<? super ID>> - Parameters:
method- the method to examine- Returns:
trueifmethodis an ID method,falseotherwise
-
getCompositeIdClass
Description copied from class:AbstractInMemoryCrudRepositoryOverride this in concrete subclass to give the ID class representing a composite primary key for an entity, if any.- Specified by:
getCompositeIdClassin classAbstractInMemoryCrudRepository<T,ID extends Comparable<? super ID>> - Parameters:
entity- the entity to examine- Returns:
- the ID class representing the composite primary key of
entity, or an empty optional if there is no such class
-
findBy
public <S extends T,R> R findBy(org.springframework.data.domain.Example<S> example, Function<org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery<S>, R> queryFunction) - Specified by:
findByin interfaceorg.springframework.data.repository.query.QueryByExampleExecutor<T>
-
getReferenceById
- Specified by:
getReferenceByIdin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<? super ID>>
-
count
- Specified by:
countin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
delete
- Specified by:
deletein interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
exists
- Specified by:
existsin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findAll
- Specified by:
findAllin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findBy
public <S extends T,R> R findBy(org.springframework.data.jpa.domain.PredicateSpecification<T> spec, Function<? super org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<S>, R> queryFunction) - Specified by:
findByin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findOne
- Specified by:
findOnein interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
delete
- Specified by:
deletein interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
count
- Specified by:
countin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
exists
- Specified by:
existsin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findAll
- Specified by:
findAllin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findAll
public org.springframework.data.domain.Page<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Pageable pageable) - Specified by:
findAllin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findAll
public List<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.domain.Sort sort) - Specified by:
findAllin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findAll
public org.springframework.data.domain.Page<T> findAll(org.springframework.data.jpa.domain.Specification<T> spec, org.springframework.data.jpa.domain.Specification<T> countSpec, org.springframework.data.domain.Pageable pageable) - Specified by:
findAllin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findBy
public <S extends T,R> R findBy(org.springframework.data.jpa.domain.Specification<T> spec, Function<? super org.springframework.data.jpa.repository.JpaSpecificationExecutor.SpecificationFluentQuery<S>, R> queryFunction) - Specified by:
findByin interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
findOne
- Specified by:
findOnein interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-
update
- Specified by:
updatein interfaceorg.springframework.data.jpa.repository.JpaSpecificationExecutor<T>
-