Package io.micronaut.transaction.support
Class DefaultTransactionStatus<T>
- java.lang.Object
-
- io.micronaut.transaction.support.AbstractTransactionStatus<T>
-
- io.micronaut.transaction.support.DefaultTransactionStatus<T>
-
- Type Parameters:
T- The transaction object type
- All Implemented Interfaces:
SavepointManager,TransactionExecution,TransactionStatus<T>,java.io.Flushable
public class DefaultTransactionStatus<T> extends AbstractTransactionStatus<T>
Default implementation of theTransactionStatusinterface, used byAbstractSynchronousTransactionManager. Based on the concept of an underlying "transaction object".Holds all status information that
AbstractSynchronousTransactionManagerneeds internally, including a generic transaction object determined by the concrete transaction manager implementation.Supports delegating savepoint-related methods to a transaction object that implements the
SavepointManagerinterface.NOTE: This is not intended for use with other PlatformTransactionManager implementations, in particular not for mock transaction managers in testing environments.
TransactionStatusinterface instead.- Since:
- 19.01.2004
- Author:
- Juergen Hoeller
- See Also:
AbstractSynchronousTransactionManager,SavepointManager,getTransaction(),AbstractTransactionStatus.createSavepoint(),AbstractTransactionStatus.rollbackToSavepoint(java.lang.Object),AbstractTransactionStatus.releaseSavepoint(java.lang.Object)
-
-
Constructor Summary
Constructors Constructor Description DefaultTransactionStatus(java.lang.Object transaction, java.util.function.Supplier<T> connectionSupplier, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, java.lang.Object suspendedResources)Create a newDefaultTransactionStatusinstance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObjectinterface.TgetConnection()protected SavepointManagergetSavepointManager()This implementation exposes theSavepointManagerinterface of the underlying transaction object, if any.java.lang.ObjectgetSuspendedResources()Return the holder for resources that have been suspended for this transaction, if any.java.lang.ObjectgetTransaction()Return the underlying transaction object.booleanhasTransaction()Return whether there is an actual transaction active.booleanisDebug()Return whether the progress of this transaction is debugged.booleanisGlobalRollbackOnly()Determine the rollback-only flag via checking the transaction object, provided that the latter implements theSmartTransactionObjectinterface.booleanisNewSynchronization()Return if a new transaction synchronization has been opened for this transaction.booleanisNewTransaction()Return whether the present transaction is new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.booleanisReadOnly()Return if this transaction is defined as read-only transaction.booleanisTransactionSavepointManager()Return whether the underlying transaction implements theSavepointManagerinterface and therefore supports savepoints.-
Methods inherited from class io.micronaut.transaction.support.AbstractTransactionStatus
createAndHoldSavepoint, createSavepoint, getSavepoint, hasSavepoint, isCompleted, isLocalRollbackOnly, isRollbackOnly, releaseHeldSavepoint, releaseSavepoint, rollbackToHeldSavepoint, rollbackToSavepoint, setCompleted, setRollbackOnly, setSavepoint
-
-
-
-
Constructor Detail
-
DefaultTransactionStatus
public DefaultTransactionStatus(@Nullable java.lang.Object transaction, @NonNull java.util.function.Supplier<T> connectionSupplier, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, @Nullable java.lang.Object suspendedResources)Create a newDefaultTransactionStatusinstance.- Parameters:
transaction- underlying transaction object that can hold state for the internal transaction implementationconnectionSupplier- The connection suppliernewTransaction- if the transaction is new, otherwise participating in an existing transactionnewSynchronization- if a new transaction synchronization has been opened for the given transactionreadOnly- whether the transaction is marked as read-onlydebug- should debug logging be enabled for the handling of this transaction? Caching it in here can prevent repeated calls to ask the logging system whether debug logging should be enabled.suspendedResources- a holder for resources that have been suspended for this transaction, if any
-
-
Method Detail
-
getConnection
@NonNull public T getConnection()
- Returns:
- The associated connection.
-
getTransaction
public java.lang.Object getTransaction()
Return the underlying transaction object.- Returns:
- The underlying transaction
- Throws:
java.lang.IllegalStateException- if no transaction is active
-
hasTransaction
public boolean hasTransaction()
Return whether there is an actual transaction active.- Returns:
- Does the status have a transaction
-
isNewTransaction
public boolean isNewTransaction()
Description copied from interface:TransactionExecutionReturn whether the present transaction is new; otherwise participating in an existing transaction, or potentially not running in an actual transaction in the first place.- Returns:
- Whether the execution is a new transaction
-
isNewSynchronization
public boolean isNewSynchronization()
Return if a new transaction synchronization has been opened for this transaction.- Returns:
- Is it a new synchronization
-
isReadOnly
public boolean isReadOnly()
Return if this transaction is defined as read-only transaction.- Returns:
- Is the transaction read only
-
isDebug
public boolean isDebug()
Return whether the progress of this transaction is debugged. This is used byAbstractSynchronousTransactionManageras an optimization, to prevent repeated calls tologger.isDebugEnabled(). Not really intended for client code.- Returns:
- Is debug enabled
-
getSuspendedResources
@Nullable public java.lang.Object getSuspendedResources()
Return the holder for resources that have been suspended for this transaction, if any.- Returns:
- The suspended resources
-
isGlobalRollbackOnly
public boolean isGlobalRollbackOnly()
Determine the rollback-only flag via checking the transaction object, provided that the latter implements theSmartTransactionObjectinterface.Will return
trueif the global transaction itself has been marked rollback-only by the transaction coordinator, for example in case of a timeout.- Overrides:
isGlobalRollbackOnlyin classAbstractTransactionStatus<T>- Returns:
- Whether is global rollback
- See Also:
SmartTransactionObject.isRollbackOnly()
-
getSavepointManager
protected SavepointManager getSavepointManager()
This implementation exposes theSavepointManagerinterface of the underlying transaction object, if any.- Overrides:
getSavepointManagerin classAbstractTransactionStatus<T>- Returns:
- The save point manager
- Throws:
NestedTransactionNotSupportedException- if savepoints are not supported- See Also:
isTransactionSavepointManager()
-
isTransactionSavepointManager
public boolean isTransactionSavepointManager()
Return whether the underlying transaction implements theSavepointManagerinterface and therefore supports savepoints.- Returns:
- Is the transaction a save point manager
- See Also:
getTransaction(),getSavepointManager()
-
flush
public void flush()
Delegate the flushing to the transaction object, provided that the latter implements theSmartTransactionObjectinterface.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin interfaceTransactionStatus<T>- Overrides:
flushin classAbstractTransactionStatus<T>- See Also:
SmartTransactionObject.flush()
-
-