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
ConstructorsConstructorDescriptionTransactionMongoHandler(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 TypeMethodDescriptionvoidCloses the session, if still open.voidCommits changes of the active MongoDB transaction via the session.voidRolls back changes of the active MongoDB transaction via the session.voidStarts 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:
startTransactionin classTransactionHandler<com.mongodb.client.ClientSession>
-
commitTransaction
public void commitTransaction()Commits changes of the active MongoDB transaction via the session.- Specified by:
commitTransactionin 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:
rollbackTransactionin classTransactionHandler<com.mongodb.client.ClientSession>
-
closeHandler
public void closeHandler()Closes the session, if still open.- Specified by:
closeHandlerin classTransactionHandler<com.mongodb.client.ClientSession>
-