Package io.ran

Interface CrudRepository<T,K>

Type Parameters:
T - the type of the repository
K - the type of the primary key of T, or in case of compound primary key, T itself, or Void if T does not have a primary key
All Known Subinterfaces:
CrudRepositoryBaseRepo<T,K,Q>, ValqueriesAccessDataLayer<T,K>, ValqueriesCrudRepository<T,K>
All Known Implementing Classes:
AutoCrudRepositoryImpl, CrudRepositoryTestDoubleBase, com.fracturecode.saga.repository.FairLockRepository, TestFairLockRepository, ValqueriesAccessDataLayerImpl, ValqueriesAccessDataLayerTestDouble, ValqueriesCrudRepositoryImpl

public interface CrudRepository<T,K>
Common interface for all CRUD repositories.

If the repository entity does not have a key field, the type of the key should be Void.

This will prevent using the get(K), deleteById(K) and deleteByIds(Collection) methods at compile time, as it is not possible to get an entity by its key if it does not have one.

It is still possible to query other fields and get entities by other means.

See Also:
  • Method Details

    • get

      Optional<T> get(K id)
      Get an instance of the entity by its id (primary key).

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Parameters:
      id - the id of the entity
      Returns:
      an optional containing the entity if it exists
    • getAll

      Stream<T> getAll()
      Get all instances of the entity, as a stream.
      Returns:
      an unordered stream of all instances of the entity
    • deleteById

      Delete an instance of the entity by its id (primary key).

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Parameters:
      id - the id of the entity to be deleted
      Returns:
      the result of the delete operation
    • deleteByIds

      Delete all instances of the entity which has an id (primary key) in the given collection.

      Note: If the entity does not have a primary key, this method will not be available.

      In case of compound primary key, pass the model object with the primary key fields populated.

      Parameters:
      id - a collection of ids to be deleted
      Returns:
      the result of the delete operation
    • save

      Insert a new instance of the entity or update an existing one. Will match by primary key, but not other unique keys.
      Parameters:
      t - the entity to save
      Returns:
      the result of the save operation