Class ReactiveMongoTransactionManager

java.lang.Object
org.springframework.transaction.reactive.AbstractReactiveTransactionManager
org.springframework.data.mongodb.ReactiveMongoTransactionManager
All Implemented Interfaces:
Serializable, org.springframework.beans.factory.InitializingBean, org.springframework.transaction.ReactiveTransactionManager, org.springframework.transaction.TransactionManager

public class ReactiveMongoTransactionManager extends org.springframework.transaction.reactive.AbstractReactiveTransactionManager implements org.springframework.beans.factory.InitializingBean
A ReactiveTransactionManager implementation that manages ClientSession based transactions for a single ReactiveMongoDatabaseFactory.
Binds a ClientSession from the specified ReactiveMongoDatabaseFactory to the subscriber Context.
Readonly transactions operate on a ClientSession and enable causal consistency, and also start, commit or abort a transaction.
Application code is required to retrieve the MongoDatabase via ReactiveMongoDatabaseUtils.getDatabase(ReactiveMongoDatabaseFactory) instead of a standard ReactiveMongoDatabaseFactory.getMongoDatabase() call. Spring classes such as ReactiveMongoTemplate use this strategy implicitly.
By default failure of a commit operation raises a TransactionSystemException. You can override doCommit(TransactionSynchronizationManager, ReactiveMongoTransactionObject) to implement the Retry Commit Operation behavior as outlined in the MongoDB reference manual.
Since:
2.2
Author:
Christoph Strobl, Mark Paluch
See Also:
  • Constructor Details

  • Method Details

    • doGetTransaction

      protected Object doGetTransaction(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager) throws org.springframework.transaction.TransactionException
      Specified by:
      doGetTransaction in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • isExistingTransaction

      protected boolean isExistingTransaction(Object transaction) throws org.springframework.transaction.TransactionException
      Overrides:
      isExistingTransaction in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doBegin

      protected reactor.core.publisher.Mono<Void> doBegin(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, Object transaction, org.springframework.transaction.TransactionDefinition definition) throws org.springframework.transaction.TransactionException
      Specified by:
      doBegin in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doSuspend

      protected reactor.core.publisher.Mono<Object> doSuspend(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, Object transaction) throws org.springframework.transaction.TransactionException
      Overrides:
      doSuspend in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doResume

      protected reactor.core.publisher.Mono<Void> doResume(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, @Nullable Object transaction, Object suspendedResources)
      Overrides:
      doResume in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
    • doCommit

      protected final reactor.core.publisher.Mono<Void> doCommit(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, org.springframework.transaction.reactive.GenericReactiveTransaction status) throws org.springframework.transaction.TransactionException
      Specified by:
      doCommit in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doCommit

      protected reactor.core.publisher.Mono<Void> doCommit(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, ReactiveMongoTransactionManager.ReactiveMongoTransactionObject transactionObject)
      Customization hook to perform an actual commit of the given transaction.
      If a commit operation encounters an error, the MongoDB driver throws a MongoException holding error labels.
      By default those labels are ignored, nevertheless one might check for transient commit errors labels and retry the the commit.
      Parameters:
      synchronizationManager - reactive synchronization manager.
      transactionObject - never null.
    • doRollback

      protected reactor.core.publisher.Mono<Void> doRollback(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, org.springframework.transaction.reactive.GenericReactiveTransaction status)
      Specified by:
      doRollback in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
    • doSetRollbackOnly

      protected reactor.core.publisher.Mono<Void> doSetRollbackOnly(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, org.springframework.transaction.reactive.GenericReactiveTransaction status) throws org.springframework.transaction.TransactionException
      Overrides:
      doSetRollbackOnly in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
      Throws:
      org.springframework.transaction.TransactionException
    • doCleanupAfterCompletion

      protected reactor.core.publisher.Mono<Void> doCleanupAfterCompletion(org.springframework.transaction.reactive.TransactionSynchronizationManager synchronizationManager, Object transaction)
      Overrides:
      doCleanupAfterCompletion in class org.springframework.transaction.reactive.AbstractReactiveTransactionManager
    • setDatabaseFactory

      public void setDatabaseFactory(ReactiveMongoDatabaseFactory databaseFactory)
      Set the ReactiveMongoDatabaseFactory that this instance should manage transactions for.
      Parameters:
      databaseFactory - must not be null.
    • setOptions

      public void setOptions(@Nullable com.mongodb.TransactionOptions options)
      Set the TransactionOptions to be applied when starting transactions.
      Parameters:
      options - can be null.
    • getDatabaseFactory

      @Nullable public ReactiveMongoDatabaseFactory getDatabaseFactory()
      Get the ReactiveMongoDatabaseFactory that this instance manages transactions for.
      Returns:
      can be null.
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean