Package com.jsgalactic.axiom.jta
Class TransactionContext
java.lang.Object
com.jsgalactic.axiom.jta.TransactionContext
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 Summary
Modifier and TypeMethodDescriptionbooleanactive()Reports whether a transaction is currently associated with this request.static Optional<TransactionContext> Finds the transaction context attached to a request's context, if a boundary is running or has just finished for that request.outcome()Returns the outcome of the transaction that last completed for this request.booleanReports whether the innermost transaction has been marked for rollback, either bysetRollbackOnly()or by the provider.voidMarks the innermost transaction rollback-only.status()Returns the status of the innermost transaction, or the status left by the last completed one.timeout()Returns the timeout configured for the innermost boundary, if one was set.
-
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
Returns the status of the innermost transaction, or the status left by the last completed one. A provider status with no equivalent here isTransactionStatus.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 bysetRollbackOnly()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
Returns the timeout configured for the innermost boundary, if one was set.- Returns:
- configured timeout, or empty for the provider's default
-
outcome
Returns the outcome of the transaction that last completed for this request. It isTransactionOutcome.PENDINGwhile a boundary is running and stays available after completion so an error handler can decorate its response.- Returns:
- plain completion outcome
-
from
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
-