Skip to content

Commit

Permalink
[WFLY-10146] Simplify invokeInCallerTx
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 5, 2018
1 parent dbff0ce commit ec575f1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
4 changes: 3 additions & 1 deletion ejb3/src/main/java/org/jboss/as/ejb3/logging/EjbLogger.java
Expand Up @@ -43,6 +43,7 @@
import javax.ejb.EJBAccessException;
import javax.ejb.EJBException;
import javax.ejb.EJBTransactionRequiredException;
import javax.ejb.EJBTransactionRolledbackException;
import javax.ejb.IllegalLoopbackException;
import javax.ejb.LockType;
import javax.ejb.NoMoreTimeoutsException;
Expand Down Expand Up @@ -2986,7 +2987,8 @@ public interface EjbLogger extends BasicLogger {
void failedToRefreshTimers(String timedObjectId);

@Message(id = 457, value = "Unexpected Error")
String convertUnexpectedError();
@Signature(String.class)
EJBTransactionRolledbackException unexpectedErrorRolledBack(@Cause Error error);

//@LogMessage(level = ERROR)
//@Message(id = 458, value = "Failure in caller transaction.")
Expand Down
56 changes: 21 additions & 35 deletions ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptor.java
Expand Up @@ -119,36 +119,6 @@ protected void endTransaction(final Transaction tx) {
}
}

protected void handleInCallerTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) throws Exception {
ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod());

if (ae != null) {
if (ae.isRollback()) setRollbackOnly(tx);
// an app exception can never be an Error
throw (Exception) t;
}

Exception toThrow;
if (!(t instanceof EJBTransactionRolledbackException)) {
if (t instanceof Error) {
toThrow = new EJBTransactionRolledbackException(EjbLogger.ROOT_LOGGER.convertUnexpectedError());
toThrow.initCause(t);
} else if (t instanceof NoSuchEJBException || t instanceof NoSuchEntityException) {
// If this is an NoSuchEJBException, pass through to the caller
toThrow = (Exception) t;
} else if (t instanceof RuntimeException) {
toThrow = new EJBTransactionRolledbackException(t.getMessage(), (Exception) t);
} else {// application exception
throw (Exception) t;
}
} else {
toThrow= (Exception) t;
}

setRollbackOnly(tx);
throw toThrow;
}

public void handleExceptionInOurTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) throws Exception {
ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod());
if (ae != null) {
Expand All @@ -161,9 +131,7 @@ public void handleExceptionInOurTx(InterceptorContext invocation, Throwable t, T
// errors and unchecked are wrapped into EJBException
if (t instanceof Error) {
//t = new EJBException(formatException("Unexpected Error", t));
Throwable cause = t;
t = EjbLogger.ROOT_LOGGER.unexpectedError();
t.initCause(cause);
t = EjbLogger.ROOT_LOGGER.unexpectedError(t);
} else if (t instanceof RuntimeException) {
t = new EJBException((Exception) t);
} else {
Expand Down Expand Up @@ -209,10 +177,28 @@ public Object processInvocation(InterceptorContext invocation) throws Exception
protected Object invokeInCallerTx(InterceptorContext invocation, Transaction tx, final EJBComponent component) throws Exception {
try {
return invocation.proceed();
} catch (Error e) {
setRollbackOnly(tx);
throw EjbLogger.ROOT_LOGGER.unexpectedErrorRolledBack(e);
} catch (Exception e) {
ApplicationExceptionDetails ae = component.getApplicationException(e.getClass(), invocation.getMethod());

if (ae != null) {
if (ae.isRollback()) setRollbackOnly(tx);
throw e;
}
try {
throw e;
} catch (EJBTransactionRolledbackException | NoSuchEJBException | NoSuchEntityException e2) {
setRollbackOnly(tx);
throw e2;
} catch (RuntimeException e2) {
setRollbackOnly(tx);
throw new EJBTransactionRolledbackException(e2.getMessage(), e2);
}
} catch (Throwable t) {
handleInCallerTx(invocation, t, tx, component);
throw new EJBException(new UndeclaredThrowableException(t));
}
throw new RuntimeException("UNREACHABLE");
}

protected Object invokeInNoTx(InterceptorContext invocation, final EJBComponent component) throws Exception {
Expand Down
Binary file not shown.

0 comments on commit ec575f1

Please sign in to comment.