Interface BibernateRepository<T,ID>

Type Parameters:
T - The type of the entity managed by the repository.
ID - The type of the entity's primary key.

public interface BibernateRepository<T,ID>
Generic interface for a basic Bibernate repository providing common CRUD operations.
Since:
1.0
Author:
Blyzhnytsia Team
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(ID primaryKey)
    Deletes an entity by its primary key.
    void
    Deletes multiple entities by their primary keys.
    Retrieves all entities of the managed type.
    findById(ID primaryKey)
    Retrieves an entity by its primary key.
    findOne(ID primaryKey)
    Retrieves an entity by its primary key.
    save(T entity)
    Saves the given entity in the repository.
    void
    saveAll(List<T> entities)
    Saves a list of entities in the repository.
    void
    update(T entity)
    Updates the given entity in the repository.
  • Method Details

    • findById

      Optional<T> findById(ID primaryKey)
      Retrieves an entity by its primary key.
      Parameters:
      primaryKey - The primary key of the entity to be retrieved.
      Returns:
      An Optional containing the entity if found, or an empty Optional otherwise.
      
       Optional<User> user = userRepository.findById(123);
       if (user.isPresent()) {
           System.out.println("User found: " + user.get());
       } else {
           System.out.println("User not found");
       }
       
    • findOne

      T findOne(ID primaryKey)
      Retrieves an entity by its primary key.
      Parameters:
      primaryKey - The primary key of the entity to be retrieved.
      Returns:
      The entity if found, or null otherwise.
      
       User user = userRepository.findOne(123);
       if (user != null) {
           System.out.println("User found: " + user);
       } else {
           System.out.println("User not found");
       }
       
    • findAll

      List<T> findAll()
      Retrieves all entities of the managed type.
      Returns:
      A list containing all entities in the repository.
      
       List<User> users = userRepository.findAll();
       for (User user : users) {
           System.out.println("User: " + user);
       }
       
    • update

      void update(T entity)
      Updates the given entity in the repository.
      Parameters:
      entity - The entity to be updated.
      
       User user = userRepository.findOne(123);
       user.setName("John Doe");
       userRepository.update(user);
       
    • save

      T save(T entity)
      Saves the given entity in the repository.
      Parameters:
      entity - The entity to be saved.
      Returns:
      The saved entity.
      
       User user = new User("Alice");
       userRepository.save(user);
       
    • saveAll

      void saveAll(List<T> entities)
      Saves a list of entities in the repository.
      Parameters:
      entities - The list of entities to be saved.
      
       List<User> users = Arrays.asList(new User("Alice"), new User("Bob"));
       userRepository.saveAll(users);
       
    • delete

      void delete(ID primaryKey)
      Deletes an entity by its primary key.
      Parameters:
      primaryKey - The primary key of the entity to be deleted.
      
       userRepository.delete(123);
       
    • deleteAll

      void deleteAll(List<ID> ids)
      Deletes multiple entities by their primary keys.
      Parameters:
      ids - The list of primary keys of entities to be deleted.
      
       List<Integer> userIds = Arrays.asList(123, 456, 789);
       userRepository.deleteAll(userIds);