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>, Flushable

public class DefaultTransactionStatus<T> extends AbstractTransactionStatus<T>
Default implementation of the TransactionStatus interface, used by AbstractSynchronousTransactionManager. Based on the concept of an underlying "transaction object".

Holds all status information that AbstractSynchronousTransactionManager needs 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 SavepointManager interface.

NOTE: This is not intended for use with other PlatformTransactionManager implementations, in particular not for mock transaction managers in testing environments. TransactionStatus interface instead.

Since:
19.01.2004
Author:
Juergen Hoeller
See Also:
  • Constructor Details

    • DefaultTransactionStatus

      public DefaultTransactionStatus(@Nullable Object transaction, @NonNull Supplier<T> connectionSupplier, boolean newTransaction, boolean newSynchronization, boolean readOnly, boolean debug, @Nullable Object suspendedResources)
      Create a new DefaultTransactionStatus instance.
      Parameters:
      transaction - underlying transaction object that can hold state for the internal transaction implementation
      connectionSupplier - The connection supplier
      newTransaction - if the transaction is new, otherwise participating in an existing transaction
      newSynchronization - if a new transaction synchronization has been opened for the given transaction
      readOnly - whether the transaction is marked as read-only
      debug - 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 Details

    • getConnection

      @NonNull public T getConnection()
      Returns:
      The associated connection.
    • getTransaction

      public Object getTransaction()
      Return the underlying transaction object.
      Returns:
      The underlying transaction
      Throws:
      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: TransactionExecution
      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.
      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 by AbstractSynchronousTransactionManager as an optimization, to prevent repeated calls to logger.isDebugEnabled(). Not really intended for client code.
      Returns:
      Is debug enabled
    • getSuspendedResources

      @Nullable public 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 the SmartTransactionObject interface.

      Will return true if the global transaction itself has been marked rollback-only by the transaction coordinator, for example in case of a timeout.

      Overrides:
      isGlobalRollbackOnly in class AbstractTransactionStatus<T>
      Returns:
      Whether is global rollback
      See Also:
    • getSavepointManager

      protected SavepointManager getSavepointManager()
      This implementation exposes the SavepointManager interface of the underlying transaction object, if any.
      Overrides:
      getSavepointManager in class AbstractTransactionStatus<T>
      Returns:
      The save point manager
      Throws:
      NestedTransactionNotSupportedException - if savepoints are not supported
      See Also:
    • isTransactionSavepointManager

      public boolean isTransactionSavepointManager()
      Return whether the underlying transaction implements the SavepointManager interface and therefore supports savepoints.
      Returns:
      Is the transaction a save point manager
      See Also:
    • flush

      public void flush()
      Delegate the flushing to the transaction object, provided that the latter implements the SmartTransactionObject interface.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in interface TransactionStatus<T>
      Overrides:
      flush in class AbstractTransactionStatus<T>
      See Also: