org.objectweb.jotm

Class Current

Implemented Interfaces:
Referenceable, Serializable, TransactionManager, UserTransaction, ResourceManagerEventListener, TransactionManager

public class Current
extends Object
implements UserTransaction, TransactionManager, Referenceable, Serializable

Current is the common implementation for both UserTransaction and TransactionManager.

This object is unique in a VM, i. e. each application server has ONE Current object and each client program should normally issue only ONE lookup on JNDI.

Current also implements Referenceable and Serializable because of JNDI.

Constructor Summary

Current()
Default constructor.
Current(TransactionFactory tmfact)
Constructor for an application server.

Method Summary

int
actionXAResource(String xaAction, String xatx)
void
associateThreadTx(Xid xid)
Associate Thread to this transaction.
void
begin()
Creates a new transaction and associate it with the current thread.
void
begin(Xid passxid)
Creates a new inflow transaction and associates it with the current thread.
void
begin(Xid passxid, long timeout)
Creates a new inflow transaction and associates it with the current thread.
void
clearThreadTx()
Clear transaction from this thread if not known.
void
commit()
Commits the transaction associated with the current thread.
void
connectionClosed(ResourceManagerEvent event)
void
connectionErrorOccured(ResourceManagerEvent event)
void
connectionOpened(ResourceManagerEvent event)
void
forgetTx(Xid xid)
Forget all about this transaction.
String[]
getAllRcTx()
Get all Transactions that may require recovery.
String[]
getAllTx()
Get all executing transactions.
String[]
getAllXaTx(String stx)
Get all XAResources that may require recovery.
Xid[]
getAllXid()
Get all Xid's associated with this transaction.
static Current
getCurrent()
Returns the unique instance of the class or null if not initialized in case of plain client.
static boolean
getDefaultRecovery()
Gets the default recovery value
int
getDefaultTimeout()
Gets the default timeout value
static TransactionFactory
getJTM()
Returns the TMFactory (in JTM)
Xid[]
getPreparedHeuristicXid()
Get the Xid's of all prepared transactions.
TransactionContext
getPropagationContext(boolean hold)
Get the transaction context associated with the current thread or null if the thread is not involved in a transaction.
Reference
getReference()
Retrieves the Reference of this object.
int
getStatus()
Returns the status of the transaction associated with the current thread.
int
getTotalBegunTransactions()
Returns the total number of begun transactions.
int
getTotalCommittedTransactions()
Returns the total number of committed transactions.
int
getTotalCurrentTransactions()
Returns the current number of transactions.
int
getTotalExpiredTransactions()
Returns the total number of rolled back transactions due to timeout.
int
getTotalRolledbackTransactions()
Returns the total number of rolled back transactions.
Transaction
getTransaction()
Gets the transaction object that represents the transaction context of the calling thread.
Integer[]
getTransactionCounters()
Returns all counters.
static TransactionManager
getTransactionManager()
Gets the TransactionManager instance.
static TransactionRecovery
getTransactionRecovery()
Returns the Transaction Recovery object
TransactionImpl
getTxByXid(Xid xid)
Get the transaction referenced by Xid.
XATerminator
getXATerminator()
Gets the inflow transaction object that represents the transaction context of the calling thread.
List
popThreadLocalRMEventList()
void
pushThreadLocalRMEventList(List eventList)
void
resetAllTxTotalCounters()
Resets total number of transactions.
void
resume(Transaction tobj)
Resumes the transaction context association of the calling thread with the transaction represented by the supplied Transaction object.
void
rollback()
Rolls back the transaction associated with the current thread.
static void
setDefaultRecovery(boolean recovery)
Sets the default recovery value
void
setDefaultTimeout(int timeout)
Sets the default timeout value
void
setPropagationContext(TransactionContext pctx, boolean isReply)
Associate to the current thread a transaction represented by its transaction context.
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
setTransactionRecovery(boolean recovery)
Modifies the value of the recovery value that is associated with the transactions started by the current thread with the begin method.
void
setTransactionTimeout(int timeout)
Modifies the value of the timeout value that is associated with the transactions started by the current thread with the begin method.
Transaction
suspend()
Suspends the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended.

Constructor Details

Current

public Current()
Default constructor. A client does not need the TMFactory.


Current

public Current(TransactionFactory tmfact)
Constructor for an application server. The TM factory is passed as an argument. Note that the TM factory can be either local or remote.

Parameters:
tmfact - TM Factory to use

Method Details

actionXAResource

