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 TypeMethodDescriptionvoidDeletes an entity by its primary key.voidDeletes multiple entities by their primary keys.findAll()Retrieves all entities of the managed type.Retrieves an entity by its primary key.Retrieves an entity by its primary key.Saves the given entity in the repository.voidSaves a list of entities in the repository.voidUpdates the given entity in the repository.
-
Method Details
-
findById
Retrieves an entity by its primary key.- Parameters:
primaryKey- The primary key of the entity to be retrieved.- Returns:
- An
Optionalcontaining the entity if found, or an emptyOptionalotherwise.Optional<User> user = userRepository.findById(123); if (user.isPresent()) { System.out.println("User found: " + user.get()); } else { System.out.println("User not found"); }
-
findOne
Retrieves an entity by its primary key.- Parameters:
primaryKey- The primary key of the entity to be retrieved.- Returns:
- The entity if found, or
nullotherwise.User user = userRepository.findOne(123); if (user != null) { System.out.println("User found: " + user); } else { System.out.println("User not found"); }
-
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
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
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
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
Deletes an entity by its primary key.- Parameters:
primaryKey- The primary key of the entity to be deleted.userRepository.delete(123);
-
deleteAll
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);
-