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 newInMemoryJpaRepository
with no primary key generator.InMemoryJpaRepository
(PrimaryKeyGenerator<ID> primaryKeyGenerator) Creates a newInMemoryJpaRepository
with the provided primary key generator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteAllByIdInBatch
(Iterable<ID> ids) void
void
deleteAllInBatch
(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) void
flush()
getIdClass
(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 boolean
Override this in a concrete subclass to decide if a given field is an ID field of an entity.protected boolean
isIdMethod
(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, toString
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
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
deleteInBatch, findAll, findAll
Methods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAll
Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAll
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
-
InMemoryJpaRepository
public InMemoryJpaRepository()Creates a newInMemoryJpaRepository
with no primary key generator. If an entity with anull
primary key is saved, an exception is thrown. -
InMemoryJpaRepository
Creates a newInMemoryJpaRepository
with the provided primary key generator. If an entity with anull
primary 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:
deleteAllInBatch
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
deleteAllInBatch
- Specified by:
deleteAllInBatch
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
deleteAllByIdInBatch
- Specified by:
deleteAllByIdInBatch
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
flush
public void flush()- Specified by:
flush
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
saveAndFlush
- Specified by:
saveAndFlush
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
saveAllAndFlush
- Specified by:
saveAllAndFlush
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
getById
- Specified by:
getById
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
getOne
- Specified by:
getOne
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-
isIdField
Description copied from class:AbstractInMemoryCrudRepository
Override this in a concrete subclass to decide if a given field is an ID field of an entity.- Specified by:
isIdField
in classAbstractInMemoryCrudRepository<T,
ID extends Comparable<ID>> - Parameters:
field
- the field to examine- Returns:
true
iffield
is an ID field,false
otherwise
-
isIdMethod
Description copied from class:AbstractInMemoryCrudRepository
Override this in a concrete subclass to decide if a given method is a method giving the ID of an entity.- Specified by:
isIdMethod
in classAbstractInMemoryCrudRepository<T,
ID extends Comparable<ID>> - Parameters:
method
- the method to examine- Returns:
true
ifmethod
is an ID method,false
otherwise
-
getIdClass
Description copied from class:AbstractInMemoryCrudRepository
Override this in concrete subclass to give the ID class representing a composite primary key for an entity, if any.- Specified by:
getIdClass
in 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:
findBy
in interfaceorg.springframework.data.repository.query.QueryByExampleExecutor<T>
-
getReferenceById
- Specified by:
getReferenceById
in interfaceorg.springframework.data.jpa.repository.JpaRepository<T,
ID extends Comparable<ID>>
-