Class TransactionMongoHandler
java.lang.Object
io.github.marcopaglio.booking.transaction.handler.TransactionHandler<com.mongodb.client.ClientSession>
io.github.marcopaglio.booking.transaction.handler.mongo.TransactionMongoHandler
An implementation of
TransactionHandler
for using MongoDB transactions
via ClientSession
.-
Field Summary
Fields inherited from class io.github.marcopaglio.booking.transaction.handler.TransactionHandler
handler
-
Constructor Summary
ConstructorDescriptionTransactionMongoHandler
(com.mongodb.client.ClientSession session, com.mongodb.TransactionOptions txnOptions) Constructs a handler for MongoDB transactions using the session opened with MongoDB and some custom optional transaction options. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Closes the session, if still open.void
Commits changes of the active MongoDB transaction via the session.void
Rolls back changes of the active MongoDB transaction via the session.void
Starts a new MongoDB transaction via the session and using options if provided, if one isn't already active.Methods inherited from class io.github.marcopaglio.booking.transaction.handler.TransactionHandler
getHandler
-
Constructor Details
-
TransactionMongoHandler
public TransactionMongoHandler(com.mongodb.client.ClientSession session, com.mongodb.TransactionOptions txnOptions) Constructs a handler for MongoDB transactions using the session opened with MongoDB and some custom optional transaction options.- Parameters:
session
- the session opened with MongoDB.txnOptions
- the optional transaction options.
-
-
Method Details
-
startTransaction
public void startTransaction()Starts a new MongoDB transaction via the session and using options if provided, if one isn't already active.- Specified by:
startTransaction
in classTransactionHandler<com.mongodb.client.ClientSession>
-
commitTransaction
public void commitTransaction()Commits changes of the active MongoDB transaction via the session.- Specified by:
commitTransaction
in classTransactionHandler<com.mongodb.client.ClientSession>
-
rollbackTransaction
public void rollbackTransaction()Rolls back changes of the active MongoDB transaction via the session. Note: an already committed transaction cannot be abort.- Specified by:
rollbackTransaction
in classTransactionHandler<com.mongodb.client.ClientSession>
-
closeHandler
public void closeHandler()Closes the session, if still open.- Specified by:
closeHandler
in classTransactionHandler<com.mongodb.client.ClientSession>
-