Interface CrudRepository<T,K>

Type Parameters:
T - the entity bean type
K - the key type.
All Superinterfaces:
BasicRepository<T,K>, DataRepository<T,K>

public interface CrudRepository<T,K> extends BasicRepository<T,K>

A repository interface that extends the capabilities of basic operations on entities, including insert and update operations.

This repository extends the BasicRepository interface, providing a comprehensive set of methods to interact with persistent entities of type <T>, where <T> represents the entity bean type, and <K> represents the key type.

It encompasses standard CRUD (Create, Read, Update, Delete) operations, allowing you to perform insert and update operations in addition to basic retrieval and deletion. This interface combines the Data Access Object (DAO) aspect with the repository pattern, offering a versatile and complete solution for managing persistent entities within your Java applications.

See Also:
  • Method Details

    • insert

      @Insert <S extends T> S insert(S entity)

      Inserts an entity into the database. If an entity of this type with the same unique identifier already exists in the database and the database supports ACID transactions, then this method raises EntityExistsException. In databases that follow the BASE model or use an append model to write data, this exception is not thrown.

      The entity instance returned as a result of this method must include all values that were written to the database, including all automatically generated values and incremented values that changed due to the insert. After invoking this method, do not continue to use the instance that is supplied as a parameter. This method makes no guarantees about the state of the instance that is supplied as a parameter.

      Type Parameters:
      S - Type of the entity to insert.
      Parameters:
      entity - the entity to insert. Must not be null.
      Returns:
      the inserted entity, which may or may not be a different instance depending on whether the insert caused values to be generated or automatically incremented.
      Throws:
      EntityExistsException - if the entity is already present in the database (in ACID-supported databases).
      NullPointerException - if the entity is null.
    • insertAll

      @Insert <S extends T> Iterable<S> insertAll(Iterable<S> entities)

      Inserts multiple entities into the database. If any entity of this type with the same unique identifier as any of the given entities already exists in the database and the database supports ACID transactions, then this method raises EntityExistsException. In databases that follow the BASE model or use an append model to write data, this exception is not thrown.

      The entities within the returned Iterable must include all values that were written to the database, including all automatically generated values and incremented values that changed due to the insert. After invoking this method, do not continue to use the entity instances that are supplied in the parameter. This method makes no guarantees about the state of the entity instances that are supplied in the parameter. The position of entities within the Iterable return value must correspond to the position of entities in the parameter based on the unique identifier of the entity.

      Type Parameters:
      S - Type of the entities to insert.
      Parameters:
      entities - entities to insert.
      Returns:
      an iterable containing the inserted entities, which may or may not be different instances depending on whether the insert caused values to be generated or automatically incremented.
      Throws:
      EntityExistsException - if any of the entities are already present in the database (in ACID-supported databases).
      NullPointerException - if the iterable is null or any element is null.
    • update

      @Update boolean update(T entity)

      Modifies an entity that already exists in the database.

      For an update to be made, a matching entity with the same unique identifier must be present in the database. In databases that use an append model to write data or follow the BASE model, this method behaves the same as the insert(S) method.

      If the entity is versioned (for example, with jakarta.persistence.Version or by another convention from the entity model such as having an attribute named version), then the version must also match. The version is automatically incremented when making the update.

      Non-matching entities are ignored and do not cause an error to be raised.

      Parameters:
      entity - the entity to update. Must not be null.
      Returns:
      true if a matching entity was found in the database to update, otherwise false.
      Throws:
      NullPointerException - if the entity is null.
    • updateAll

      @Update int updateAll(Iterable<T> entities)

      Modifies entities that already exist in the database.

      For an update to be made to an entity, a matching entity with the same unique identifier must be present in the database. In databases that use an append model to write data or follow the BASE model, this method behaves the same as the insertAll(java.lang.Iterable<S>) method.

      If the entity is versioned (for example, with jakarta.persistence.Version or by another convention from the entity model such as having an attribute named version), then the version must also match. The version is automatically incremented when making the update.

      Non-matching entities are ignored and do not cause an error to be raised.

      Parameters:
      entities - entities to update.
      Returns:
      the number of matching entities that were found in the database to update.
      Throws:
      NullPointerException - if either the iterable is null or any element is null.