Class TransactionMongoManager
java.lang.Object
io.github.marcopaglio.booking.transaction.manager.TransactionManager
io.github.marcopaglio.booking.transaction.manager.mongo.TransactionMongoManager
An implementation of
TransactionManager
for managing code executed
on MongoDB within transactions.-
Field Summary
Modifier and TypeFieldDescriptionstatic final com.mongodb.TransactionOptions
Options used to configure transactions.Fields inherited from class io.github.marcopaglio.booking.transaction.manager.TransactionManager
clientRepositoryFactory, LOGGER, reservationRepositoryFactory, transactionHandlerFactory
-
Constructor Summary
ConstructorDescriptionTransactionMongoManager
(com.mongodb.client.MongoClient mongoClient, String databaseName, TransactionHandlerFactory transactionHandlerFactory, ClientRepositoryFactory clientRepositoryFactory, ReservationRepositoryFactory reservationRepositoryFactory) Constructs a manager for applying code that uses entity repositories using MongoDB transactions. -
Method Summary
Modifier and TypeMethodDescription<R> R
Prepares to execution of code that involves bothClientRepository
's andReservationRepository
's methods on MongoDB in a single transaction.<R> R
doInTransaction
(ClientTransactionCode<R> code) Prepares to execution of code that involves theClientRepository
's method(s) on MongoDB in a single transaction.<R> R
Prepares to execution of code that involves theReservationRepository
's method(s) on MongoDB in a single transaction.Methods inherited from class io.github.marcopaglio.booking.transaction.manager.TransactionManager
executeInTransaction, executeInTransaction, executeInTransaction, transactionFailureMsg
-
Field Details
-
TXN_OPTIONS
public static final com.mongodb.TransactionOptions TXN_OPTIONSOptions used to configure transactions. Note: casually consistency is applied when both read and write concerns has value 'majority'.
-
-
Constructor Details
-
TransactionMongoManager
public TransactionMongoManager(com.mongodb.client.MongoClient mongoClient, String databaseName, TransactionHandlerFactory transactionHandlerFactory, ClientRepositoryFactory clientRepositoryFactory, ReservationRepositoryFactory reservationRepositoryFactory) Constructs a manager for applying code that uses entity repositories using MongoDB transactions.- Parameters:
mongoClient
- the client connected to the MongoDB database.databaseName
- the name of the MongoDB database.transactionHandlerFactory
- the factory to createClientSession
instances.clientRepositoryFactory
- the factory to createClientMongoRepository
instances.reservationRepositoryFactory
- the factory to createReservationMongoRepository
instances.
-
-
Method Details
-
doInTransaction
Prepares to execution of code that involves theClientRepository
's method(s) on MongoDB in a single transaction.- Specified by:
doInTransaction
in classTransactionManager
- Type Parameters:
R
- the returned type of executed code.- Parameters:
code
- the code to execute.- Returns:
- something depending on execution code.
- Throws:
TransactionException
- if the execution or the commitment of the transaction fails.
-
doInTransaction
Prepares to execution of code that involves theReservationRepository
's method(s) on MongoDB in a single transaction.- Specified by:
doInTransaction
in classTransactionManager
- Type Parameters:
R
- the returned type of executed code.- Parameters:
code
- the code to execute.- Returns:
- something depending on execution code.
- Throws:
TransactionException
- if the execution or the commitment of the transaction fails.
-
doInTransaction
Prepares to execution of code that involves bothClientRepository
's andReservationRepository
's methods on MongoDB in a single transaction.- Specified by:
doInTransaction
in classTransactionManager
- Type Parameters:
R
- the returned type of executed code.- Parameters:
code
- the code to execute.- Returns:
- something depending on execution code.
- Throws:
TransactionException
- if the execution or the commitment of the transaction fails.
-