Top Description Methods
org.osgi.service.transaction.control

public Interface TransactionContext

Annotations
@ProviderType
Imports
java.util.function.Consumer, javax.transaction.xa.XAResource, org.osgi.annotation.versioning.ProviderType, org.osgi.service.transaction.control.recovery.RecoverableXAResource

A transaction context defines the current transaction, and allows resources to register information and/or synchronizations

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if this transaction is rollback only
getRollbackOnly
()

Is this transaction marked for rollback only

public Object

Returns:

The resource, or null
getScopedValue
(Object key)

Get a value scoped to this transaction

public Object

Returns:

the transaction key, or null if there is no transaction
getTransactionKey
()

Get the key associated with the current transaction

public TransactionStatus

Returns:

The current transaction status
getTransactionStatus
()

public boolean

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.
isReadOnly
()

public void
postCompletion(Consumer<TransactionStatus> job)

Register a callback that will be made after the scope completes

For transactional scopes the state of the scope will be either TransactionStatus#COMMITTED or TransactionStatus#ROLLED_BACK.

public void
preCompletion(Runnable
The action to perform before completing the scope
job
)

Register a callback that will be made before a scope completes.

public void
putScopedValue(Object key, Object value)

Associate a value with this transaction

public void
registerLocalResource(LocalResource resource)

Register a Local resource with the current transaction

public void
registerXAResource(javax.transaction.xa.XAResource resource, String
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.

recoveryId
)

Register an XA resource with the current transaction

public void
setRollbackOnly()

Mark this transaction for rollback

public boolean

Returns:

true if the current transaction supports Local resources
supportsLocal
()

public boolean

Returns:

true if the current transaction supports XA resources
supportsXA
()

Method Detail

getRollbackOnlyback to summary
public boolean getRollbackOnly() throws IllegalStateException

Is this transaction marked for rollback only

Returns:boolean

true if this transaction is rollback only

Exceptions
IllegalStateException:
if no transaction is active
getScopedValueback to summary
public Object getScopedValue(Object key)

Get a value scoped to this transaction

Returns:Object

The resource, or null

getTransactionKeyback to summary
public Object getTransactionKey()

Get the key associated with the current transaction

Returns:Object

the transaction key, or null if there is no transaction

getTransactionStatusback to summary
public TransactionStatus getTransactionStatus()
Returns:TransactionStatus

The current transaction status

isReadOnlyback to summary
public boolean isReadOnly()
Returns:boolean

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.

postCompletionback to summary
public void postCompletion(Consumer<TransactionStatus> job) throws IllegalStateException

Register a callback that will be made after the scope completes

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 Exceptions and cannot affect the outcome of a piece of scoped work

Exceptions
IllegalStateException:
if no transaction is active
preCompletionback to summary
public void preCompletion(Runnable job) throws IllegalStateException

Register a callback that will be made before a scope completes.

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.

Parameters
job:Runnable

The action to perform before completing the scope

Exceptions
IllegalStateException:
if the transaction has already passed beyond the TransactionStatus#MARKED_ROLLBACK state
putScopedValueback to summary
public void putScopedValue(Object key, Object value)

Associate a value with this transaction

registerLocalResourceback to summary
public void registerLocalResource(LocalResource resource) throws IllegalStateException

Register a Local resource with the current transaction

Exceptions
IllegalStateException:
if no transaction is active, or the current transaction does not support local resources.
registerXAResourceback to summary
public void registerXAResource(javax.transaction.xa.XAResource resource, String recoveryId) throws IllegalStateException

Register an XA resource with the current transaction

Parameters
recoveryId:String

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.

Exceptions
IllegalStateException:
if no transaction is active, or the current transaction is not XA capable
setRollbackOnlyback to summary
public void setRollbackOnly() throws IllegalStateException

Mark this transaction for rollback

Exceptions
IllegalStateException:
if no transaction is active
supportsLocalback to summary
public boolean supportsLocal()
Returns:boolean

true if the current transaction supports Local resources

supportsXAback to summary
public boolean supportsXA()
Returns:boolean

true if the current transaction supports XA resources