Class SynchronousFromReactiveTransactionManager<T>
- java.lang.Object
-
- io.micronaut.transaction.sync.SynchronousFromReactiveTransactionManager<T>
-
- Type Parameters:
T- The connection type
- All Implemented Interfaces:
SynchronousTransactionManager<T>,TransactionManager,TransactionOperations<T>
@Internal public final class SynchronousFromReactiveTransactionManager<T> extends java.lang.Object implements SynchronousTransactionManager<T>
Implementation of the synchronous transaction manager using a reactive transaction manager.- Since:
- 3.5.0
- Author:
- Denis Stepanov
-
-
Constructor Summary
Constructors Constructor Description SynchronousFromReactiveTransactionManager(ReactorReactiveTransactionOperations<T> reactiveTransactionOperations, java.util.concurrent.ExecutorService blockingExecutorService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit(TransactionStatus<T> status)Commit the given transaction, with regard to its status.<R> Rexecute(TransactionDefinition definition, TransactionCallback<T,R> callback)Execute a transaction within the context of the function.<R> RexecuteRead(TransactionCallback<T,R> callback)Execute a read-only transaction within the context of the function.<R> RexecuteWrite(TransactionCallback<T,R> callback)Execute a default transaction within the context of the function.TgetConnection()Obtains the connection for the current transaction.TransactionStatus<T>getTransaction(TransactionDefinition definition)Return a currently active transaction or create a new one, according to the specified propagation behavior.booleanhasConnection()Check if the connection exists.voidrollback(TransactionStatus<T> status)Perform a rollback of the given transaction.
-
-
-
Constructor Detail
-
SynchronousFromReactiveTransactionManager
public SynchronousFromReactiveTransactionManager(ReactorReactiveTransactionOperations<T> reactiveTransactionOperations, java.util.concurrent.ExecutorService blockingExecutorService)
-
-
Method Detail
-
getTransaction
public TransactionStatus<T> getTransaction(TransactionDefinition definition) throws TransactionException
Description copied from interface:SynchronousTransactionManagerReturn a currently active transaction or create a new one, according to the specified propagation behavior.Note that parameters like isolation level or timeout will only be applied to new transactions, and thus be ignored when participating in active ones.
Furthermore, not all transaction definition settings will be supported by every transaction manager: A proper transaction manager implementation should throw an exception when unsupported settings are encountered.
An exception to the above rule is the read-only flag, which should be ignored if no explicit read-only mode is supported. Essentially, the read-only flag is just a hint for potential optimization.
- Specified by:
getTransactionin interfaceSynchronousTransactionManager<T>- Parameters:
definition- the TransactionDefinition instance (can benullfor defaults), describing propagation behavior, isolation level, timeout etc.- Returns:
- transaction status object representing the new or current transaction
- Throws:
TransactionException- in case of lookup, creation, or system errorsIllegalTransactionStateException- if the given transaction definition cannot be executed (for example, if a currently active transaction is in conflict with the specified propagation behavior)- See Also:
TransactionDefinition.getPropagationBehavior(),TransactionDefinition.getIsolationLevel(),TransactionDefinition.getTimeout(),TransactionDefinition.isReadOnly()
-
commit
public void commit(TransactionStatus<T> status) throws TransactionException
Description copied from interface:SynchronousTransactionManagerCommit the given transaction, with regard to its status. If the transaction has been marked rollback-only programmatically, perform a rollback.If the transaction wasn't a new one, omit the commit for proper participation in the surrounding transaction. If a previous transaction has been suspended to be able to create a new one, resume the previous transaction after committing the new one.
Note that when the commit call completes, no matter if normally or throwing an exception, the transaction must be fully completed and cleaned up. No rollback call should be expected in such a case.
If this method throws an exception other than a TransactionException, then some before-commit error caused the commit attempt to fail. For example, an O/R Mapping tool might have tried to flush changes to the database right before commit, with the resulting DataAccessException causing the transaction to fail. The original exception will be propagated to the caller of this commit method in such a case.
- Specified by:
commitin interfaceSynchronousTransactionManager<T>- Parameters:
status- object returned by thegetTransactionmethod- Throws:
UnexpectedRollbackException- in case of an unexpected rollback that the transaction coordinator initiatedHeuristicCompletionException- in case of a transaction failure caused by a heuristic decision on the side of the transaction coordinatorTransactionSystemException- in case of commit or system errors (typically caused by fundamental resource failures)IllegalTransactionStateException- if the given transaction is already completed (that is, committed or rolled back)TransactionException- if something goes wrong during commit- See Also:
TransactionExecution.setRollbackOnly()
-
rollback
public void rollback(TransactionStatus<T> status) throws TransactionException
Description copied from interface:SynchronousTransactionManagerPerform a rollback of the given transaction.If the transaction wasn't a new one, just set it rollback-only for proper participation in the surrounding transaction. If a previous transaction has been suspended to be able to create a new one, resume the previous transaction after rolling back the new one.
Do not call rollback on a transaction if commit threw an exception. The transaction will already have been completed and cleaned up when commit returns, even in case of a commit exception. Consequently, a rollback call after commit failure will lead to an IllegalTransactionStateException.
- Specified by:
rollbackin interfaceSynchronousTransactionManager<T>- Parameters:
status- object returned by thegetTransactionmethod- Throws:
TransactionSystemException- in case of rollback or system errors (typically caused by fundamental resource failures)IllegalTransactionStateException- if the given transaction is already completed (that is, committed or rolled back)TransactionException- if something goes wrong during rollback
-
getConnection
public T getConnection()
Description copied from interface:TransactionOperationsObtains the connection for the current transaction.- Specified by:
getConnectionin interfaceTransactionOperations<T>- Returns:
- The connection
-
hasConnection
public boolean hasConnection()
Description copied from interface:TransactionOperationsCheck if the connection exists.- Specified by:
hasConnectionin interfaceTransactionOperations<T>- Returns:
- True if transaction exists
-
execute
public <R> R execute(TransactionDefinition definition, TransactionCallback<T,R> callback)
Description copied from interface:TransactionOperationsExecute a transaction within the context of the function.- Specified by:
executein interfaceTransactionOperations<T>- Type Parameters:
R- The result- Parameters:
definition- The transaction definitioncallback- The call back- Returns:
- The result
-
executeRead
public <R> R executeRead(TransactionCallback<T,R> callback)
Description copied from interface:TransactionOperationsExecute a read-only transaction within the context of the function.- Specified by:
executeReadin interfaceTransactionOperations<T>- Type Parameters:
R- The result- Parameters:
callback- The call back- Returns:
- The result
-
executeWrite
public <R> R executeWrite(TransactionCallback<T,R> callback)
Description copied from interface:TransactionOperationsExecute a default transaction within the context of the function.- Specified by:
executeWritein interfaceTransactionOperations<T>- Type Parameters:
R- The result- Parameters:
callback- The call back- Returns:
- The result
-
-