public int actionXAResource(String xaAction,
                            String xatx)

Returns:
Returns all XAResources that require administrator recovery action.


associateThreadTx

public void associateThreadTx(Xid xid)
Associate Thread to this transaction. (used by iiop interceptor)


begin

public void begin()
            throws NotSupportedException,
                   SystemException
Creates a new transaction and associate it with the current thread.


begin

public void begin(Xid passxid)
            throws NotSupportedException,
                   SystemException
Creates a new inflow transaction and associates it with the current thread.

Parameters:
passxid - Xid of the inflow transaction.


begin

public void begin(Xid passxid,
                  long timeout)
            throws NotSupportedException,
                   SystemException
Creates a new inflow transaction and associates it with the current thread.

Parameters:
passxid - Xid of the inflow transaction.
timeout - value of the timeout (in seconds). If the value is less than or equal to zero, the value will be set to the default value.


clearThreadTx

public void clearThreadTx()
Clear transaction from this thread if not known. Useful when another thread completes the current thread's transaction


commit

public void commit()
            throws RollbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   SecurityException,
                   IllegalStateException,
                   SystemException
Commits the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.


connectionClosed

public void connectionClosed(ResourceManagerEvent event)
Specified by:
connectionClosed in interface ResourceManagerEventListener

See Also:
ResourceManagerEventListener.connectionClosed(ResourceManagerEvent)


connectionErrorOccured

public void connectionErrorOccured(ResourceManagerEvent event)
Specified by:
connectionErrorOccured in interface ResourceManagerEventListener

See Also:
ResourceManagerEventListener.connectionErrorOccured(ResourceManagerEvent)


connectionOpened

public void connectionOpened(ResourceManagerEvent event)
Specified by:
connectionOpened in interface ResourceManagerEventListener

See Also:
ResourceManagerEventListener.connectionOpened(ResourceManagerEvent)


forgetTx

public void forgetTx(Xid xid)
Forget all about this transaction. References to TransactionImpl must be destroyed to allow the garbage collector to free memory allocated to this transaction.

Parameters:
xid - Xid of the transaction


getAllRcTx

public String[] getAllRcTx()
Get all Transactions that may require recovery.

Returns:
array of all Transactions that may require recovery


getAllTx

public String[] getAllTx()
Get all executing transactions.

Returns:
array of all Transactions in execution


getAllXaTx

public String[] getAllXaTx(String stx)
Get all XAResources that may require recovery.

Returns:
array of all XAResources that may require recovery


getAllXid

public Xid[] getAllXid()
Get all Xid's associated with this transaction.

Returns:
array of all Xids


getCurrent

public static Current getCurrent()
Returns the unique instance of the class or null if not initialized in case of plain client.

Returns:
The Current object created


getDefaultRecovery

public static boolean getDefaultRecovery()
Gets the default recovery value

Returns:
default recovery value (true or false)


getDefaultTimeout

public int getDefaultTimeout()
Gets the default timeout value

Returns:
default timeout value (in seconds)


getJTM

public static TransactionFactory getJTM()
Returns the TMFactory (in JTM)

Returns:
TransactionFactory


getPreparedHeuristicXid

public Xid[] getPreparedHeuristicXid()
Get the Xid's of all prepared transactions.

Returns:
array of all Xids in the prepared state


getPropagationContext

public TransactionContext getPropagationContext(boolean hold)
Get the transaction context associated with the current thread or null if the thread is not involved in a transaction.


getReference

public Reference getReference()
            throws NamingException
Retrieves the Reference of this object.

Returns:
The non-null Reference of this object.


getStatus

public int getStatus()
            throws SystemException
Returns the status of the transaction associated with the current thread.

Returns:
transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value.


getTotalBegunTransactions

public int getTotalBegunTransactions()
Returns the total number of begun transactions.

Returns:
total number of begun transactions


getTotalCommittedTransactions

public int getTotalCommittedTransactions()
Returns the total number of committed transactions.

Returns:
total number of commited transactions


getTotalCurrentTransactions

public int getTotalCurrentTransactions()
Returns the current number of transactions.

Returns:
current number of transaction


getTotalExpiredTransactions

public int getTotalExpiredTransactions()
Returns the total number of rolled back transactions due to timeout.

Returns:
number of rolled back transactions due to timeout


getTotalRolledbackTransactions

public int getTotalRolledbackTransactions()
Returns the total number of rolled back transactions.

Returns:
total number of rolled back transactions


