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
ConstructorDescriptionTransactionalBookingService
(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.void
removeClient
(UUID id) Deletes the client with the specified id and all his reservation from the database within a transaction.void
removeClientNamed
(String firstName, String lastName) Deletes the client with specified name and surname and all his reservation from the database within a transaction.void
Deletes the reservation with the specified id from the database within a transaction.void
removeReservationOn
(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
- theTransactionManager
used for applying transactions.
-
-
Method Details
-
findAllClients
Retrieves all the clients saved in the database within a transaction.- Specified by:
findAllClients
in 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:
findAllReservations
in 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:
findClient
in interfaceBookingService
- Parameters:
id
- the identifier of the client to find.- Returns:
- the
Client
identified 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:
findReservation
in interfaceBookingService
- Parameters:
id
- the identifier of the reservation to find.- Returns:
- the
Reservation
identified 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:
findClientNamed
in interfaceBookingService
- Parameters:
firstName
- the name of the client to find.lastName
- the surname of the client to find.- Returns:
- the
Client
namedfirstName
andlastName
. - 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:
findReservationOn
in interfaceBookingService
- Parameters:
date
- the date of the reservation to find.- Returns:
- the
Reservation
ondate
. - 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:
insertNewClient
in interfaceBookingService
- Parameters:
client
- the client to insert.- Returns:
- the
Client
inserted. - Throws:
InstanceAlreadyExistsException
- ifclient
is 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:
insertNewReservation
in interfaceBookingService
- Parameters:
reservation
- the reservation to insert.- Returns:
- the
Reservation
inserted. - Throws:
InstanceAlreadyExistsException
- ifreservation
is already in the database.InstanceNotFoundException
- if the associatedclient
doesn'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:
removeClient
in 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:
removeReservation
in 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:
removeClientNamed
in 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:
removeReservationOn
in 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:
renameClient
in 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
Client
renamed. - Throws:
InstanceNotFoundException
- if there is noclient
with specified id in the database.InstanceAlreadyExistsException
- if aClient
with 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:
rescheduleReservation
in interfaceBookingService
- Parameters:
id
- the identifier of the reservation to reschedule.newDate
- the new date for the reservation.- Returns:
- the
Reservation
rescheduled. - Throws:
InstanceNotFoundException
- if there is noreservation
with specified id in the database.InstanceAlreadyExistsException
- if areservation
with that date is already in the database.DatabaseException
- if a database error occurs.
-