BMTInterceptorpublic class BMTInterceptor extends Object implements org.jboss.aop.advice.Interceptor
Fields Summary |
---|
private TransactionManager | tm | private boolean | isStateless | protected static Logger | log |
Methods Summary |
---|
private void | checkBadStateful(org.jboss.ejb3.Container container)
int status = Status.STATUS_NO_TRANSACTION;
try
{
status = tm.getStatus();
}
catch (SystemException ex)
{
log.error("Failed to get status", ex);
}
switch (status)
{
case Status.STATUS_COMMITTING :
case Status.STATUS_MARKED_ROLLBACK :
case Status.STATUS_PREPARING :
case Status.STATUS_ROLLING_BACK :
try
{
tm.rollback();
}
catch (Exception ex)
{
log.error("Failed to rollback", ex);
}
String msg = "BMT stateful bean '" + container.getEjbName()
+ "' did not complete user transaction properly status=" + TxUtils.getStatusAsString(status);
log.error(msg);
}
| private void | checkStatelessDone(org.jboss.ejb3.Container container, java.lang.Exception ex)
int status = Status.STATUS_NO_TRANSACTION;
try
{
status = tm.getStatus();
}
catch (SystemException sex)
{
log.error("Failed to get status", sex);
}
switch (status)
{
case Status.STATUS_ACTIVE :
case Status.STATUS_COMMITTING :
case Status.STATUS_MARKED_ROLLBACK :
case Status.STATUS_PREPARING :
case Status.STATUS_ROLLING_BACK :
try
{
tm.rollback();
}
catch (Exception sex)
{
log.error("Failed to rollback", sex);
}
// fall through...
case Status.STATUS_PREPARED :
String msg = "Application error: BMT stateless bean " + container.getEjbName()
+ " should complete transactions before" + " returning (EJB3 13.6.1)";
log.error(msg);
// the instance interceptor will discard the instance
if (ex != null)
{
if (ex instanceof EJBException)
throw (EJBException)ex;
else
throw new EJBException(msg, ex);
}
else throw new EJBException(msg);
}
| public java.lang.String | getName()
return BMTInterceptor.class.getName();
| public java.lang.Object | handleStateful(org.jboss.aop.joinpoint.Invocation invocation)
EJBContainerInvocation ejb = (EJBContainerInvocation)invocation;
Container container = (Container)invocation.getAdvisor();
StatefulBeanContext ctx = (StatefulBeanContext)ejb.getBeanContext();
Transaction tx = (Transaction)ctx.getMetaData().getMetaData("TX", "TX");
if (tx != null)
{
ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
tm.resume(tx);
}
try
{
return invocation.invokeNext();
}
finally
{
checkBadStateful(container);
Transaction newTx = tm.getTransaction();
if (newTx != null)
{
ctx.getMetaData().addMetaData("TX", "TX", newTx, PayloadKey.TRANSIENT);
tm.suspend();
}
else
{
ctx.getMetaData().addMetaData("TX", "TX", null, PayloadKey.TRANSIENT);
}
}
| public java.lang.Object | handleStateless(org.jboss.aop.joinpoint.Invocation invocation)
Container container = (Container)invocation.getAdvisor();
boolean exceptionThrown = false;
try
{
return invocation.invokeNext();
}
catch (Exception ex)
{
exceptionThrown = true;
checkStatelessDone(container, ex);
throw ex;
}
finally
{
try
{
if (!exceptionThrown) checkStatelessDone(container, null);
}
finally
{
tm.suspend();
}
}
| public java.lang.Object | invoke(org.jboss.aop.joinpoint.Invocation invocation)
Transaction oldTx = tm.getTransaction();
if (oldTx != null) tm.suspend();
try
{
if (isStateless) return handleStateless(invocation);
else return handleStateful(invocation);
}
finally
{
if (oldTx != null) tm.resume(oldTx);
}
|
|