Interface Data.BasicRepository<E,ID>

Type Parameters:
E - the entity type
ID - the identifier type
All Superinterfaces:
Data.GenericRepository<E,ID>
All Known Subinterfaces:
Data.CrudRepository<E,ID>
Enclosing class:
Data

public static interface Data.BasicRepository<E,ID> extends Data.GenericRepository<E,ID>
Data repository interface for basic entity operations.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Return the number of all entities of the E type.
    void
    delete(E entity)
    Delete provided entity.
    long
    Delete all entities of the E type.
    void
    deleteAll(Iterable<? extends E> entities)
    Delete all provided entities.
    long
    Delete the entity with the given ID (primary key).
    boolean
    Check whether entity with given ID (primary key) exists.
    Return all entities of the E type.
    Find entity by ID (primary key) value.
    <T extends E>
    T
    save(T entity)
    Save provided entity.
    <T extends E>
    Iterable<T>
    saveAll(Iterable<T> entities)
    Save all provided entities.
  • Method Details

    • save

      <T extends E> T save(T entity)
      Save provided entity. This method will update existing record or insert a new record if record does not exist in the database.
      Type Parameters:
      T - type of the entity
      Parameters:
      entity - the entity to persist, shall not be null
      Returns:
      persisted entity. Never returns null
      Throws:
      DataException - if the entity is null or the operation has failed
    • saveAll

      <T extends E> Iterable<T> saveAll(Iterable<T> entities)
      Save all provided entities. This method will update existing record or insert a new record if record does not exist in the database.
      Type Parameters:
      T - type of the entity
      Parameters:
      entities - the entities to persist, shall not be null
      Returns:
      persisted entities, never returns null
      Throws:
      DataException - if the entities are null or the operation has failed
    • findById

      Optional<E> findById(ID id)
      Find entity by ID (primary key) value.
      Parameters:
      id - the ID of the entity to search for, shall not be null
      Returns:
      the entity with the given ID or Optional#empty() if no such entity was found, never returns null
      Throws:
      DataException - if the ID is null or the operation has failed
    • existsById

      boolean existsById(ID id)
      Check whether entity with given ID (primary key) exists.
      Parameters:
      id - the ID of the entity to search for, shall not be null
      Returns:
      value of true if an entity with the given ID exists or false otherwise
      Throws:
      DataException - if the ID is null or the operation has failed
    • findAll

      Stream<E> findAll()
      Return all entities of the E type. This method will return all records from related database table, so it should be used carefully to avoid performance issues.
      Returns:
      all entities found, never returns null
      Throws:
      DataException - if the operation has failed
    • count

      long count()
      Return the number of all entities of the E type.
      Returns:
      the number of all entities found
      Throws:
      DataException - if the operation has failed
    • deleteById

      long deleteById(ID id)
      Delete the entity with the given ID (primary key).
      Parameters:
      id - ID of the entity to be deleted, shall not be null
      Returns:
      the number of deleted entities
      Throws:
      DataException - if the ID is null or the operation has failed
    • delete

      void delete(E entity)
      Delete provided entity.
      Parameters:
      entity - the entity to delete, shall not be null
      Throws:
      DataException - if the entity is null or the operation has failed
    • deleteAll

      void deleteAll(Iterable<? extends E> entities)
      Delete all provided entities.
      Parameters:
      entities - the entities to delete, shall not be null
      Throws:
      DataException - if the entities are null or the operation has failed
    • deleteAll

      long deleteAll()
      Delete all entities of the E type. This method will delete all records from related database table, so it should be used carefully to avoid unexpected loss of data.
      Returns:
      the number of deleted entities
      Throws:
      DataException - if the operation has failed