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
ConstructorsConstructorDescriptionReservationPostgresRepository(jakarta.persistence.EntityManager em) Constructs a repository layer for Reservation entities using PostgreSQL database. -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete(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- theEntityManagerused to communicate with PostgreSQL database.
-
-
Method Details
-
findAll
Retrieves all the reservations from the PostgreSQL database in a list.- Specified by:
findAllin interfaceReservationRepository- Returns:
- the
ListofReservations 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:
findByClientin interfaceReservationRepository- Parameters:
clientId- the identifier of the associated client.- Returns:
- the
ListofReservations associated withclientIdfound in the repository.
-
findById
Retrieves the unique reservation with the specified identifier from the PostgreSQL database, if it exists.- Specified by:
findByIdin interfaceReservationRepository- Parameters:
id- the identifier of the reservation to find.- Returns:
- an
Optionalcontained theReservationidentified byid, if it exists; anOptionalempty, otherwise.
-
findByDate
Retrieves the unique reservation of the specified date from the PostgreSQL database, if it exists.- Specified by:
findByDatein interfaceReservationRepository- Parameters:
date- the date of the reservation to find.- Returns:
- an
Optionalcontained theReservationondate, if it exists; anOptionalempty, 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:
savein interfaceReservationRepository- Parameters:
reservation- the reservation to save.- Returns:
- the
Reservationsaved. - Throws:
IllegalArgumentException- ifreservationis null.UpdateFailureException- if you try to save changes of a no longer existing reservation.NotNullConstraintViolationException- ifdateorclientIdofreservationto save are null.UniquenessConstraintViolationException- ifidordateofreservationto 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:
deletein interfaceReservationRepository- Parameters:
reservation- the reservation to delete.- Throws:
IllegalArgumentException- ifreservationis null.
-