Class TransactionMongoHandler

java.lang.Object
io.github.marcopaglio.booking.transaction.handler.TransactionHandler<com.mongodb.client.ClientSession>
io.github.marcopaglio.booking.transaction.handler.mongo.TransactionMongoHandler

public class TransactionMongoHandler extends TransactionHandler<com.mongodb.client.ClientSession>
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

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 class TransactionHandler<com.mongodb.client.ClientSession>
    • commitTransaction

      public void commitTransaction()
      Commits changes of the active MongoDB transaction via the session.
      Specified by:
      commitTransaction in class TransactionHandler<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 class TransactionHandler<com.mongodb.client.ClientSession>
    • closeHandler

      public void closeHandler()
      Closes the session, if still open.
      Specified by:
      closeHandler in class TransactionHandler<com.mongodb.client.ClientSession>