public class MongoTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean
PlatformTransactionManager implementation that manages
ClientSession based transactions for a single MongoDbFactory.
Binds a ClientSession from the specified MongoDbFactory to the thread.
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
MongoDatabaseUtils.getDatabase(MongoDbFactory) instead of a standard MongoDbFactory.getDb() call.
Spring classes such as MongoTemplate use this strategy implicitly.MongoDatabaseUtils.getDatabase(MongoDbFactory, SessionSynchronization),
Serialized FormAbstractPlatformTransactionManager.SuspendedResourcesHolderlogger, SYNCHRONIZATION_ALWAYS, SYNCHRONIZATION_NEVER, SYNCHRONIZATION_ON_ACTUAL_TRANSACTION| Constructor and Description |
|---|
MongoTransactionManager()
Create a new
MongoTransactionManager for bean-style usage. |
MongoTransactionManager(MongoDbFactory dbFactory)
Create a new
MongoTransactionManager obtaining sessions from the given MongoDbFactory. |
MongoTransactionManager(MongoDbFactory dbFactory,
com.mongodb.TransactionOptions options)
Create a new
MongoTransactionManager obtaining sessions from the given MongoDbFactory applying the
given options, if present, when starting a new transaction. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected void |
doBegin(Object transaction,
TransactionDefinition definition) |
protected void |
doCleanupAfterCompletion(Object transaction) |
protected void |
doCommit(DefaultTransactionStatus status) |
protected Object |
doGetTransaction() |
protected void |
doResume(Object transaction,
Object suspendedResources) |
protected void |
doRollback(DefaultTransactionStatus status) |
protected void |
doSetRollbackOnly(DefaultTransactionStatus status) |
protected Object |
doSuspend(Object transaction) |
MongoDbFactory |
getDbFactory()
Get the
MongoDbFactory that this instance manages transactions for. |
MongoDbFactory |
getResourceFactory() |
protected boolean |
isExistingTransaction(Object transaction) |
void |
setDbFactory(MongoDbFactory dbFactory)
Set the
MongoDbFactory that this instance should manage transactions for. |
void |
setOptions(com.mongodb.TransactionOptions options)
Set the
TransactionOptions to be applied when starting transactions. |
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransactionclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcommit, getTransaction, rollbackpublic MongoTransactionManager()
MongoTransactionManager for bean-style usage.
Note:The db factory has to be set
before using the instance. Use this constructor to prepare a MongoTransactionManager via a
BeanFactory.
Optionally it is possible to set default transaction options defining
ReadConcern and WriteConcern.public MongoTransactionManager(MongoDbFactory dbFactory)
MongoTransactionManager obtaining sessions from the given MongoDbFactory.dbFactory - must not be null.public MongoTransactionManager(MongoDbFactory dbFactory, @Nullable com.mongodb.TransactionOptions options)
MongoTransactionManager obtaining sessions from the given MongoDbFactory applying the
given options, if present, when starting a new transaction.dbFactory - must not be null.options - can be null.protected Object doGetTransaction() throws TransactionException
doGetTransaction in class AbstractPlatformTransactionManagerTransactionExceptionprotected boolean isExistingTransaction(Object transaction) throws TransactionException
isExistingTransaction in class AbstractPlatformTransactionManagerTransactionExceptionprotected void doBegin(Object transaction, TransactionDefinition definition) throws TransactionException
doBegin in class AbstractPlatformTransactionManagerTransactionExceptionprotected Object doSuspend(Object transaction) throws TransactionException
doSuspend in class AbstractPlatformTransactionManagerTransactionExceptionprotected void doResume(@Nullable Object transaction, Object suspendedResources)
doResume in class AbstractPlatformTransactionManagerprotected void doCommit(DefaultTransactionStatus status) throws TransactionException
doCommit in class AbstractPlatformTransactionManagerTransactionExceptionprotected void doRollback(DefaultTransactionStatus status) throws TransactionException
doRollback in class AbstractPlatformTransactionManagerTransactionExceptionprotected void doSetRollbackOnly(DefaultTransactionStatus status) throws TransactionException
doSetRollbackOnly in class AbstractPlatformTransactionManagerTransactionExceptionprotected void doCleanupAfterCompletion(Object transaction)
doCleanupAfterCompletion in class AbstractPlatformTransactionManagerpublic void setDbFactory(MongoDbFactory dbFactory)
MongoDbFactory that this instance should manage transactions for.dbFactory - 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 MongoDbFactory getDbFactory()
MongoDbFactory that this instance manages transactions for.public MongoDbFactory getResourceFactory()
getResourceFactory in interface ResourceTransactionManagerpublic void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanCopyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.