Interface GenericRepository<T,K>

Type Parameters:
T - the type of the entity
K - the type of the entity's key

public interface GenericRepository<T,K>
GenericRepository is an interface for performing generic CRUD (Create, Read, Update, Delete) operations on entities.
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    add(T entity)
    Adds an entity to the repository.
    default void
    Deletes all entities from the repository.
    default boolean
    exists(K key)
    Determines if an entity exists for the given key.
    default Optional<T>
    find(K key)
    Finds an entity by its key.
    default List<T>
    Executes a query based on the given query specification.
    default int
    Removes entities from the repository based on the provided update specification.
    default void
    remove(T entity)
    Removes an entity from the repository.
    default int
    Updates entities in the repository based on the provided update specification.
    default T
    update(T entity)
    Updates an entity in the repository.
  • Method Details

    • query

      default List<T> query(QuerySpecification<T> spec)
      Executes a query based on the given query specification.
      Parameters:
      spec - the query specification to execute
      Returns:
      a list of entities that match the query
    • find

      default Optional<T> find(K key)
      Finds an entity by its key.
      Parameters:
      key - the key of the entity
      Returns:
      an Optional containing the entity if found, or an empty Optional if not found
    • add

      default T add(T entity)
      Adds an entity to the repository.
      Parameters:
      entity - the entity to add
      Returns:
      the added entity
    • update

      default T update(T entity)
      Updates an entity in the repository.
      Parameters:
      entity - the entity to be updated
      Returns:
      the updated entity
    • update

      default int update(UpdateSpecification spec)
      Updates entities in the repository based on the provided update specification.
      Parameters:
      spec - the update specification defining the update criteria and data
      Returns:
      the number of rows affected by the update operation
    • remove

      default void remove(T entity)
      Removes an entity from the repository.
      Parameters:
      entity - the entity to be deleted
    • remove

      default int remove(UpdateSpecification spec)
      Removes entities from the repository based on the provided update specification.
      Parameters:
      spec - the update specification defining the criteria for the removal
      Returns:
      the number of rows affected by the remove operation
    • exists

      default boolean exists(K key)
      Determines if an entity exists for the given key.
      Parameters:
      key - the entity key
    • clear

      default void clear()
      Deletes all entities from the repository.