public class Current
extends java.lang.Object
implements javax.transaction.UserTransaction, javax.transaction.TransactionManager, javax.naming.Referenceable, java.io.Serializable
Current
is the common implementation for
UserTransaction
.
UserTransaction
is used by clients that want to demarcate
transactions themselves. It is referenceable through JNDI.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 and Description |
---|
Current()
Default constructor.
|
Current(TransactionFactory tmfact)
Constructor for an application server.
|
Modifier and Type | Method and Description |
---|---|
int |
actionXAResource(java.lang.String xaAction,
java.lang.String xatx) |
void |
begin()
Creates a new transaction and associate it with the current thread.
|
void |
begin(javax.transaction.xa.Xid passxid)
Creates a new inflow transaction and associates it with the current thread.
|
void |
begin(javax.transaction.xa.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 |
forgetTx(Xid xid)
Forget all about this transaction.
|
java.lang.String[] |
getAllRcTx()
Get all Transactions that may require recovery.
|
java.lang.String[] |
getAllTx()
Get all executing transactions.
|
java.lang.String[] |
getAllXaTx(java.lang.String stx)
Get all XAResources that may require recovery.
|
javax.transaction.xa.Xid[] |
getAllXid()
Get all Xid's associated with this transaction.
|
static boolean |
getAppServer()
Gets the Application Server enabled value
|
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)
|
javax.transaction.xa.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.
|
javax.naming.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.
|
javax.transaction.Transaction |
getTransaction()
Gets the transaction object that represents the transaction context of
the calling thread.
|
java.lang.Integer[] |
getTransactionCounters()
Returns all counters.
|
static javax.transaction.TransactionManager |
getTransactionManager() |
static TransactionRecovery |
getTransactionRecovery()
Returns the Transaction Recovery object
|
int |
getTransactionTimeout()
Gets the transaction timeout value
|
TransactionImpl |
getTxByXid(Xid xid)
Get the transaction referenced by Xid.
|
static javax.transaction.UserTransaction |
getUserTransaction() |
javax.resource.spi.XATerminator |
getXATerminator()
Gets the inflow transaction object that represents the transaction context of
the calling thread.
|
void |
resetAllTxTotalCounters()
Resets total number of transactions.
|
void |
resume(javax.transaction.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 |
setAppServer(boolean appserver)
Sets indicator if running with Application Server
|
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.
|
static void |
setTMFactory(TransactionFactory tmfact)
The TM factory is passed as an argument.
|
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.
|
javax.transaction.Transaction |
suspend()
Suspends the transaction currently associated with the calling thread
and return a
Transaction object that represents the
transaction context being suspended. |
static void |
transactionRecovery()
Initiate transaction recovery if enabled.
|
public Current()
public Current(TransactionFactory tmfact)
tmfact
- TM Factory to usepublic static javax.transaction.TransactionManager getTransactionManager()
public static javax.transaction.UserTransaction getUserTransaction()
public static void setTMFactory(TransactionFactory tmfact)
tmfact
- TM Factory to usepublic static void transactionRecovery()
public void begin() throws javax.transaction.NotSupportedException, javax.transaction.SystemException
begin
in interface javax.transaction.TransactionManager
begin
in interface javax.transaction.UserTransaction
javax.transaction.NotSupportedException
- Thrown if the thread is already
associated with a transaction. (nested transaction are not
supported)javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void begin(javax.transaction.xa.Xid passxid) throws javax.transaction.NotSupportedException, javax.transaction.SystemException
passxid
- Xid
of the inflow transaction.javax.transaction.NotSupportedException
- Thrown if the thread is already
associated with a transaction. (nested transaction are not
supported)javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void begin(javax.transaction.xa.Xid passxid, long timeout) throws javax.transaction.NotSupportedException, javax.transaction.SystemException
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.javax.transaction.NotSupportedException
- Thrown if the thread is already
associated with a transaction. (nested transaction are not
supported)javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic javax.resource.spi.XATerminator getXATerminator() throws javax.transaction.xa.XAException
javax.transaction.xa.XAException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void commit() throws javax.transaction.RollbackException, javax.transaction.HeuristicMixedException, javax.transaction.HeuristicRollbackException, java.lang.SecurityException, java.lang.IllegalStateException, javax.transaction.SystemException
commit
in interface javax.transaction.TransactionManager
commit
in interface javax.transaction.UserTransaction
javax.transaction.RollbackException
- Thrown to indicate that the transaction
has been rolled back rather than committed.javax.transaction.HeuristicMixedException
- Thrown to indicate that a heuristic
decision was made and that some relevant updates have been committed
while others have been rolled back.javax.transaction.HeuristicRollbackException
- Thrown to indicate that a
heuristic decision was made and that some relevant updates have been
rolled back.java.lang.SecurityException
- Thrown to indicate that the thread is not
allowed to commit the transaction.java.lang.IllegalStateException
- Thrown if the current thread is not
associated with a transaction.javax.transaction.SystemException
- Thrown if the transaction manager encounters
an unexpected error conditionpublic void rollback() throws java.lang.IllegalStateException, java.lang.SecurityException, javax.transaction.SystemException
rollback
in interface javax.transaction.TransactionManager
rollback
in interface javax.transaction.UserTransaction
java.lang.SecurityException
- Thrown to indicate that the thread is not
allowed to roll back the transaction.java.lang.IllegalStateException
- Thrown if the current thread is not
associated with a transaction.javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void setRollbackOnly() throws java.lang.IllegalStateException, javax.transaction.SystemException
setRollbackOnly
in interface javax.transaction.TransactionManager
setRollbackOnly
in interface javax.transaction.UserTransaction
java.lang.IllegalStateException
- Thrown if the current thread is not
associated with a transaction.javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic int getStatus() throws javax.transaction.SystemException
getStatus
in interface javax.transaction.TransactionManager
getStatus
in interface javax.transaction.UserTransaction
javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void setTransactionTimeout(int timeout) throws javax.transaction.SystemException
setTransactionTimeout
in interface javax.transaction.TransactionManager
setTransactionTimeout
in interface javax.transaction.UserTransaction
timeout
- value of the timeout (in seconds). If the value is zero,
the transaction service restores the default value.javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic int getTransactionTimeout()
public void setTransactionRecovery(boolean recovery) throws javax.transaction.SystemException
recovery
- value of the recovery (true or false). If the value is
false, recovery of transactions is disabled.javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic javax.transaction.Transaction getTransaction() throws javax.transaction.SystemException
getTransaction
in interface javax.transaction.TransactionManager
javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic void resume(javax.transaction.Transaction tobj) throws javax.transaction.InvalidTransactionException, java.lang.IllegalStateException, javax.transaction.SystemException
Warning: No XA start is done here. We suppose it is already
done after a getConnection()
.
getConnection()
connection.close()
resume
in interface javax.transaction.TransactionManager
tobj
- The Transaction
object that represents the
transaction to be resumed.javax.transaction.InvalidTransactionException
- Thrown if the parameter
transaction object contains an invalid transactionjava.lang.IllegalStateException
- Thrown if the thread is already
associated with another transaction.javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic javax.transaction.Transaction suspend() throws javax.transaction.SystemException
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()
.
getConnection()
connection.close()
suspend
in interface javax.transaction.TransactionManager
javax.transaction.SystemException
- Thrown if the transaction manager
encounters an unexpected error conditionpublic javax.naming.Reference getReference() throws javax.naming.NamingException
Reference
of this object.getReference
in interface javax.naming.Referenceable
Reference
of this object.javax.naming.NamingException
- If a naming exception was encountered while retrieving the reference.public static Current getCurrent()
null
if not
initialized in case of plain client.Current
object createdpublic static TransactionFactory getJTM()
public static TransactionRecovery getTransactionRecovery()
public void setDefaultTimeout(int timeout)
timeout
- timeout value (in seconds)public int getDefaultTimeout()
public static void setDefaultRecovery(boolean recovery)
recovery
- recovery value (true or false)public static boolean getDefaultRecovery()
public static void setAppServer(boolean appserver)
appserver
- application server enabled value (true or false)public static boolean getAppServer()
public void setPropagationContext(TransactionContext pctx, boolean isReply)
pctx
- TransactionContext. May be null to clean the thread (server side)isReply
- true
when receiving a reply (client side)public TransactionContext getPropagationContext(boolean hold)
hold
- true if hold the object while used. (Not used any longer)public void forgetTx(Xid xid)
TransactionImpl
must be destroyed to allow
the garbage collector to free memory allocated to this transaction.xid
- Xid
of the transactionpublic TransactionImpl getTxByXid(Xid xid)
xid
- Xid
of the transactionpublic javax.transaction.xa.Xid[] getPreparedHeuristicXid()
public javax.transaction.xa.Xid[] getAllXid()
public java.lang.String[] getAllTx()
public java.lang.String[] getAllRcTx()
public java.lang.String[] getAllXaTx(java.lang.String stx)
stx
- identifies the transactionpublic int actionXAResource(java.lang.String xaAction, java.lang.String xatx)
xaAction
- String "commit" "rollback" or "forget"xatx
- String representing the transactionpublic void clearThreadTx()
public int getTotalCurrentTransactions()
public int getTotalBegunTransactions()
public int getTotalRolledbackTransactions()
public int getTotalCommittedTransactions()
public void resetAllTxTotalCounters()
public int getTotalExpiredTransactions()
public java.lang.Integer[] getTransactionCounters()