Class ClientMongoRepository
java.lang.Object
io.github.marcopaglio.booking.repository.mongo.MongoRepository<Client>
io.github.marcopaglio.booking.repository.mongo.ClientMongoRepository
- All Implemented Interfaces:
ClientRepository
Implementation of repository layer through MongoDB for Client entities of the booking application.
-
Field Summary
Fields inherited from class io.github.marcopaglio.booking.repository.mongo.MongoRepository
collection, session -
Constructor Summary
ConstructorsConstructorDescriptionClientMongoRepository(com.mongodb.client.MongoClient client, com.mongodb.client.ClientSession session, String databaseName) Constructs a repository layer for Client entities using MongoDB database. -
Method Summary
Modifier and TypeMethodDescriptionvoidRemoves the unique specified client from the MongoDB database, if it exists, otherwise it does nothing.findAll()Retrieves all the clients from the MongoDB database in a list.Retrieves the unique client with the specified identifier from the MongoDB database, if it exists.findByName(String firstName, String lastName) Retrieves the unique client with the specified name and surname from the MongoDB database, if it exists.Inserts a new Client 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
-
ClientMongoRepository
public ClientMongoRepository(com.mongodb.client.MongoClient client, com.mongodb.client.ClientSession session, String databaseName) Constructs a repository layer for Client 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 clients from the MongoDB database in a list.- Specified by:
findAllin interfaceClientRepository- Returns:
- the
ListofClients found in the repository.
-
findById
Retrieves the unique client with the specified identifier from the MongoDB database, if it exists.- Specified by:
findByIdin interfaceClientRepository- Parameters:
id- the identifier of the client to find.- Returns:
- an
Optionalcontained theClientidentified byid, if it exists; anOptionalempty, otherwise.
-
findByName
Retrieves the unique client with the specified name and surname from the MongoDB database, if it exists.- Specified by:
findByNamein interfaceClientRepository- Parameters:
firstName- the name of the client to find.lastName- the surname of the client to find.- Returns:
- an
Optionalcontained theClientnamedfirstNameandlastName, if it exists; anOptionalempty, otherwise.
-
save
public Client save(Client client) throws IllegalArgumentException, UpdateFailureException, NotNullConstraintViolationException, UniquenessConstraintViolationException Inserts a new Client in the MongoDB database or saves changes of an existing one. Note: a Client without an identifier is considered to be entered, while with the identifier it will be updated.- Specified by:
savein interfaceClientRepository- Parameters:
client- the Client to save.- Returns:
- the
Clientsaved. - Throws:
IllegalArgumentException- ifclientis null.UpdateFailureException- if you try to save changes of a no longer existing client.NotNullConstraintViolationException- iffirstNameorlastNameofclientto save are null.UniquenessConstraintViolationException- ifidor[firstName, lastName]ofclientto save are already present.
-
delete
Removes the unique specified client from the MongoDB database, if it exists, otherwise it does nothing.- Specified by:
deletein interfaceClientRepository- Parameters:
client- the client to delete.- Throws:
IllegalArgumentException- ifclientis null.
-