@RequiresSyncMongo @EachBean(value=com.mongodb.client.MongoClient.class) @Internal public final class MongoSynchronousTransactionManager extends AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
AbstractSynchronousTransactionManager.SuspendedResourcesHolder
logger
Constructor and Description |
---|
MongoSynchronousTransactionManager(com.mongodb.client.MongoClient mongoClient)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
closeClientSession()
Close existing connection.
|
protected void |
doBegin(java.lang.Object transaction,
TransactionDefinition definition)
Begin a new transaction with semantics according to the given transaction
definition.
|
protected void |
doCleanupAfterCompletion(java.lang.Object transaction)
Cleanup resources after transaction completion.
|
protected void |
doCommit(DefaultTransactionStatus<com.mongodb.client.ClientSession> status)
Perform an actual commit of the given transaction.
|
protected java.lang.Object |
doGetTransaction()
Return a transaction object for the current transaction state.
|
protected void |
doResume(java.lang.Object transaction,
java.lang.Object suspendedResources)
Resume the resources of the current transaction.
|
protected void |
doRollback(DefaultTransactionStatus<com.mongodb.client.ClientSession> status)
Perform an actual rollback of the given transaction.
|
protected void |
doSetRollbackOnly(DefaultTransactionStatus status)
Set the given transaction rollback-only.
|
protected java.lang.Object |
doSuspend(java.lang.Object transaction)
Suspend the resources of the current transaction.
|
com.mongodb.client.ClientSession |
findClientSession()
Find existing connection.
|
com.mongodb.client.ClientSession |
getConnection()
Obtains the connection for the current transaction.
|
protected com.mongodb.client.ClientSession |
getConnection(java.lang.Object transaction)
The connection for the given transaction object.
|
protected java.lang.Object |
getTransactionStateKey()
Get the transaction state key that should be used to store the state.
|
boolean |
hasConnection()
Check if the connection exists.
|
protected boolean |
isExistingTransaction(java.lang.Object transaction)
Check if the given transaction object indicates an existing transaction
(that is, a transaction which has already started).
|
commit, doCleanupAfterCompletion, doDestroyState, doGetTransaction, execute, executeRead, executeWrite, findOrCreateState, getConnection, getState, getTransaction, invokeAfterCompletion, isExistingTransaction, newTransactionStatus, newTransactionStatus, prepareSynchronization, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, registerAfterCompletionWithExistingTransaction, resume, rollback, suspend, triggerBeforeCommit, triggerBeforeCompletion
commit, determineTimeout, execute, executeRead, executeWrite, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, prepareForCommit, prepareTransactionStatus, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransaction
public MongoSynchronousTransactionManager(com.mongodb.client.MongoClient mongoClient)
mongoClient
- The mongo clientprotected java.lang.Object getTransactionStateKey()
AbstractSynchronousTransactionManager
getTransactionStateKey
in class AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
@Nullable public com.mongodb.client.ClientSession findClientSession()
public void closeClientSession()
public com.mongodb.client.ClientSession getConnection()
TransactionOperations
public boolean hasConnection()
TransactionOperations
protected com.mongodb.client.ClientSession getConnection(java.lang.Object transaction)
AbstractSynchronousTransactionManager
getConnection
in class AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
transaction
- The transactionprotected java.lang.Object doGetTransaction() throws TransactionException
AbstractSynchronousTransactionManager
The returned object will usually be specific to the concrete transaction manager implementation, carrying corresponding transaction state in a modifiable fashion. This object will be passed into the other template methods (e.g. doBegin and doCommit), either directly or as part of a DefaultTransactionStatus instance.
The returned object should contain information about any existing
transaction, that is, a transaction that has already started before the
current getTransaction
call on the transaction manager.
Consequently, a doGetTransaction
implementation will usually
look for an existing transaction and store corresponding state in the
returned transaction object.
doGetTransaction
in class AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
CannotCreateTransactionException
- if transaction support is not availableTransactionException
- in case of lookup or system errorsAbstractSynchronousStateTransactionManager.doBegin(java.lang.Object, io.micronaut.transaction.TransactionDefinition)
,
AbstractSynchronousStateTransactionManager.doCommit(io.micronaut.transaction.support.DefaultTransactionStatus<T>)
,
AbstractSynchronousStateTransactionManager.doRollback(io.micronaut.transaction.support.DefaultTransactionStatus<T>)
,
DefaultTransactionStatus.getTransaction()
protected boolean isExistingTransaction(java.lang.Object transaction) throws TransactionException
AbstractSynchronousTransactionManager
The result will be evaluated according to the specified propagation behavior for the new transaction. An existing transaction might get suspended (in case of PROPAGATION_REQUIRES_NEW), or the new transaction might participate in the existing one (in case of PROPAGATION_REQUIRED).
The default implementation returns false
, assuming that
participating in existing transactions is generally not supported.
Subclasses are of course encouraged to provide such support.
isExistingTransaction
in class AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
transaction
- transaction object returned by doGetTransactionTransactionException
- in case of system errorsAbstractSynchronousTransactionManager.doGetTransaction(io.micronaut.transaction.support.SynchronousTransactionState)
protected void doBegin(java.lang.Object transaction, TransactionDefinition definition) throws TransactionException
AbstractSynchronousStateTransactionManager
This method gets called when the transaction manager has decided to actually start a new transaction. Either there wasn't any transaction before, or the previous transaction has been suspended.
A special scenario is a nested transaction without savepoint: If
useSavepointForNestedTransaction()
returns "false", this method
will be called to start a nested transaction when necessary. In such a context,
there will be an active transaction: The implementation of this method has
to detect this and start an appropriate nested transaction.
doBegin
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
transaction
- transaction object returned by doGetTransaction
definition
- a TransactionDefinition instance, describing propagation
behavior, isolation level, read-only flag, timeout, and transaction nameTransactionException
- in case of creation or system errorsNestedTransactionNotSupportedException
- if the underlying transaction does not support nestingprotected void doCommit(DefaultTransactionStatus<com.mongodb.client.ClientSession> status) throws TransactionException
AbstractSynchronousStateTransactionManager
An implementation does not need to check the "new transaction" flag or the rollback-only flag; this will already have been handled before. Usually, a straight commit will be performed on the transaction object contained in the passed-in status.
doCommit
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
status
- the status representation of the transactionTransactionException
- in case of commit or system errorsDefaultTransactionStatus.getTransaction()
protected void doRollback(DefaultTransactionStatus<com.mongodb.client.ClientSession> status) throws TransactionException
AbstractSynchronousStateTransactionManager
An implementation does not need to check the "new transaction" flag; this will already have been handled before. Usually, a straight rollback will be performed on the transaction object contained in the passed-in status.
doRollback
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
status
- the status representation of the transactionTransactionException
- in case of system errorsDefaultTransactionStatus.getTransaction()
protected java.lang.Object doSuspend(java.lang.Object transaction)
AbstractSynchronousStateTransactionManager
The default implementation throws a TransactionSuspensionNotSupportedException, assuming that transaction suspension is generally not supported.
doSuspend
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
transaction
- transaction object returned by doGetTransaction
AbstractSynchronousStateTransactionManager.doResume(java.lang.Object, java.lang.Object)
protected void doResume(@Nullable java.lang.Object transaction, java.lang.Object suspendedResources)
AbstractSynchronousStateTransactionManager
The default implementation throws a TransactionSuspensionNotSupportedException, assuming that transaction suspension is generally not supported.
doResume
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
transaction
- transaction object returned by doGetTransaction
suspendedResources
- the object that holds suspended resources,
as returned by doSuspendAbstractSynchronousStateTransactionManager.doSuspend(java.lang.Object)
protected void doSetRollbackOnly(DefaultTransactionStatus status)
AbstractSynchronousStateTransactionManager
The default implementation throws an IllegalTransactionStateException, assuming that participating in existing transactions is generally not supported. Subclasses are of course encouraged to provide such support.
doSetRollbackOnly
in class AbstractSynchronousStateTransactionManager<com.mongodb.client.ClientSession>
status
- the status representation of the transactionprotected void doCleanupAfterCompletion(java.lang.Object transaction)
AbstractSynchronousTransactionManager
Called after doCommit
and doRollback
execution,
on any outcome. The default implementation does nothing.
Should not throw any exceptions but just issue warnings on errors.
doCleanupAfterCompletion
in class AbstractSynchronousTransactionManager<com.mongodb.client.ClientSession>
transaction
- transaction object returned by doGetTransaction