Class TransactionContext

java.lang.Object
com.jsgalactic.axiom.jta.TransactionContext

public final class TransactionContext extends Object
The transaction view handed to handlers inside a Jta.transaction() boundary.

There is one instance per request and it is reached through Jta.context(com.jsgalactic.axiom.context.Context), using the request's existing Axiom context rather than a thread local. It is valid only on the request thread until the boundary returns. When boundaries are nested it reports the innermost active transaction; once all boundaries finish it reports their final outcome and is no longer active. Every method uses plain Java types, so neither this class nor its callers need the JTA API.

  • Method Details

    • active

      public boolean active()
      Reports whether a transaction is currently associated with this request.
      Returns:
      true only while the innermost boundary has an active transaction
    • status

      public TransactionStatus status()
      Returns the status of the innermost transaction, or the status left by the last completed one. A provider status with no equivalent here is TransactionStatus.UNKNOWN; this method never throws because the provider cannot be queried.
      Returns:
      plain transaction status
    • rollbackOnly

      public boolean rollbackOnly()
      Reports whether the innermost transaction has been marked for rollback, either by setRollbackOnly() or by the provider.
      Returns:
      true when the current transaction must be rolled back
    • setRollbackOnly

      public void setRollbackOnly()
      Marks the innermost transaction rollback-only. The boundary still completes normally, but rolls back instead of committing. This is a request-local operation: it cannot affect a suspended outer transaction or another request.
      Throws:
      IllegalStateException - if no transaction is active or the provider refuses the mark
    • timeout

      public Optional<Duration> timeout()
      Returns the timeout configured for the innermost boundary, if one was set.
      Returns:
      configured timeout, or empty for the provider's default
    • outcome

      public TransactionOutcome outcome()
      Returns the outcome of the transaction that last completed for this request. It is TransactionOutcome.PENDING while a boundary is running and stays available after completion so an error handler can decorate its response.
      Returns:
      plain completion outcome
    • from

      public static Optional<TransactionContext> from(Context context)
      Finds the transaction context attached to a request's context, if a boundary is running or has just finished for that request.
      Parameters:
      context - the request's Axiom context
      Returns:
      the request's transaction context, if any
      Throws:
      NullPointerException - if the context is null