Class AbstractTransactionOperations<T extends InternalTransaction<C>,C> 
- Type Parameters:
- T- The transaction type
- C- The connection type
- All Implemented Interfaces:
- SynchronousTransactionManager<C>,- TransactionManager,- TransactionOperations<C>
- Direct Known Subclasses:
- AbstractDefaultTransactionOperations
- Since:
- 4.0.0
- Author:
- Denis Stepanov
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final ConnectionOperations<C>protected final org.slf4j.Loggerprotected final @Nullable SynchronousConnectionManager<C>
- 
Constructor SummaryConstructorsConstructorDescriptionAbstractTransactionOperations(ConnectionOperations<C> connectionOperations, @Nullable SynchronousConnectionManager<C> synchronousConnectionManager) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidcommit(TransactionStatus<C> status) Commit the given transaction, with regard to its status.protected abstract TcreateExistingTransactionStatus(@NonNull ConnectionStatus<C> connectionStatus, @NonNull TransactionDefinition definition, T existingTransaction) Create transaction status with existing transaction.protected abstract TcreateNewTransactionStatus(@NonNull ConnectionStatus<C> connectionStatus, @NonNull TransactionDefinition definition) Create transaction status with new transaction.protected abstract TcreateNoTxTransactionStatus(@NonNull ConnectionStatus<C> connectionStatus, @NonNull TransactionDefinition definition) Create transaction status without open transaction.determineTimeout(TransactionDefinition definition) Determine the actual timeout to use for the given definition.protected abstract voidBegin a new transaction with semantics according to the given transaction definition.protected abstract voidPerform an actual commit of the given transaction.protected final <R> RdoExecute(@NonNull TransactionDefinition definition, @NonNull TransactionCallback<C, R> callback) Do execute in transaction.protected voidDo resume the transaction.protected abstract voiddoRollback(T tx) Perform an actual rollback of the given transaction.protected voidDo suspend the transaction.protected ConnectionDefinitiongetConnectionDefinition(TransactionDefinition transactionDefinition) Returns connection definition.@NonNull TransactionStatus<C>getTransaction(TransactionDefinition definition) Return a currently active transaction or create a new one, according to the specified propagation behavior.booleanCheck if the connection exists.protected <R> RDo execute nested transaction.voidrollback(TransactionStatus<C> status) Perform a rollback of the given transaction.protected <R> RDo suspend the transaction.Methods inherited from class io.micronaut.transaction.support.AbstractPropagatedStatusTransactionOperationsexecute, extendCurrentPropagatedContext, findTransactionStatusMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.transaction.TransactionOperationsexecute, executeRead, executeWrite, findTransactionStatus, getConnection
- 
Field Details- 
loggerprotected final org.slf4j.Logger logger
- 
connectionOperations
- 
synchronousConnectionManager
 
- 
- 
Constructor Details- 
AbstractTransactionOperationspublic AbstractTransactionOperations(ConnectionOperations<C> connectionOperations, @Nullable @Nullable SynchronousConnectionManager<C> synchronousConnectionManager) 
 
- 
- 
Method Details- 
getConnectionDefinitionReturns connection definition.- Parameters:
- transactionDefinition- The transaction definition
- Returns:
- connection definition
 
- 
createNoTxTransactionStatusprotected abstract T createNoTxTransactionStatus(@NonNull @NonNull ConnectionStatus<C> connectionStatus, @NonNull @NonNull TransactionDefinition definition) Create transaction status without open transaction.- Parameters:
- connectionStatus- The connection status
- definition- The transaction definition
- Returns:
- new transaction status
 
- 
createNewTransactionStatusprotected abstract T createNewTransactionStatus(@NonNull @NonNull ConnectionStatus<C> connectionStatus, @NonNull @NonNull TransactionDefinition definition) Create transaction status with new transaction.- Parameters:
- connectionStatus- The connection status
- definition- The transaction definition
- Returns:
- new transaction status
 
- 
createExistingTransactionStatusprotected abstract T createExistingTransactionStatus(@NonNull @NonNull ConnectionStatus<C> connectionStatus, @NonNull @NonNull TransactionDefinition definition, @NonNull T existingTransaction) Create transaction status with existing transaction.- Parameters:
- connectionStatus- The connection status
- definition- The transaction definition
- existingTransaction- The existing transaction
- Returns:
- new transaction status
 
- 
hasConnectionpublic boolean hasConnection()Description copied from interface:TransactionOperationsCheck if the connection exists.- Specified by:
- hasConnectionin interface- TransactionOperations<T extends InternalTransaction<C>>
- Returns:
- True if transaction exists
 
- 
doExecuteprotected final <R> R doExecute(@NonNull @NonNull TransactionDefinition definition, @NonNull @NonNull TransactionCallback<C, R> callback) Description copied from class:AbstractPropagatedStatusTransactionOperationsDo execute in transaction.- Specified by:
- doExecutein class- AbstractPropagatedStatusTransactionOperations<T extends InternalTransaction<C>,- C> 
- Type Parameters:
- R- The result type
- Parameters:
- definition- The transaction definition
- callback- The callback
- Returns:
- The result
 
- 
doBeginBegin a new transaction with semantics according to the given transaction definition. Does not have to care about applying the propagation behavior, as this has already been handled by this abstract manager.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. - Parameters:
- tx- The transaction
 
- 
doCommitPerform an actual commit of the given transaction.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. - Parameters:
- tx- The transaction
 
- 
doRollbackPerform an actual rollback of the given transaction.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. - Parameters:
- tx- The transaction
 
- 
determineTimeoutDetermine the actual timeout to use for the given definition. Will fall back to this manager's default timeout if the transaction definition doesn't specify a non-default value.- Parameters:
- definition- the transaction definition
- Returns:
- the optional timeout to use
- See Also:
 
- 
doSuspendDo suspend the transaction.- Parameters:
- transaction- The transaction
 
- 
doResumeDo resume the transaction.- Parameters:
- transaction- The transaction
 
- 
suspendDo suspend the transaction.- Type Parameters:
- R- The result type
- Parameters:
- transaction- The transaction
- callback- The callback
- Returns:
- The callback result
 
- 
nestedDo execute nested transaction.- Type Parameters:
- R- The result type
- Parameters:
- existingTransaction- The transaction
- callback- The callback
- Returns:
- The callback result
 
- 
getTransaction@NonNull public @NonNull TransactionStatus<C> 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 interface- SynchronousTransactionManager<T extends InternalTransaction<C>>
- Parameters:
- definition- the TransactionDefinition instance (can be- nullfor 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 errors
- IllegalTransactionStateException- 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:
 
- 
commitDescription 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 interface- SynchronousTransactionManager<T extends InternalTransaction<C>>
- Parameters:
- status- object returned by the- getTransactionmethod
- Throws:
- UnexpectedRollbackException- in case of an unexpected rollback that the transaction coordinator initiated
- HeuristicCompletionException- in case of a transaction failure caused by a heuristic decision on the side of the transaction coordinator
- TransactionSystemException- 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:
 
- 
rollbackDescription 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 interface- SynchronousTransactionManager<T extends InternalTransaction<C>>
- Parameters:
- status- object returned by the- getTransactionmethod
- 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
 
 
-