Class ClientPostgresRepository
java.lang.Object
io.github.marcopaglio.booking.repository.postgres.ClientPostgresRepository
- All Implemented Interfaces:
ClientRepository
Implementation of repository layer through PostgreSQL for Client entities of the booking application.
-
Constructor Summary
ConstructorsConstructorDescriptionClientPostgresRepository(jakarta.persistence.EntityManager em) Constructs a repository layer for Client entities using PostgreSQL database. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the unique specified client from the PostgreSQL database, if it exists, otherwise it does nothing.findAll()Retrieves all the clients from the PostgreSQL database in a list.Retrieves the unique client with the specified identifier from the PostgreSQL database, if it exists.findByName(String firstName, String lastName) Retrieves the unique client with the specified name and surname from the PostgreSQL database, if it exists.Inserts a new Client in the PostgreSQL database or saves changes of an existing one.
-
Constructor Details
-
ClientPostgresRepository
public ClientPostgresRepository(jakarta.persistence.EntityManager em) Constructs a repository layer for Client entities using PostgreSQL database.- Parameters:
em- theEntityManagerused to communicate with PostgreSQL database.
-
-
Method Details
-
findAll
Retrieves all the clients from the PostgreSQL database in a list.- Specified by:
findAllin interfaceClientRepository- Returns:
- the
ListofClients found in the repository.
-
findById
Retrieves the unique client with the specified identifier from the PostgreSQL database, if it exists.- Specified by:
findByIdin interfaceClientRepository- Parameters:
id- the identifier of the client to find.- Returns:
- an
Optionalcontained theClientidentified byid, if it exists; anOptionalempty, otherwise.
-
findByName
Retrieves the unique client with the specified name and surname from the PostgreSQL database, if it exists.- Specified by:
findByNamein interfaceClientRepository- Parameters:
firstName- the name of the client to find.lastName- the surname of the client to find.- Returns:
- an
Optionalcontained theClientnamedfirstNameandlastName, if it exists; anOptionalempty, otherwise.
-
save
public Client save(Client client) throws IllegalArgumentException, UpdateFailureException, NotNullConstraintViolationException, UniquenessConstraintViolationException Inserts a new Client in the PostgreSQL database or saves changes of an existing one. Note: a Client without an identifier is considered to be entered, while with the identifier it will be updated. Note: this method must be executed as part of a transaction.- Specified by:
savein interfaceClientRepository- Parameters:
client- the Client to save.- Returns:
- the
Clientsaved. - Throws:
IllegalArgumentException- ifclientis null.UpdateFailureException- if you try to save changes of a no longer existing client.NotNullConstraintViolationException- iffirstNameorlastNameofclientto save are null.UniquenessConstraintViolationException- ifidor[firstName, lastName]ofclientto save are already present.
-
delete
Removes the unique specified client from the PostgreSQL database, if it exists, otherwise it does nothing. Note: this method must be executed as part of a transaction.- Specified by:
deletein interfaceClientRepository- Parameters:
client- the client to delete.- Throws:
IllegalArgumentException- ifclientis null.
-