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
FieldsModifier and TypeFieldDescriptionstatic final com.mongodb.TransactionOptionsOptions used to configure transactions.Fields inherited from class io.github.marcopaglio.booking.transaction.manager.TransactionManager
clientRepositoryFactory, LOGGER, reservationRepositoryFactory, transactionHandlerFactory -
Constructor Summary
ConstructorsConstructorDescriptionTransactionMongoManager(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> RPrepares to execution of code that involves bothClientRepository's andReservationRepository's methods on MongoDB in a single transaction.<R> RdoInTransaction(ClientTransactionCode<R> code) Prepares to execution of code that involves theClientRepository's method(s) on MongoDB in a single transaction.<R> RPrepares 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 createClientSessioninstances.clientRepositoryFactory- the factory to createClientMongoRepositoryinstances.reservationRepositoryFactory- the factory to createReservationMongoRepositoryinstances.
-
-
Method Details
-
doInTransaction
Prepares to execution of code that involves theClientRepository's method(s) on MongoDB in a single transaction.- Specified by:
doInTransactionin 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:
doInTransactionin 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:
doInTransactionin 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.
-