protected Object handleInvocation(TransactionalInvocationContext invocation) throws Exception
{
assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
StatefulContext ctx = (StatefulContext) invocation.getEJBContext();
String ejbName = ctx.getManager().toString();
// Is the instance already associated with a transaction?
Transaction tx = ctx.getTransaction();
if (tx != null)
{
ctx.setTransaction(null);
// then resume that transaction.
tm.resume(tx);
}
try
{
return invocation.proceed();
}
finally
{
checkBadStateful(ejbName);
// Is the instance finished with the transaction?
Transaction newTx = tm.getTransaction();
if (newTx != null)
{
// remember the association
ctx.setTransaction(newTx);
// and suspend it.
tm.suspend();
}
else
{
// forget any previous associated transaction
ctx.setTransaction(null);
}
}
}