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
ConstructorDescriptionClientMongoRepository
(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 TypeMethodDescriptionvoid
Removes 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
- 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 clients from the MongoDB database in a list.- Specified by:
findAll
in interfaceClientRepository
- Returns:
- the
List
ofClient
s found in the repository.
-
findById
Retrieves the unique client with the specified identifier from the MongoDB database, if it exists.- Specified by:
findById
in interfaceClientRepository
- Parameters:
id
- the identifier of the client to find.- Returns:
- an
Optional
contained theClient
identified byid
, if it exists; anOptional
empty, otherwise.
-
findByName
Retrieves the unique client with the specified name and surname from the MongoDB database, if it exists.- Specified by:
findByName
in interfaceClientRepository
- Parameters:
firstName
- the name of the client to find.lastName
- the surname of the client to find.- Returns:
- an
Optional
contained theClient
namedfirstName
andlastName
, if it exists; anOptional
empty, 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:
save
in interfaceClientRepository
- Parameters:
client
- the Client to save.- Returns:
- the
Client
saved. - Throws:
IllegalArgumentException
- ifclient
is null.UpdateFailureException
- if you try to save changes of a no longer existing client.NotNullConstraintViolationException
- iffirstName
orlastName
ofclient
to save are null.UniquenessConstraintViolationException
- ifid
or[firstName, lastName]
ofclient
to save are already present.
-
delete
Removes the unique specified client from the MongoDB database, if it exists, otherwise it does nothing.- Specified by:
delete
in interfaceClientRepository
- Parameters:
client
- the client to delete.- Throws:
IllegalArgumentException
- ifclient
is null.
-