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 repository
ID - 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 Details

    • InMemoryJpaRepository

      public InMemoryJpaRepository()
      Creates a new InMemoryJpaRepository with no primary key generator. If an entity with a null primary key is saved, an exception is thrown.
    • InMemoryJpaRepository

      public InMemoryJpaRepository(PrimaryKeyGenerator<ID> primaryKeyGenerator)
      Creates a new InMemoryJpaRepository with the provided primary key generator. If an entity with a null 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 interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • deleteAllInBatch

      public void deleteAllInBatch(Iterable<T> entities)
      Specified by:
      deleteAllInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • deleteAllByIdInBatch

      public void deleteAllByIdInBatch(Iterable<ID> ids)
      Specified by:
      deleteAllByIdInBatch in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • flush

      public void flush()
      Specified by:
      flush in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • saveAndFlush

      public <S extends T> S saveAndFlush(S entity)
      Specified by:
      saveAndFlush in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • saveAllAndFlush

      public <S extends T> List<S> saveAllAndFlush(Iterable<S> entities)
      Specified by:
      saveAllAndFlush in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • getById

      public T getById(ID id)
      Specified by:
      getById in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • getOne

      public T getOne(ID id)
      Specified by:
      getOne in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>
    • isIdField

      protected boolean isIdField(Field field)
      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 class AbstractInMemoryCrudRepository<T,ID extends Comparable<ID>>
      Parameters:
      field - the field to examine
      Returns:
      true if field is an ID field, false otherwise
    • isIdMethod

      protected boolean isIdMethod(Method method)
      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 class AbstractInMemoryCrudRepository<T,ID extends Comparable<ID>>
      Parameters:
      method - the method to examine
      Returns:
      true if method is an ID method, false otherwise
    • getIdClass

      protected Optional<Class<ID>> getIdClass(Object entity)
      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 class AbstractInMemoryCrudRepository<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 interface org.springframework.data.repository.query.QueryByExampleExecutor<T>
    • getReferenceById

      public T getReferenceById(ID id)
      Specified by:
      getReferenceById in interface org.springframework.data.jpa.repository.JpaRepository<T,ID extends Comparable<ID>>