Class ReservationMongoRepository
java.lang.Object
io.github.marcopaglio.booking.repository.mongo.MongoRepository<Reservation>
io.github.marcopaglio.booking.repository.mongo.ReservationMongoRepository
- All Implemented Interfaces:
ReservationRepository
public class ReservationMongoRepository
extends MongoRepository<Reservation>
implements ReservationRepository
Implementation of repository layer through MongoDB for Reservation entities of the booking application.
-
Field Summary
Fields inherited from class io.github.marcopaglio.booking.repository.mongo.MongoRepository
collection, session -
Constructor Summary
ConstructorsConstructorDescriptionReservationMongoRepository(com.mongodb.client.MongoClient client, com.mongodb.client.ClientSession session, String databaseName) Constructs a repository layer for Reservation entities using MongoDB database. -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete(Reservation reservation) Removes the unique specified reservation from the MongoDB database, if it exists, otherwise it does nothing.findAll()Retrieves all the reservations from the database in a list.findByClient(UUID clientId) Retrieves all the reservations associated with the specified client's identifier from the MongoDB database in a list.findByDate(LocalDate date) Retrieves the unique reservation of the specified date from the MongoDB database, if it exists.Retrieves the unique reservation with the specified identifier from the MongoDB database, if it exists.save(Reservation reservation) Insert a new reservation in the MongoDB database or saves changes of an existing one.Methods inherited from class io.github.marcopaglio.booking.repository.mongo.MongoRepository
getCollection
-
Constructor Details
-
ReservationMongoRepository
public ReservationMongoRepository(com.mongodb.client.MongoClient client, com.mongodb.client.ClientSession session, String databaseName) Constructs a repository layer for Reservation entities using MongoDB database. The construction generates and configures a collection for using by the repository.- Parameters:
client- theMongoClientused to retrieve the collection.session- theClientSessionused to communicate with MongoDB database.databaseName- the name of the database in which the repository works.
-
-
Method Details
-
findAll
Retrieves all the reservations from the 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 MongoDB 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 MongoDB 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 MongoDB 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 MongoDB 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 MongoDB database, if it exists, otherwise it does nothing.- Specified by:
deletein interfaceReservationRepository- Parameters:
reservation- the reservation to delete.- Throws:
IllegalArgumentException- ifreservationis null.
-