public class ReactiveMongoTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean
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.ReactiveMongoDatabaseUtils.getDatabase(ReactiveMongoDatabaseFactory, SessionSynchronization),
Serialized Form| Modifier and Type | Class and Description |
|---|---|
protected static class |
ReactiveMongoTransactionManager.ReactiveMongoTransactionObject
MongoDB specific transaction object, representing a
MongoResourceHolder. |
AbstractReactiveTransactionManager.SuspendedResourcesHolderlogger| Constructor and Description |
|---|
ReactiveMongoTransactionManager()
Create a new
ReactiveMongoTransactionManager for bean-style usage. |
ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory)
Create a new
ReactiveMongoTransactionManager obtaining sessions from the given
ReactiveMongoDatabaseFactory. |
ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory,
com.mongodb.TransactionOptions options)
Create a new
ReactiveMongoTransactionManager obtaining sessions from the given
ReactiveMongoDatabaseFactory applying the given options, if present, when
starting a new transaction. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected reactor.core.publisher.Mono<Void> |
doBegin(TransactionSynchronizationManager synchronizationManager,
Object transaction,
TransactionDefinition definition) |
protected reactor.core.publisher.Mono<Void> |
doCleanupAfterCompletion(TransactionSynchronizationManager synchronizationManager,
Object transaction) |
protected reactor.core.publisher.Mono<Void> |
doCommit(TransactionSynchronizationManager synchronizationManager,
GenericReactiveTransaction status) |
protected reactor.core.publisher.Mono<Void> |
doCommit(TransactionSynchronizationManager synchronizationManager,
ReactiveMongoTransactionManager.ReactiveMongoTransactionObject transactionObject)
Customization hook to perform an actual commit of the given transaction.
|
protected Object |
doGetTransaction(TransactionSynchronizationManager synchronizationManager) |
protected reactor.core.publisher.Mono<Void> |
doResume(TransactionSynchronizationManager synchronizationManager,
Object transaction,
Object suspendedResources) |
protected reactor.core.publisher.Mono<Void> |
doRollback(TransactionSynchronizationManager synchronizationManager,
GenericReactiveTransaction status) |
protected reactor.core.publisher.Mono<Void> |
doSetRollbackOnly(TransactionSynchronizationManager synchronizationManager,
GenericReactiveTransaction status) |
protected reactor.core.publisher.Mono<Object> |
doSuspend(TransactionSynchronizationManager synchronizationManager,
Object transaction) |
ReactiveMongoDatabaseFactory |
getDatabaseFactory()
Get the
ReactiveMongoDatabaseFactory that this instance manages transactions for. |
protected boolean |
isExistingTransaction(Object transaction) |
void |
setDatabaseFactory(ReactiveMongoDatabaseFactory databaseFactory)
Set the
ReactiveMongoDatabaseFactory that this instance should manage transactions for. |
void |
setOptions(com.mongodb.TransactionOptions options)
Set the
TransactionOptions to be applied when starting transactions. |
commit, getReactiveTransaction, prepareForCommit, registerAfterCompletionWithExistingTransaction, rollbackpublic ReactiveMongoTransactionManager()
ReactiveMongoTransactionManager for bean-style usage.
Note:The db factory has to
be setDatabaseFactory(ReactiveMongoDatabaseFactory) set} before using the instance. Use this constructor
to prepare a ReactiveMongoTransactionManager via a BeanFactory.
Optionally it is possible to set default transaction options defining
ReadConcern and WriteConcern.public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory)
ReactiveMongoTransactionManager obtaining sessions from the given
ReactiveMongoDatabaseFactory.databaseFactory - must not be null.public ReactiveMongoTransactionManager(ReactiveMongoDatabaseFactory databaseFactory, @Nullable com.mongodb.TransactionOptions options)
ReactiveMongoTransactionManager obtaining sessions from the given
ReactiveMongoDatabaseFactory applying the given options, if present, when
starting a new transaction.databaseFactory - must not be null.options - can be null.protected Object doGetTransaction(TransactionSynchronizationManager synchronizationManager) throws TransactionException
doGetTransaction in class AbstractReactiveTransactionManagerTransactionExceptionprotected boolean isExistingTransaction(Object transaction) throws TransactionException
isExistingTransaction in class AbstractReactiveTransactionManagerTransactionExceptionprotected reactor.core.publisher.Mono<Void> doBegin(TransactionSynchronizationManager synchronizationManager, Object transaction, TransactionDefinition definition) throws TransactionException
doBegin in class AbstractReactiveTransactionManagerTransactionExceptionprotected reactor.core.publisher.Mono<Object> doSuspend(TransactionSynchronizationManager synchronizationManager, Object transaction) throws TransactionException
doSuspend in class AbstractReactiveTransactionManagerTransactionExceptionprotected reactor.core.publisher.Mono<Void> doResume(TransactionSynchronizationManager synchronizationManager, @Nullable Object transaction, Object suspendedResources)
doResume in class AbstractReactiveTransactionManagerprotected final reactor.core.publisher.Mono<Void> doCommit(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException
doCommit in class AbstractReactiveTransactionManagerTransactionExceptionprotected reactor.core.publisher.Mono<Void> doCommit(TransactionSynchronizationManager synchronizationManager, ReactiveMongoTransactionManager.ReactiveMongoTransactionObject transactionObject)
MongoException holding
error labels. transient commit errors labels and retry the the
commit.synchronizationManager - reactive synchronization manager.transactionObject - never null.protected reactor.core.publisher.Mono<Void> doRollback(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status)
doRollback in class AbstractReactiveTransactionManagerprotected reactor.core.publisher.Mono<Void> doSetRollbackOnly(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException
doSetRollbackOnly in class AbstractReactiveTransactionManagerTransactionExceptionprotected reactor.core.publisher.Mono<Void> doCleanupAfterCompletion(TransactionSynchronizationManager synchronizationManager, Object transaction)
doCleanupAfterCompletion in class AbstractReactiveTransactionManagerpublic void setDatabaseFactory(ReactiveMongoDatabaseFactory databaseFactory)
ReactiveMongoDatabaseFactory that this instance should manage transactions for.databaseFactory - must not be null.public void setOptions(@Nullable com.mongodb.TransactionOptions options)
TransactionOptions to be applied when starting transactions.options - can be null.@Nullable public ReactiveMongoDatabaseFactory getDatabaseFactory()
ReactiveMongoDatabaseFactory that this instance manages transactions for.public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanCopyright © 2011–2020 Pivotal Software, Inc.. All rights reserved.