public class PseudoTransactionService extends java.lang.Object implements TransactionService, TransactionManager, TransactionSynchronizationRegistry
Modifier and Type | Class and Description |
---|---|
class |
PseudoTransactionService.MyTransaction |
Constructor and Description |
---|
PseudoTransactionService() |
Modifier and Type | Method and Description |
---|---|
void |
begin()
Create a new transaction and associate it with the current thread.
|
void |
commit()
Complete the transaction associated with the current thread.
|
java.lang.Object |
getResource(java.lang.Object key)
Get an object from the Map of resources being managed for
the transaction bound to the current thread at the time this
method is called.
|
boolean |
getRollbackOnly()
Get the rollbackOnly status of the transaction bound to the
current thread at the time this method is called.
|
int |
getStatus()
Obtain the status of the transaction associated with the current thread.
|
Transaction |
getTransaction()
Get the transaction object that represents the transaction
context of the calling thread.
|
java.lang.Object |
getTransactionKey()
Return an opaque object to represent the transaction bound to the
current thread at the time this method is called.
|
TransactionManager |
getTransactionManager() |
int |
getTransactionStatus()
Return the status of the transaction bound to the
current thread at the time this method is called.
|
TransactionSynchronizationRegistry |
getTransactionSynchronizationRegistry() |
void |
init(java.util.Properties props) |
void |
putResource(java.lang.Object key,
java.lang.Object value)
Add or replace an object in the Map of resources being managed for
the transaction bound to the current thread at the time this
method is called.
|
void |
registerInterposedSynchronization(Synchronization synchronization)
Register a Synchronization instance with special ordering
semantics.
|
void |
resume(Transaction tx)
Resume the transaction context association of the calling thread
with the transaction represented by the supplied Transaction object.
|
void |
rollback()
Roll back the transaction associated with the current thread.
|
void |
setRollbackOnly()
Modify the transaction associated with the current thread such that
the only possible outcome of the transaction is to roll back the
transaction.
|
void |
setTransactionTimeout(int seconds)
Modify the timeout value that is associated with transactions started
by the current thread with the begin method.
|
Transaction |
suspend()
Suspend the transaction currently associated with the calling
thread and return a Transaction object that represents the
transaction context being suspended.
|
public TransactionManager getTransactionManager()
getTransactionManager
in interface TransactionService
public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry()
public int getStatus()
TransactionManager
getStatus
in interface TransactionManager
public Transaction getTransaction()
TransactionManager
getTransaction
in interface TransactionManager
Transaction
object representing the
transaction associated with the calling thread.public boolean getRollbackOnly()
TransactionSynchronizationRegistry
getRollbackOnly
in interface TransactionSynchronizationRegistry
public void setRollbackOnly()
TransactionManager
setRollbackOnly
in interface TransactionManager
setRollbackOnly
in interface TransactionSynchronizationRegistry
public void begin() throws NotSupportedException
TransactionManager
begin
in interface TransactionManager
NotSupportedException
- Thrown if the thread is already
associated with a transaction and the Transaction Manager
implementation does not support nested transactions.public void commit() throws RollbackException
TransactionManager
commit
in interface TransactionManager
RollbackException
- Thrown to indicate that
the transaction has been rolled back rather than committed.public void rollback()
TransactionManager
rollback
in interface TransactionManager
public Transaction suspend()
TransactionManager
suspend
in interface TransactionManager
public void resume(Transaction tx) throws InvalidTransactionException
TransactionManager
resume
in interface TransactionManager
tx
- The Transaction
object that represents the
transaction to be resumed.InvalidTransactionException
- Thrown if the parameter
transaction object contains an invalid transaction.public java.lang.Object getTransactionKey()
TransactionSynchronizationRegistry
This object will return the same hashCode and compare equal to all other objects returned by calling this method from any component executing in the same transaction context in the same application server.
The toString method returns a String that might be usable by a human reader to usefully understand the transaction context. The toString result is otherwise not defined. Specifically, there is no forward or backward compatibility guarantee of the results of toString.
The object is not necessarily serializable, and has no defined behavior outside the virtual machine whence it was obtained.
getTransactionKey
in interface TransactionSynchronizationRegistry
public int getTransactionStatus()
TransactionSynchronizationRegistry
getTransactionStatus
in interface TransactionSynchronizationRegistry
public java.lang.Object getResource(java.lang.Object key)
TransactionSynchronizationRegistry
Map.get(Object)
for a Map that
supports non-null keys and null values. For example,
the returned value is null if there is no entry for the parameter
key or if the value associated with the key is actually null.getResource
in interface TransactionSynchronizationRegistry
key
- the key for the Map entry.public void putResource(java.lang.Object key, java.lang.Object value)
TransactionSynchronizationRegistry
Map.put(Object, Object)
for a Map that
supports non-null keys and null values. For example,
if there is already an value associated with the key, it is replaced
by the value parameter.putResource
in interface TransactionSynchronizationRegistry
key
- the key for the Map entry.value
- the value for the Map entry.public void registerInterposedSynchronization(Synchronization synchronization)
TransactionSynchronizationRegistry
The beforeCompletion callback will be invoked in the transaction context of the transaction bound to the current thread at the time this method is called. Allowable methods include access to resources, e.g. Connectors. No access is allowed to "user components" (e.g. timer services or bean methods), as these might change the state of data being managed by the caller, and might change the state of data that has already been flushed by another caller of registerInterposedSynchronization. The general context is the component context of the caller of registerInterposedSynchronization.
The afterCompletion callback will be invoked in an undefined context. No access is permitted to "user components" as defined above. Resources can be closed but no transactional work can be performed with them.
If this method is invoked without an active transaction context, an IllegalStateException is thrown.
If this method is invoked after the two-phase commit processing has started, an IllegalStateException is thrown.
registerInterposedSynchronization
in interface TransactionSynchronizationRegistry
synchronization
- the Synchronization instance.public void setTransactionTimeout(int seconds)
TransactionManager
If an application has not called this method, the transaction service uses some default value for the transaction timeout.
setTransactionTimeout
in interface TransactionManager
seconds
- The value of the timeout in seconds. If the value is zero,
the transaction service restores the default value. If the value
is negative a SystemException is thrown.