Our TransactionManager implementation.
| Method from org.jboss.tm.TxManager Detail: |
public void associateThread(Transaction transaction) {
if (transaction != null && !(transaction instanceof TransactionImpl))
throw new RuntimeException("Not a TransactionImpl, but a " +
transaction.getClass().getName());
// Associate with the thread
TransactionImpl transactionImpl = (TransactionImpl) transaction;
ThreadInfo ti = getThreadInfo();
ti.tx = transactionImpl;
transactionImpl.associateCurrentThread();
}
|
public void begin() throws SystemException, NotSupportedException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
if (current.isDone())
disassociateThread(ti);
else
throw new NotSupportedException
("Transaction already active, cannot nest transactions.");
}
long timeout = (ti.timeout == 0) ? timeOut : ti.timeout;
TransactionImpl tx = new TransactionImpl(timeout);
associateThread(ti, tx);
globalIdTx.put(tx.getGlobalId(), tx);
if (trace)
log.trace("began tx: " + tx);
}
Begin a new transaction.
The new transaction will be associated with the calling thread. |
public void commit() throws SystemException, SecurityException, RollbackException, IllegalStateException, HeuristicRollbackException, HeuristicMixedException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
current.commit();
disassociateThread(ti);
if (trace)
log.trace("commited tx: " + current);
}
else
throw new IllegalStateException("No transaction.");
}
Commit the transaction associated with the currently running thread. |
public boolean containsValue(TransactionLocal local,
Transaction tx) {
TransactionImpl tximpl = (TransactionImpl) tx;
return tximpl.containsTransactionLocal(local);
}
does TransactionImpl contain object? |
public Transaction disassociateThread() {
return disassociateThread(getThreadInfo());
}
The following 2 methods are here to provide association and
disassociation of the thread. |
public long getCommitCount() {
return commitCount;
}
A count of the transactions that have been committed |
public int getDefaultTransactionTimeout() {
return (int) (timeOut / 1000);
}
Get the default transaction timeout. |
public static TxManager getInstance() {
return singleton;
}
Get a reference to the singleton instance. |
public long getRollbackCount() {
return rollbackCount;
}
A count of the transactions that have been rolled back |
public int getStatus() throws SystemException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
if (current.isDone())
disassociateThread(ti);
else
return current.getStatus();
}
return Status.STATUS_NO_TRANSACTION;
}
Return the status of the transaction associated with the currently
running thread, or Status.STATUS_NO_TRANSACTION if no
active transaction is currently associated. |
public Transaction getTransaction() throws SystemException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null && current.isDone())
{
current = null;
disassociateThread(ti);
}
return current;
}
Return the transaction currently associated with the invoking thread,
or null if no active transaction is currently associated. |
public int getTransactionCount() {
return globalIdTx.size();
}
Return the number of active transactions |
public Object getTransactionPropagationContext() {
return getTransactionPropagationContext(getThreadInfo().tx);
}
Return a TPC for the current transaction. |
public Object getTransactionPropagationContext(Transaction tx) {
// If no transaction or unknown transaction class, return null.
if (tx == null)
return null;
if (!(tx instanceof TransactionImpl))
{
log.warn("Cannot export transaction propagation context: " + tx);
return null;
}
return ((TransactionImpl) tx).getGlobalId();
}
Return a TPC for the argument transaction. |
public Object getValue(TransactionLocal local,
Transaction tx) {
TransactionImpl tximpl = (TransactionImpl) tx;
return tximpl.getTransactionLocalValue(local);
}
get the transaction local value. Pull it from the TransactionImpl object |
public Transaction importTransactionPropagationContext(Object tpc) {
if (tpc instanceof GlobalId)
{
GlobalId id = (GlobalId) tpc;
return (Transaction) globalIdTx.get(id);
}
log.warn("Cannot import transaction propagation context: " + tpc);
return null;
}
Import a transaction propagation context into this TM.
The TPC is loosely typed, as we may (at a later time) want to
import TPCs that come from other transaction domains without
offloading the conversion to the client. |
void incCommitCount() {
++commitCount;
}
Increment the commit count |
void incRollbackCount() {
++rollbackCount;
}
Increment the rollback count |
void releaseTransactionImpl(TransactionImpl tx) {
globalIdTx.remove(tx.getGlobalId());
}
Release the given TransactionImpl. |
public void resume(Transaction transaction) throws SystemException, InvalidTransactionException, IllegalStateException {
if (transaction != null && !(transaction instanceof TransactionImpl))
throw new RuntimeException("Not a TransactionImpl, but a " +
transaction.getClass().getName());
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
if (current.isDone())
current = ti.tx = null;
else
throw new IllegalStateException("Already associated with a tx");
}
if (current != transaction)
{
associateThread(ti, (TransactionImpl)transaction);
}
if (trace)
log.trace("resumed tx: " + ti.tx);
}
Resume a transaction.
Note: This will not enlist any resources involved in this
transaction. According to JTA1.0.1 specification section 3.2.3,
that is the responsibility of the application server. |
public void rollback() throws SystemException, SecurityException, IllegalStateException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
if (!current.isDone())
{
current.rollback();
if (trace)
log.trace("rolled back tx: " + current);
return;
}
disassociateThread(ti);
}
throw new IllegalStateException("No transaction.");
}
Roll back the transaction associated with the currently running thread. |
public void setDefaultTransactionTimeout(int seconds) {
timeOut = 1000L * seconds;
if (trace)
log.trace("default tx timeout is now: " + seconds + "s");
}
Set the default transaction timeout for new transactions.
This default value is used if setTransactionTimeout()
was never called, or if it was called with a value of 0. |
public void setRollbackOnly() throws SystemException, IllegalStateException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
if (!current.isDone())
{
current.setRollbackOnly();
if (trace)
log.trace("tx marked for rollback only: " + current);
return;
}
ti.tx = null;
}
throw new IllegalStateException("No transaction.");
}
Mark the transaction associated with the currently running thread
so that the only possible outcome is a rollback. |
public void setTransactionTimeout(int seconds) throws SystemException {
getThreadInfo().timeout = 1000 * seconds;
if (trace)
log.trace("tx timeout is now: " + seconds + "s");
}
Set the transaction timeout for new transactions started by the
calling thread. |
public void storeValue(TransactionLocal local,
Transaction tx,
Object value) {
TransactionImpl tximpl = (TransactionImpl) tx;
tximpl.putTransactionLocalValue(local, value);
}
put the value in the TransactionImpl map |
public Transaction suspend() throws SystemException {
ThreadInfo ti = getThreadInfo();
TransactionImpl current = ti.tx;
if (current != null)
{
ti.tx = null;
if (trace)
log.trace("suspended tx: " + current);
if (current.isDone())
current = null;
}
return current;
}
Suspend the transaction currently associated with the current
thread, and return it.
Note: This will not delist any resources involved in this
transaction. According to JTA1.0.1 specification section 3.2.3,
that is the responsibility of the application server. |