Class InMemoryJpaRepository<T,ID extends Comparable<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.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<ID>>
extends AbstractInMemoryCrudRepository<T,ID>
implements org.springframework.data.jpa.repository.JpaRepository<T,ID>
An implementation of the Spring Data JPA
JpaRepository interface that holds entities in a map. Useful for testing.- Author:
- RealLifeDeveloper
-
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 TypeMethodDescriptionvoiddeleteAllByIdInBatch(Iterable<ID> ids) voidvoiddeleteAllInBatch(Iterable<T> entities) <S extends T,R>
RfindBy(org.springframework.data.domain.Example<S> example, Function<org.springframework.data.repository.query.FluentQuery.FetchableFluentQuery<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.saveAllAndFlush(Iterable<S> entities) <S extends T>
SsaveAndFlush(S entity) Methods 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
-
deleteAllInBatch
public void deleteAllInBatch()- Specified by:
deleteAllInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
deleteAllInBatch
- Specified by:
deleteAllInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
deleteAllByIdInBatch
- Specified by:
deleteAllByIdInBatchin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
flush
public void flush()- Specified by:
flushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
saveAndFlush
- Specified by:
saveAndFlushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
saveAllAndFlush
- Specified by:
saveAllAndFlushin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
getById
- Specified by:
getByIdin interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
-
getOne
- Specified by:
getOnein interfaceorg.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<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<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<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<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<ID>>
-