Class TransactionalBookingService
java.lang.Object
io.github.marcopaglio.booking.service.transactional.TransactionalBookingService
- All Implemented Interfaces:
BookingService
Implements methods for operating on repositories of the booking application using transactions.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTransactionalBookingService(TransactionManager transactionManager) Constructs a service for the booking application with a transaction manager. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves all the clients saved in the database within a transaction.Retrieves all the reservations saved in the database within a transaction.findClient(UUID id) Retrieves the client with the specified id from the database within a transaction.findClientNamed(String firstName, String lastName) Retrieves the client with specified name and surname from the database within a transaction.findReservation(UUID id) Retrieves the reservation with the specified id from the database within a transaction.findReservationOn(LocalDate date) Retrieves the reservation of the specified date from the database within a transaction.insertNewClient(Client client) Adds a new client in the database within a transaction.insertNewReservation(Reservation reservation) Adds a new reservation in the database within a transaction.voidremoveClient(UUID id) Deletes the client with the specified id and all his reservation from the database within a transaction.voidremoveClientNamed(String firstName, String lastName) Deletes the client with specified name and surname and all his reservation from the database within a transaction.voidDeletes the reservation with the specified id from the database within a transaction.voidremoveReservationOn(LocalDate date) Deletes the reservation of the specified date from the database within a transaction.renameClient(UUID id, String newFirstName, String newLastName) Changes name and surname of the client with the specified id in the database within a transaction.rescheduleReservation(UUID id, LocalDate newDate) Changes date of the reservation with the specified id in the database within a transaction.
-
Constructor Details
-
TransactionalBookingService
Constructs a service for the booking application with a transaction manager.- Parameters:
transactionManager- theTransactionManagerused for applying transactions.
-
-
Method Details
-
findAllClients
Retrieves all the clients saved in the database within a transaction.- Specified by:
findAllClientsin interfaceBookingService- Returns:
- the list of clients found in the database.
- Throws:
DatabaseException- if a database error occurs.
-
findAllReservations
Retrieves all the reservations saved in the database within a transaction.- Specified by:
findAllReservationsin interfaceBookingService- Returns:
- the list of reservations found in the database.
- Throws:
DatabaseException- if a transaction failure occurs on database.
-
findClient
Retrieves the client with the specified id from the database within a transaction.- Specified by:
findClientin interfaceBookingService- Parameters:
id- the identifier of the client to find.- Returns:
- the
Clientidentified byid. - Throws:
InstanceNotFoundException- if there is no client with that id in the database.DatabaseException- if a database error occurs.
-
findReservation
Retrieves the reservation with the specified id from the database within a transaction.- Specified by:
findReservationin interfaceBookingService- Parameters:
id- the identifier of the reservation to find.- Returns:
- the
Reservationidentified byid. - Throws:
InstanceNotFoundException- if there is no reservation with that id in the database.DatabaseException- if a database error occurs.
-
findClientNamed
public Client findClientNamed(String firstName, String lastName) throws InstanceNotFoundException, DatabaseException Retrieves the client with specified name and surname from the database within a transaction.- Specified by:
findClientNamedin interfaceBookingService- Parameters:
firstName- the name of the client to find.lastName- the surname of the client to find.- Returns:
- the
ClientnamedfirstNameandlastName. - Throws:
InstanceNotFoundException- if there is no client with those names in the database.DatabaseException- if a transaction failure occurs on database.
-
findReservationOn
public Reservation findReservationOn(LocalDate date) throws InstanceNotFoundException, DatabaseException Retrieves the reservation of the specified date from the database within a transaction.- Specified by:
findReservationOnin interfaceBookingService- Parameters:
date- the date of the reservation to find.- Returns:
- the
Reservationondate. - Throws:
InstanceNotFoundException- if there is no reservation on that date in the database.DatabaseException- if a transaction failure occurs on database.
-
insertNewClient
public Client insertNewClient(Client client) throws InstanceAlreadyExistsException, DatabaseException Adds a new client in the database within a transaction. This method checks if the client is present in the database before inserting.- Specified by:
insertNewClientin interfaceBookingService- Parameters:
client- the client to insert.- Returns:
- the
Clientinserted. - Throws:
InstanceAlreadyExistsException- ifclientis already in the database.DatabaseException- if a transaction failure occurs on database.
-
insertNewReservation
public Reservation insertNewReservation(Reservation reservation) throws InstanceAlreadyExistsException, InstanceNotFoundException, DatabaseException Adds a new reservation in the database within a transaction. This method checks if the reservation is not present and the associated client is present in the database before inserting.- Specified by:
insertNewReservationin interfaceBookingService- Parameters:
reservation- the reservation to insert.- Returns:
- the
Reservationinserted. - Throws:
InstanceAlreadyExistsException- ifreservationis already in the database.InstanceNotFoundException- if the associatedclientdoesn't exist in the database.DatabaseException- if a transaction failure occurs on database.
-
removeClient
Deletes the client with the specified id and all his reservation from the database within a transaction.- Specified by:
removeClientin interfaceBookingService- Parameters:
id- the identifier of the client to remove.- Throws:
InstanceNotFoundException- if there is no client with that identifier in the database.DatabaseException- if a database error occurs.
-
removeReservation
Deletes the reservation with the specified id from the database within a transaction.- Specified by:
removeReservationin interfaceBookingService- Parameters:
id- the identifier of the reservation to remove.- Throws:
InstanceNotFoundException- if there is no reservation with that identifier in the database.DatabaseException- if a database error occurs.
-
removeClientNamed
public void removeClientNamed(String firstName, String lastName) throws InstanceNotFoundException, DatabaseException Deletes the client with specified name and surname and all his reservation from the database within a transaction. This method checks if the client is present in the database before removing.- Specified by:
removeClientNamedin interfaceBookingService- Parameters:
firstName- the name of the client to remove.lastName- the surname of the client to remove.- Throws:
InstanceNotFoundException- if there is no client with those names in the database.DatabaseException- if a transaction failure occurs on database.
-
removeReservationOn
Deletes the reservation of the specified date from the database within a transaction. This method checks if the reservation is present in the database before removing.- Specified by:
removeReservationOnin interfaceBookingService- Parameters:
date- the date of the reservation to find.- Throws:
InstanceNotFoundException- if there is no reservation on that date in the database.DatabaseException- if a transaction failure occurs on database.
-
renameClient
public Client renameClient(UUID id, String newFirstName, String newLastName) throws InstanceNotFoundException, InstanceAlreadyExistsException, DatabaseException Changes name and surname of the client with the specified id in the database within a transaction.- Specified by:
renameClientin interfaceBookingService- Parameters:
id- the identifier of the client to rename.newFirstName- the new name for the client.newLastName- the new surname for the client.- Returns:
- the
Clientrenamed. - Throws:
InstanceNotFoundException- if there is noclientwith specified id in the database.InstanceAlreadyExistsException- if aClientwith those names is already in the database.DatabaseException- if a database error occurs.
-
rescheduleReservation
public Reservation rescheduleReservation(UUID id, LocalDate newDate) throws InstanceNotFoundException, InstanceAlreadyExistsException, DatabaseException Changes date of the reservation with the specified id in the database within a transaction.- Specified by:
rescheduleReservationin interfaceBookingService- Parameters:
id- the identifier of the reservation to reschedule.newDate- the new date for the reservation.- Returns:
- the
Reservationrescheduled. - Throws:
InstanceNotFoundException- if there is noreservationwith specified id in the database.InstanceAlreadyExistsException- if areservationwith that date is already in the database.DatabaseException- if a database error occurs.
-