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
ConstructorDescriptionClientPostgresRepository
(jakarta.persistence.EntityManager em) Constructs a repository layer for Client entities using PostgreSQL database. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Removes 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
- theEntityManager
used to communicate with PostgreSQL database.
-
-
Method Details
-
findAll
Retrieves all the clients from the PostgreSQL database in a list.- Specified by:
findAll
in interfaceClientRepository
- Returns:
- the
List
ofClient
s found in the repository.
-
findById
Retrieves the unique client with the specified identifier from the PostgreSQL database, if it exists.- Specified by:
findById
in interfaceClientRepository
- Parameters:
id
- the identifier of the client to find.- Returns:
- an
Optional
contained theClient
identified byid
, if it exists; anOptional
empty, otherwise.
-
findByName
Retrieves the unique client with the specified name and surname from the PostgreSQL database, if it exists.- Specified by:
findByName
in interfaceClientRepository
- Parameters:
firstName
- the name of the client to find.lastName
- the surname of the client to find.- Returns:
- an
Optional
contained theClient
namedfirstName
andlastName
, if it exists; anOptional
empty, 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:
save
in interfaceClientRepository
- Parameters:
client
- the Client to save.- Returns:
- the
Client
saved. - Throws:
IllegalArgumentException
- ifclient
is null.UpdateFailureException
- if you try to save changes of a no longer existing client.NotNullConstraintViolationException
- iffirstName
orlastName
ofclient
to save are null.UniquenessConstraintViolationException
- ifid
or[firstName, lastName]
ofclient
to 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:
delete
in interfaceClientRepository
- Parameters:
client
- the client to delete.- Throws:
IllegalArgumentException
- ifclient
is null.
-