Class Jta

java.lang.Object
com.jsgalactic.axiom.jta.Jta
All Implemented Interfaces:
JtaTransactionLookup

public final class Jta extends Object implements JtaTransactionLookup
Opt-in JTA transaction boundaries around Axiom handlers.

 var jta = Jta.builder(applicationOwnedTransactionManager).timeout(Duration.ofSeconds(5)).build();
 app.use(jta.transaction());
 

The application supplies its own jakarta.transaction.TransactionManager as an Object; it is checked when the builder is created and adapted inside this module. No JTA type appears in an Axiom signature, and no transaction manager is bundled or published here. Nothing is bound until transaction() is registered as middleware.

Each boundary suspends any transaction already associated with the thread, begins a new one for the request, and commits when the chain returns a non-problem response or rolls back when it throws, answers a problem status or sets rollback-only. Completion always restores the previously associated transaction, including when nested boundaries run on the same request. Failures become fixed-code problem responses with no provider message or class name; their cause stays available to the framework's logs. Instances are immutable and thread-safe after construction.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Configures an immutable Jta; not thread-safe, build once at startup.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    active(Object context)
    Reports whether a transaction is currently associated with the request represented by context.
    builder(Object transactionManager)
    Starts a configuration around the application's transaction manager.
    context(Context context)
    Finds the request's transaction context, available to a handler while a boundary runs and to an error handler just after it ends.
    boolean
    Reports whether the request's active transaction has been marked rollback-only.
    status(Object context)
    Returns the request's transaction status as a plain name: ACTIVE, MARKED_ROLLBACK, COMMITTED, ROLLED_BACK, INACTIVE or UNKNOWN.
    Returns the middleware that binds one transaction around each request that runs through it.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • builder

      public static Jta.Builder builder(Object transactionManager)
      Starts a configuration around the application's transaction manager. A value that is not a JTA TransactionManager is rejected here, with an exception naming the expected type but not the supplied object.
      Parameters:
      transactionManager - application-owned transaction manager, supplied as an Object
      Returns:
      a builder
      Throws:
      IllegalArgumentException - if the value is not a JTA transaction manager
    • transaction

      public Middleware transaction()
      Returns the middleware that binds one transaction around each request that runs through it. The same thread-safe instance may be registered globally or on one route, and more than once to create nested, independent scopes.
      Returns:
      transaction-boundary middleware
    • context

      public static Optional<TransactionContext> context(Context context)
      Finds the request's transaction context, available to a handler while a boundary runs and to an error handler just after it ends. The lookup uses the request's context object, not a thread local, so a later request on the same thread cannot see this one's transaction.
      Parameters:
      context - the request's Axiom context
      Returns:
      the transaction context, if a boundary ran for this request
      Throws:
      NullPointerException - if the context is null
    • active

      public boolean active(Object context)
      Description copied from interface: JtaTransactionLookup
      Reports whether a transaction is currently associated with the request represented by context.
      Specified by:
      active in interface JtaTransactionLookup
      Parameters:
      context - the request's Axiom context, or any object to answer false
      Returns:
      true while a transaction is active for that request
    • status

      public String status(Object context)
      Description copied from interface: JtaTransactionLookup
      Returns the request's transaction status as a plain name: ACTIVE, MARKED_ROLLBACK, COMMITTED, ROLLED_BACK, INACTIVE or UNKNOWN.
      Specified by:
      status in interface JtaTransactionLookup
      Parameters:
      context - the request's Axiom context
      Returns:
      one of the six status names
    • rollbackOnly

      public boolean rollbackOnly(Object context)
      Description copied from interface: JtaTransactionLookup
      Reports whether the request's active transaction has been marked rollback-only.
      Specified by:
      rollbackOnly in interface JtaTransactionLookup
      Parameters:
      context - the request's Axiom context
      Returns:
      true when rollback-only was set by the handler or the provider