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
ConstructorDescriptionReservationMongoRepository
(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 TypeMethodDescriptionvoid
delete
(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
- theMongoClient
used to retrieve the collection.session
- theClientSession
used 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:
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 MongoDB 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 MongoDB 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 MongoDB 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 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:
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 MongoDB database, if it exists, otherwise it does nothing.- Specified by:
delete
in interfaceReservationRepository
- Parameters:
reservation
- the reservation to delete.- Throws:
IllegalArgumentException
- ifreservation
is null.
-