Methods Summary |
---|
public void | endTransaction(javax.transaction.TransactionManager tm, javax.transaction.Transaction tx)The endTransaction method ends a transaction and
translates any exceptions into
TransactionRolledBack[Local]Exception or SystemException.
try
{
if (tx != tm.getTransaction())
{
throw new IllegalStateException("Wrong tx on thread: expected " + tx + ", actual " + tm.getTransaction());
}
if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
{
tm.rollback();
}
else
{
// Commit tx
// This will happen if
// a) everything goes well
// b) app. exception was thrown
tm.commit();
}
}
catch (RollbackException e)
{
handleEndTransactionException(e);
}
catch (HeuristicMixedException e)
{
handleEndTransactionException(e);
}
catch (HeuristicRollbackException e)
{
handleEndTransactionException(e);
}
catch (SystemException e)
{
handleEndTransactionException(e);
}
|
public void | handleEndTransactionException(java.lang.Exception e)
throw new RuntimeException(e);
|
public void | handleExceptionInOurTx(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Throwable t, javax.transaction.Transaction tx)
// if this is an ApplicationException, just rethrow it
rethrowApplicationException(invocation, t);
setRollbackOnly(tx);
throw t;
|
public void | handleInCallerTx(org.jboss.aop.joinpoint.Invocation invocation, java.lang.Throwable t, javax.transaction.Transaction tx)
rethrowApplicationException(invocation, t);
setRollbackOnly(tx);
throw t;
|
public java.lang.Object | invokeInCallerTx(org.jboss.aop.joinpoint.Invocation invocation, javax.transaction.Transaction tx)
try
{
return invocation.invokeNext();
}
catch (Throwable t)
{
handleInCallerTx(invocation, t, tx);
}
throw new RuntimeException("UNREACHABLE");
|
public java.lang.Object | invokeInNoTx(org.jboss.aop.joinpoint.Invocation invocation)
return invocation.invokeNext();
|
public java.lang.Object | invokeInOurTx(org.jboss.aop.joinpoint.Invocation invocation, javax.transaction.TransactionManager tm)
for (int i = 0; i < MAX_RETRIES; i++)
{
tm.begin();
Transaction tx = tm.getTransaction();
try
{
try
{
return invocation.invokeNext();
}
catch (Throwable t)
{
handleExceptionInOurTx(invocation, t, tx);
}
finally
{
endTransaction(tm, tx);
}
}
catch (Exception ex)
{
ApplicationDeadlockException deadlock = ApplicationDeadlockException.isADE(ex);
if (deadlock != null)
{
if (!deadlock.retryable() ||
i + 1 >= MAX_RETRIES)
{
throw deadlock;
}
log.warn(deadlock.getMessage() + " retrying " + (i + 1));
Thread.sleep(random.nextInt(1 + i), random.nextInt(1000));
}
else
{
throw ex;
}
}
}
throw new RuntimeException("UNREACHABLE");
|
public void | rethrowApplicationException(org.jboss.aop.joinpoint.Invocation inv, java.lang.Throwable e)The rethrowApplicationException method determines
if the supplied Throwable is an application exception and
rethrows it if it is.
Object applicationExceptions = inv.getMetaData("transaction", "application-exceptions");
if (applicationExceptions == null) return;
Class[] applicationExceptionsList;
if (applicationExceptions instanceof String)
{
ArrayList tmpList = new ArrayList();
String aes = (String) applicationExceptions;
aes = aes.trim();
StringTokenizer tokenizer = new StringTokenizer(aes, ",");
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken().trim();
Class excClass = Thread.currentThread().getContextClassLoader().loadClass(token);
tmpList.add(excClass);
}
applicationExceptionsList = (Class[]) tmpList.toArray(new Class[tmpList.size()]);
}
else
{
applicationExceptionsList = (Class[]) applicationExceptions;
}
for (int i = 0; i < applicationExceptionsList.length; i++)
{
if (applicationExceptionsList[i].isInstance(e)) throw e;
}
|
public void | setRollbackOnly(javax.transaction.Transaction tx)The setRollbackOnly method calls setRollbackOnly()
on the invocation's transaction and logs any exceptions than may
occur.
try
{
tx.setRollbackOnly();
}
catch (SystemException ex)
{
log.error("SystemException while setting transaction " +
"for rollback only", ex);
}
catch (IllegalStateException ex)
{
log.error("IllegalStateException while setting transaction " +
"for rollback only", ex);
}
|
public void | throwMandatory(org.jboss.aop.joinpoint.Invocation invocation)
throw new RuntimeException("Transaction is mandatory.");
|