Interface IRepository<T,ID>
- Type Parameters:
T
- Type of the entity managed by this repositoryID
- Type of the identifier used to uniquely identify entities
- All Known Subinterfaces:
IApplicationRepository
,IBookingRepository
,IEnquiryRepository
,IOfficerRegistrationRepository
,IProjectRepository
,IUserRepository
- All Known Implementing Classes:
ApplicationRepository
,BookingRepository
,EnquiryRepository
,OfficerRegistrationRepository
,ProjectRepository
,UserRepository
This interface forms the foundation of the data access layer, providing a consistent contract for all repository implementations across the system. It follows the Repository pattern to abstract data persistence and retrieval mechanisms from the business logic.
The interface is parameterized with:- T - The entity type this repository manages
- ID - The type of the entity's unique identifier
All repository implementations must adhere to this contract, ensuring consistent data access behaviors throughout the system regardless of the underlying persistence technology.
-
Method Summary
Modifier and TypeMethodDescriptionfindAll()
Retrieves all entities currently managed by this repository.Finds and retrieves a single entity by its unique identifier.loadAll()
Loads all entities from the persistent storage into memory.void
Saves an entity to the repository.void
Saves multiple entities to the repository in a batch operation.
-
Method Details
-
findById
Finds and retrieves a single entity by its unique identifier.This method attempts to locate an entity with the specified ID in the data store. If no matching entity is found, the method returns null.
- Parameters:
id
- The unique identifier of the entity to retrieve- Returns:
- The entity if found, or null if no entity exists with the given ID
-
findAll
Retrieves all entities currently managed by this repository.This method returns a map of all entities, with entity IDs as keys and entity objects as values. If the repository is empty, an empty map is returned.
- Returns:
- A map containing all entities, with IDs as keys and entity objects as values
-
save
Saves an entity to the repository.If the entity already exists in the repository (based on its ID), the existing entity will be updated with the new values. If the entity does not exist, it will be added as a new entry. The repository implementation is responsible for determining how to extract the ID from the entity.
- Parameters:
entity
- The entity to save
-
saveAll
Saves multiple entities to the repository in a batch operation.This method allows for more efficient bulk saving of entities compared to calling save() repeatedly. It takes a map of entities keyed by their IDs and persists them all, potentially in a single operation depending on the implementation.
- Parameters:
entities
- A map of entities to save, with IDs as keys and entity objects as values
-
loadAll
Loads all entities from the persistent storage into memory.This method is typically called during application initialization to populate the repository with data from the persistent store. Implementations should handle parsing and conversion from the storage format to entity objects.
- Returns:
- A map of all loaded entities, with IDs as keys and entity objects as values
- Throws:
DataAccessException
- If an error occurs during data loading or parsing
-