Class ReservationPostgresRepository
java.lang.Object
io.github.marcopaglio.booking.repository.postgres.ReservationPostgresRepository
- All Implemented Interfaces:
ReservationRepository
Implementation of repository layer through PostgreSQL for Reservation entities of the booking application.
-
Constructor Summary
ConstructorDescriptionReservationPostgresRepository
(jakarta.persistence.EntityManager em) Constructs a repository layer for Reservation entities using PostgreSQL database. -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete
(Reservation reservation) Removes the unique specified reservation from the PostgreSQL database, if it exists, otherwise it does nothing.findAll()
Retrieves all the reservations from the PostgreSQL database in a list.findByClient
(UUID clientId) Retrieves all the reservations associated with the specified client's identifier from the PostgreSQL database in a list.findByDate
(LocalDate date) Retrieves the unique reservation of the specified date from the PostgreSQL database, if it exists.Retrieves the unique reservation with the specified identifier from the PostgreSQL database, if it exists.save
(Reservation reservation) Insert a new reservation in the PostgreSQL database or saves changes of an existing one.
-
Constructor Details
-
ReservationPostgresRepository
public ReservationPostgresRepository(jakarta.persistence.EntityManager em) Constructs a repository layer for Reservation entities using PostgreSQL database.- Parameters:
em
- theEntityManager
used to communicate with PostgreSQL database.
-
-
Method Details
-
findAll
Retrieves all the reservations from the PostgreSQL database in a list.- Specified by:
findAll
in interfaceReservationRepository
- Returns:
- the
List
ofReservation
s found in the repository.
-
findByClient
Retrieves all the reservations associated with the specified client's identifier from the PostgreSQL database in a list.- Specified by:
findByClient
in interfaceReservationRepository
- Parameters:
clientId
- the identifier of the associated client.- Returns:
- the
List
ofReservation
s associated withclientId
found in the repository.
-
findById
Retrieves the unique reservation with the specified identifier from the PostgreSQL database, if it exists.- Specified by:
findById
in interfaceReservationRepository
- Parameters:
id
- the identifier of the reservation to find.- Returns:
- an
Optional
contained theReservation
identified byid
, if it exists; anOptional
empty, otherwise.
-
findByDate
Retrieves the unique reservation of the specified date from the PostgreSQL database, if it exists.- Specified by:
findByDate
in interfaceReservationRepository
- Parameters:
date
- the date of the reservation to find.- Returns:
- an
Optional
contained theReservation
ondate
, if it exists; anOptional
empty, otherwise.
-
save
public Reservation save(Reservation reservation) throws IllegalArgumentException, UpdateFailureException, NotNullConstraintViolationException, UniquenessConstraintViolationException Insert a new reservation in the PostgreSQL database or saves changes of an existing one. Note: a Reservation without an identifier is considered to be entered, while with the identifier it will be updated.- Specified by:
save
in interfaceReservationRepository
- Parameters:
reservation
- the reservation to save.- Returns:
- the
Reservation
saved. - Throws:
IllegalArgumentException
- ifreservation
is null.UpdateFailureException
- if you try to save changes of a no longer existing reservation.NotNullConstraintViolationException
- ifdate
orclientId
ofreservation
to save are null.UniquenessConstraintViolationException
- ifid
ordate
ofreservation
to save are already present.
-
delete
Removes the unique specified reservation 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 interfaceReservationRepository
- Parameters:
reservation
- the reservation to delete.- Throws:
IllegalArgumentException
- ifreservation
is null.
-