Interface TransactionContext
-
@ProviderType public interface TransactionContextA transaction context defines the current transaction, and allows resources to register information and/or synchronizations
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleangetRollbackOnly()Is this transaction marked for rollback onlyjava.lang.ObjectgetScopedValue(java.lang.Object key)Get a value scoped to this transactionjava.lang.ObjectgetTransactionKey()Get the key associated with the current transactionTransactionStatusgetTransactionStatus()booleanisReadOnly()voidpostCompletion(java.util.function.Consumer<TransactionStatus> job)Register a callback that will be made after the scope completesvoidpreCompletion(java.lang.Runnable job)Register a callback that will be made before a scope completes.voidputScopedValue(java.lang.Object key, java.lang.Object value)Associate a value with this transactionvoidregisterLocalResource(LocalResource resource)Register a Local resource with the current transactionvoidregisterXAResource(javax.transaction.xa.XAResource resource, java.lang.String recoveryId)Register an XA resource with the current transactionvoidsetRollbackOnly()Mark this transaction for rollbackbooleansupportsLocal()booleansupportsXA()
-
-
-
Method Detail
-
getTransactionKey
java.lang.Object getTransactionKey()
Get the key associated with the current transaction- Returns:
- the transaction key, or null if there is no transaction
-
getScopedValue
java.lang.Object getScopedValue(java.lang.Object key)
Get a value scoped to this transaction- Parameters:
key-- Returns:
- The resource, or
null
-
putScopedValue
void putScopedValue(java.lang.Object key, java.lang.Object value)Associate a value with this transaction- Parameters:
key-value-
-
getRollbackOnly
boolean getRollbackOnly() throws java.lang.IllegalStateExceptionIs this transaction marked for rollback only- Returns:
- true if this transaction is rollback only
- Throws:
java.lang.IllegalStateException- if no transaction is active
-
setRollbackOnly
void setRollbackOnly() throws java.lang.IllegalStateExceptionMark this transaction for rollback- Throws:
java.lang.IllegalStateException- if no transaction is active
-
getTransactionStatus
TransactionStatus getTransactionStatus()
- Returns:
- The current transaction status
-
preCompletion
void preCompletion(java.lang.Runnable job) throws java.lang.IllegalStateExceptionRegister a callback that will be made before a scope completes.For transactional scopes the state of the scope will be either
TransactionStatus.ACTIVEorTransactionStatus.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:
java.lang.IllegalStateException- if the transaction has already passed beyond theTransactionStatus.MARKED_ROLLBACKstate
-
postCompletion
void postCompletion(java.util.function.Consumer<TransactionStatus> job) throws java.lang.IllegalStateException
Register a callback that will be made after the scope completesFor transactional scopes the state of the scope will be either
TransactionStatus.COMMITTEDorTransactionStatus.ROLLED_BACK.For no-transaction scopes the state of the scope will always be
TransactionStatus.NO_TRANSACTION.Post-completion callbacks should not throw
Exceptions and cannot affect the outcome of a piece of scoped work- Parameters:
job-- Throws:
java.lang.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
void registerXAResource(javax.transaction.xa.XAResource resource, java.lang.String recoveryId) throws java.lang.IllegalStateExceptionRegister an XA resource with the current transaction- Parameters:
resource-recoveryId- The resource id to be used for recovery, the id may benullif this resource is not recoverable.If an id is passed then a
RecoverableXAResourcewith the same id must be registered in the service registry for recovery to occur.If the underlying
TransactionControlservice does not support recovery then it must treat the resource as if it is not recoverable.- Throws:
java.lang.IllegalStateException- if no transaction is active, or the current transaction is not XA capable
-
registerLocalResource
void registerLocalResource(LocalResource resource) throws java.lang.IllegalStateException
Register a Local resource with the current transaction- Parameters:
resource-- Throws:
java.lang.IllegalStateException- if no transaction is active, or the current transaction does not support local resources.
-
-