Interface MaterialRepository
- All Known Implementing Classes:
JsonMaterialRepository,ModernJsonMaterialRepository
public interface MaterialRepository
Port interface for material persistence operations in hexagonal architecture.
Defines the contract for material storage without specifying implementation details.
This interface represents the "port" in the ports and adapters pattern, allowing the domain layer to interact with persistence without being coupled to specific storage technologies (JSON, database, etc.).
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Method Summary
Modifier and TypeMethodDescriptionlongcount()Counts the total number of materials in the repository.booleanDeletes a material by its ID.voidDeletes all materials from the repository.booleanChecks if a material with the given ID exists.findAll()Retrieves all materials from the repository.Finds a material by its unique identifier.voidSaves a material to the repository.
-
Method Details
-
save
Saves a material to the repository. If a material with the same ID already exists, it will be updated.- Parameters:
material- the material to save- Throws:
RepositoryException- if the save operation fails
-
findById
Finds a material by its unique identifier.- Parameters:
id- the material ID- Returns:
- the material if found, empty Optional otherwise
- Throws:
RepositoryException- if the find operation fails
-
findAll
Retrieves all materials from the repository.- Returns:
- list of all materials
- Throws:
RepositoryException- if the retrieval operation fails
-
delete
Deletes a material by its ID.- Parameters:
id- the material ID to delete- Returns:
- true if the material was deleted, false if not found
- Throws:
RepositoryException- if the delete operation fails
-
exists
Checks if a material with the given ID exists.- Parameters:
id- the material ID- Returns:
- true if the material exists, false otherwise
- Throws:
RepositoryException- if the check operation fails
-
count
long count()Counts the total number of materials in the repository.- Returns:
- the number of materials
- Throws:
RepositoryException- if the count operation fails
-
deleteAll
void deleteAll()Deletes all materials from the repository.- Throws:
RepositoryException- if the clear operation fails
-