Interface TransactionContext
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Is this transaction marked for rollback onlygetScopedValue
(Object key) Get a value scoped to this transactionGet the key associated with the current transactionboolean
void
Register a callback that will be made after the scope completesvoid
preCompletion
(Runnable job) Register a callback that will be made before a scope completes.void
putScopedValue
(Object key, Object value) Associate a value with this transactionvoid
registerLocalResource
(LocalResource resource) Register a Local resource with the current transactionvoid
registerXAResource
(XAResource resource, String recoveryId) Register an XA resource with the current transactionvoid
Mark this transaction for rollbackboolean
boolean
-
Method Details
-
getTransactionKey
Object getTransactionKey()Get the key associated with the current transaction- Returns:
- the transaction key, or null if there is no transaction
-
getScopedValue
Get a value scoped to this transaction- Parameters:
key
-- Returns:
- The resource, or
null
-
putScopedValue
Associate a value with this transaction- Parameters:
key
-value
-
-
getRollbackOnly
Is this transaction marked for rollback only- Returns:
- true if this transaction is rollback only
- Throws:
IllegalStateException
- if no transaction is active
-
setRollbackOnly
Mark this transaction for rollback- Throws:
IllegalStateException
- if no transaction is active
-
getTransactionStatus
TransactionStatus getTransactionStatus()- Returns:
- The current transaction status
-
preCompletion
Register a callback that will be made before a scope completes.For transactional scopes the state of the scope will be either
TransactionStatus.ACTIVE
orTransactionStatus.MARKED_ROLLBACK
. Pre-completion callbacks may callsetRollbackOnly()
to prevent a commit from proceeding.For no-transaction scopes the state of the scope will always be
TransactionStatus.NO_TRANSACTION
.Exceptions thrown by pre-completion callbacks are treated as if they were thrown by the scoped work, including any configured commit or rollback behaviors for transactional scopes.
- Parameters:
job
- The action to perform before completing the scope- Throws:
IllegalStateException
- if the transaction has already passed beyond theTransactionStatus.MARKED_ROLLBACK
state
-
postCompletion
Register a callback that will be made after the scope completesFor transactional scopes the state of the scope will be either
TransactionStatus.COMMITTED
orTransactionStatus.ROLLED_BACK
.For no-transaction scopes the state of the scope will always be
TransactionStatus.NO_TRANSACTION
.Post-completion callbacks should not throw
Exception
s and cannot affect the outcome of a piece of scoped work- Parameters:
job
-- Throws:
IllegalStateException
- if no transaction is active
-
supportsXA
boolean supportsXA()- Returns:
- true if the current transaction supports XA resources
-
supportsLocal
boolean supportsLocal()- Returns:
- true if the current transaction supports Local resources
-
isReadOnly
boolean isReadOnly()- Returns:
- true if the TransactionContext supports read-only optimizations and the transaction was marked read only. In particular it is legal for this method to return false even if the transaction was marked read only by the initiating client.
-
registerXAResource
Register an XA resource with the current transaction- Parameters:
resource
-recoveryId
- The resource id to be used for recovery, the id may benull
if this resource is not recoverable.If an id is passed then a
RecoverableXAResource
with the same id must be registered in the service registry for recovery to occur.If the underlying
TransactionControl
service does not support recovery then it must treat the resource as if it is not recoverable.- Throws:
IllegalStateException
- if no transaction is active, or the current transaction is not XA capable
-
registerLocalResource
Register a Local resource with the current transaction- Parameters:
resource
-- Throws:
IllegalStateException
- if no transaction is active, or the current transaction does not support local resources.
-