Class AbstractInternalTransaction<C>
java.lang.Object
io.micronaut.transaction.impl.AbstractInternalTransaction<C>
- Type Parameters:
C- The connection type
- All Implemented Interfaces:
io.micronaut.core.propagation.PropagatedContextElement, InternalTransaction<C>, TransactionExecution, TransactionStatus<C>
- Direct Known Subclasses:
DefaultTransactionStatus
@Internal
public abstract class AbstractInternalTransaction<C>
extends Object
implements InternalTransaction<C>
The abstract internal transaction.
- Since:
- 4.0.0
- Author:
- Denis Stepanov
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidBinds the synchronizations registered byInternalTransaction.registerConnectionSynchronization(ConnectionSynchronization)to this transaction.voidbindConnectionSynchronizationsToTransaction(@NonNull Runnable release) Binds the synchronizations registered byInternalTransaction.registerConnectionSynchronization(ConnectionSynchronization)and the release of the connection to this transaction.voidFinal cleanup after the transaction completed, always invoked even if an earlier completion step failed.voidDiscards the connection synchronizations bound to this transaction without executing them.booleanReturn whether this transaction is completed, that is, whether it has already been committed or rolled back.booleanbooleanTemplate method for determining the global rollback-only flag of the underlying transaction, if any.booleanDetermine the rollback-only flag via checking this TransactionStatus.booleanReturn whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).voidregisterConnectionSynchronization(@NonNull ConnectionSynchronization synchronization) Registers a synchronization restoring the connection state changed by this transaction.voidregisterInvocationSynchronization(@NonNull TransactionSynchronization synchronization) The variation ofTransactionStatus.registerSynchronization(TransactionSynchronization)that is always executed on the current TX invocation.voidregisterResourceCommit(TransactionResourceCommit resourceCommit) Registers vendor-specific work for the resource commit boundary.voidregisterSynchronization(@NonNull TransactionSynchronization synchronization) Register a new transaction synchronization for the current state.protected voidSet global rollback only.voidSet the transaction rollback-only.voidvoidvoidvoidbooleanRuns a registered resource commit action.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface InternalTransaction
isNestedTransaction, resume, suspendMethods inherited from interface TransactionExecution
getTransactionDefinition, isNewTransactionMethods inherited from interface TransactionStatus
getConnection, getConnectionStatus, getTransaction, propagate, propagate, propagate
-
Field Details
-
synchronizations
-
-
Constructor Details
-
AbstractInternalTransaction
public AbstractInternalTransaction()
-
-
Method Details
-
setGlobalRollbackOnly
protected void setGlobalRollbackOnly()Set global rollback only. -
setRollbackOnly
public void setRollbackOnly()Description copied from interface:TransactionExecutionSet the transaction rollback-only. This instructs the transaction manager that the only possible outcome of the transaction may be a rollback, as alternative to throwing an exception which would in turn trigger a rollback.- Specified by:
setRollbackOnlyin interfaceTransactionExecution
-
isRollbackOnly
public boolean isRollbackOnly()Description copied from interface:TransactionExecutionReturn whether the transaction has been marked as rollback-only (either by the application or by the transaction infrastructure).- Specified by:
isRollbackOnlyin interfaceTransactionExecution- Returns:
- Whether the execution has been marked to rollback
-
isLocalRollbackOnly
public boolean isLocalRollbackOnly()Description copied from interface:InternalTransactionDetermine the rollback-only flag via checking this TransactionStatus.Will only return "true" if the application called
setRollbackOnlyon this TransactionStatus object.- Specified by:
isLocalRollbackOnlyin interfaceInternalTransaction<C>- Returns:
- Whether is local rollback
-
isGlobalRollbackOnly
public boolean isGlobalRollbackOnly()Description copied from interface:InternalTransactionTemplate method for determining the global rollback-only flag of the underlying transaction, if any.This implementation always returns
false.- Specified by:
isGlobalRollbackOnlyin interfaceInternalTransaction<C>- Returns:
- Whether is global rollback
-
isCompleted
public boolean isCompleted()Description copied from interface:TransactionExecutionReturn whether this transaction is completed, that is, whether it has already been committed or rolled back.- Specified by:
isCompletedin interfaceTransactionExecution- Returns:
- Whether the execution has completed
-
triggerBeforeCommit
public void triggerBeforeCommit()- Specified by:
triggerBeforeCommitin interfaceInternalTransaction<C>
-
triggerAfterCommit
public void triggerAfterCommit()- Specified by:
triggerAfterCommitin interfaceInternalTransaction<C>
-
triggerBeforeCompletion
public void triggerBeforeCompletion()- Specified by:
triggerBeforeCompletionin interfaceInternalTransaction<C>
-
registerResourceCommit
Description copied from interface:InternalTransactionRegisters vendor-specific work for the resource commit boundary.- Specified by:
registerResourceCommitin interfaceInternalTransaction<C>- Parameters:
resourceCommit- The resource commit callback
-
triggerResourceCommit
public boolean triggerResourceCommit()Description copied from interface:InternalTransactionRuns a registered resource commit action.- Specified by:
triggerResourceCommitin interfaceInternalTransaction<C>- Returns:
truewhen a resource commit action was registered and executed
-
triggerAfterCompletion
- Specified by:
triggerAfterCompletionin interfaceInternalTransaction<C>
-
cleanupAfterCompletion
public void cleanupAfterCompletion()Description copied from interface:InternalTransactionFinal cleanup after the transaction completed, always invoked even if an earlier completion step failed. Runs the connection synchronizations bound to this transaction, seeInternalTransaction.bindConnectionSynchronizationsToTransaction().- Specified by:
cleanupAfterCompletionin interfaceInternalTransaction<C>
-
registerConnectionSynchronization
Description copied from interface:InternalTransactionRegisters a synchronization restoring the connection state changed by this transaction. By default, the synchronization is registered on the connection status; if the transaction reuses a connection owned by an outer scope, it is executed atInternalTransaction.cleanupAfterCompletion().- Specified by:
registerConnectionSynchronizationin interfaceInternalTransaction<C>- Parameters:
synchronization- The synchronization
-
bindConnectionSynchronizationsToTransaction
public void bindConnectionSynchronizationsToTransaction()Description copied from interface:InternalTransactionBinds the synchronizations registered byInternalTransaction.registerConnectionSynchronization(ConnectionSynchronization)to this transaction. Used when the transaction is started on a connection owned by an outer scope.- Specified by:
bindConnectionSynchronizationsToTransactionin interfaceInternalTransaction<C>
-
bindConnectionSynchronizationsToTransaction
Description copied from interface:InternalTransactionBinds the synchronizations registered byInternalTransaction.registerConnectionSynchronization(ConnectionSynchronization)and the release of the connection to this transaction. Used when the transaction owns the connection. The connection is released atInternalTransaction.cleanupAfterCompletion(), after the connection state is restored.- Specified by:
bindConnectionSynchronizationsToTransactionin interfaceInternalTransaction<C>- Parameters:
release- The release of the connection
-
discardConnectionSynchronizations
public void discardConnectionSynchronizations()Description copied from interface:InternalTransactionDiscards the connection synchronizations bound to this transaction without executing them. Used when restoring the connection state is unsafe, for example, restoring the auto-commit of a partially started transaction that couldn't be rolled back would commit it.- Specified by:
discardConnectionSynchronizationsin interfaceInternalTransaction<C>
-
isConnectionOwnedByOuterScope
public boolean isConnectionOwnedByOuterScope()- Returns:
- true if the transaction was started on a connection owned by an outer scope,
see
bindConnectionSynchronizationsToTransaction() - Since:
- 5.3.0
-
registerSynchronization
Description copied from interface:TransactionStatusRegister a new transaction synchronization for the current state.Note that synchronizations can implement the
Orderedinterface. They will be executed in an order according to their order value (if any).- Specified by:
registerSynchronizationin interfaceTransactionStatus<C>- Parameters:
synchronization- the synchronization object to register
-
registerInvocationSynchronization
Description copied from interface:InternalTransactionThe variation ofTransactionStatus.registerSynchronization(TransactionSynchronization)that is always executed on the current TX invocation. The ordinaryTransactionStatus.registerSynchronization(TransactionSynchronization)will always bound the synchronization to the TX in progress.- Specified by:
registerInvocationSynchronizationin interfaceInternalTransaction<C>- Parameters:
synchronization- The synchronization
-