@ProviderType public interface TransactionContext
Modifier and Type | Method and Description |
---|---|
boolean |
getRollbackOnly()
Is this transaction marked for rollback only
|
java.lang.Object |
getScopedValue(java.lang.Object key)
Get a value scoped to this transaction
|
java.lang.Object |
getTransactionKey()
Get the key associated with the current transaction
|
TransactionStatus |
getTransactionStatus() |
boolean |
isReadOnly() |
void |
postCompletion(java.util.function.Consumer<TransactionStatus> job)
Register a callback that will be made after the scope completes
|
void |
preCompletion(java.lang.Runnable job)
Register a callback that will be made before a scope completes.
|
void |
putScopedValue(java.lang.Object key,
java.lang.Object value)
Associate a value with this transaction
|
void |
registerLocalResource(LocalResource resource)
Register a Local resource with the current transaction
|
void |
registerXAResource(javax.transaction.xa.XAResource resource,
java.lang.String recoveryId)
Register an XA resource with the current transaction
|
void |
setRollbackOnly()
Mark this transaction for rollback
|
boolean |
supportsLocal() |
boolean |
supportsXA() |
java.lang.Object getTransactionKey()
java.lang.Object getScopedValue(java.lang.Object key)
key
- null
void putScopedValue(java.lang.Object key, java.lang.Object value)
key
- value
- boolean getRollbackOnly() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if no transaction is activevoid setRollbackOnly() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if no transaction is activeTransactionStatus getTransactionStatus()
void preCompletion(java.lang.Runnable job) throws java.lang.IllegalStateException
For transactional scopes the state of the scope will be either
TransactionStatus.ACTIVE
or
TransactionStatus.MARKED_ROLLBACK
. Pre-completion callbacks may
call setRollbackOnly()
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.
job
- The action to perform before completing the scopejava.lang.IllegalStateException
- if the transaction has already passed
beyond the TransactionStatus.MARKED_ROLLBACK
statevoid postCompletion(java.util.function.Consumer<TransactionStatus> job) throws java.lang.IllegalStateException
For transactional scopes the state of the scope will be either
TransactionStatus.COMMITTED
or
TransactionStatus.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
job
- java.lang.IllegalStateException
- if no transaction is activeboolean supportsXA()
boolean supportsLocal()
boolean isReadOnly()
void registerXAResource(javax.transaction.xa.XAResource resource, java.lang.String recoveryId) throws java.lang.IllegalStateException
resource
- recoveryId
- The resource id to be used for recovery, the id may be
null
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.
java.lang.IllegalStateException
- if no transaction is active, or the current
transaction is not XA capablevoid registerLocalResource(LocalResource resource) throws java.lang.IllegalStateException
resource
- java.lang.IllegalStateException
- if no transaction is active, or the current
transaction does not support local resources.Copyright © OSGi Alliance (2000, 2018). All Rights Reserved. Licensed under the OSGi Specification License, Version 2.0