getTransaction

public Transaction getTransaction()
            throws SystemException
Gets the transaction object that represents the transaction context of the calling thread.

Returns:
the Transaction object representing the transaction associated with the calling thread. If the calling thread is not associated with a transaction, a null object reference is returned.


getTransactionCounters

public Integer[] getTransactionCounters()
Returns all counters.

Returns:
an array of all counters (current tx, begun tx, committed tx, rolled back tx, timeouted tx)


getTransactionManager

public static TransactionManager getTransactionManager()
Gets the TransactionManager instance.

Returns:
TransactionManager


getTransactionRecovery

public static TransactionRecovery getTransactionRecovery()
Returns the Transaction Recovery object

Returns:
TransactionRecovery


getTxByXid

public TransactionImpl getTxByXid(Xid xid)
Get the transaction referenced by Xid.

Parameters:
xid - Xid of the transaction


getXATerminator

public XATerminator getXATerminator()
            throws XAException
Gets the inflow transaction object that represents the transaction context of the calling thread.

Returns:
the XATerminator object representing the inflow transaction associated with the calling thread. If the calling thread is not associated with an inflow transaction, a null object reference is returned.


popThreadLocalRMEventList

public List popThreadLocalRMEventList()
Specified by:
popThreadLocalRMEventList in interface TransactionManager

See Also:
TransactionManager.popThreadLocalRMEventList()


pushThreadLocalRMEventList

public void pushThreadLocalRMEventList(List eventList)
Specified by:
pushThreadLocalRMEventList in interface TransactionManager

See Also:
org.objectweb.transaction.jta.TransactionManager.pushThreadLocalRMEventList(java.util.List)


resetAllTxTotalCounters

public void resetAllTxTotalCounters()
Resets total number of transactions.


resume

public void resume(Transaction tobj)
            throws InvalidTransactionException,
                   IllegalStateException,
                   SystemException
Resumes the transaction context association of the calling thread with the transaction represented by the supplied Transaction object. When this method returns, the calling thread is associated with the transaction context specified.

Warning: No XA start is done here. We suppose it is already done after a getConnection(). The supposed programming model is:

  1. getConnection()
  2. SQL code
  3. connection.close()

Parameters:
tobj - The Transaction object that represents the transaction to be resumed.


rollback

public void rollback()
            throws IllegalStateException,
                   SecurityException,
                   SystemException
Rolls back the transaction associated with the current thread. When this method completes, the thread becomes associated with no transaction.


setDefaultRecovery

public static void setDefaultRecovery(boolean recovery)
Sets the default recovery value

Parameters:
recovery - recovery value (true or false)


setDefaultTimeout

public void setDefaultTimeout(int timeout)
Sets the default timeout value

Parameters:
timeout - timeout value (in seconds)


setPropagationContext

public void setPropagationContext(TransactionContext pctx,
                                  boolean isReply)
Associate to the current thread a transaction represented by its transaction context. This is used internally by the implicit propagation of the transactional context:
  • in the skeleton, before calling the request (isReply = false)
  • in the stub, after receiving the reply (isReply = true)

Parameters:
pctx - TransactionContext
isReply - true before calling a request, false after receiving a reply


setRollbackOnly

public void setRollbackOnly()
            throws IllegalStateException,
                   SystemException
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.


setTransactionRecovery

public void setTransactionRecovery(boolean recovery)
            throws SystemException
Modifies the value of the recovery value that is associated with the transactions started by the current thread with the begin method. If an application has not called this method, the transaction service uses the default value of 'false' for recovery.

Parameters:
recovery - value of the recovery (true or faluse). If the value is false, recovery of transactions is disabled.


setTransactionTimeout

public void setTransactionTimeout(int timeout)
            throws SystemException
Modifies the value of the timeout value that is associated with the transactions started by the current thread with the begin method. If an application has not called this method, the transaction service uses some default value for the transaction timeout.

Parameters:
timeout - value of the timeout (in seconds). If the value is zero, the transaction service restores the default value.


suspend

public Transaction suspend()
            throws SystemException
Suspends the transaction currently associated with the calling thread and return a Transaction object that represents the transaction context being suspended. If the calling thread is not associated with a transaction, the method returns null. When this method returns, the calling thread is associated with no transaction.

Warning: No XA start is done here. We suppose it is already done after a getConnection(). The supposed programming model is:

  1. getConnection()
  2. SQL code
  3. connection.close()

Returns:
Transaction object representing the suspended transaction.