Skip to content

Commit

Permalink
[WFLY-10146] Simplify handleExceptionInOurTx
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Apr 5, 2018
1 parent ec575f1 commit 28edce8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
55 changes: 25 additions & 30 deletions ejb3/src/main/java/org/jboss/as/ejb3/tx/CMTTxInterceptor.java
Expand Up @@ -63,8 +63,6 @@
*/
public class CMTTxInterceptor implements Interceptor {

private static final int MAX_RETRIES = 5;

public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new CMTTxInterceptor());


Expand Down Expand Up @@ -119,29 +117,29 @@ protected void endTransaction(final Transaction tx) {
}
}

public void handleExceptionInOurTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) throws Exception {
public Exception handleExceptionInOurTx(InterceptorContext invocation, Throwable t, Transaction tx, final EJBComponent component) {
ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod());
if (ae != null) {
if (ae.isRollback()) setRollbackOnly(tx);
throw (Exception) t;
return (Exception) t;
}

// if it's neither EJBException nor RemoteException
if (!(t instanceof EJBException || t instanceof RemoteException)) {
// errors and unchecked are wrapped into EJBException
if (t instanceof Error) {
//t = new EJBException(formatException("Unexpected Error", t));
t = EjbLogger.ROOT_LOGGER.unexpectedError(t);
} else if (t instanceof RuntimeException) {
t = new EJBException((Exception) t);
} else {
// an application exception
throw (Exception) t;
}
try {
throw t;
} catch (EJBException | RemoteException e) {
setRollbackOnly(tx);
return e;
} catch (RuntimeException e) {
setRollbackOnly(tx);
return new EJBException(e);
} catch (Error e) {
setRollbackOnly(tx);
return EjbLogger.ROOT_LOGGER.unexpectedError(e);
} catch (Exception e) {
// an application exception
return e;
} catch (Throwable e) {
throw new EJBException(new UndeclaredThrowableException(e));
}

setRollbackOnly(tx);
throw (Exception) t;
}

public Object processInvocation(InterceptorContext invocation) throws Exception {
Expand Down Expand Up @@ -219,17 +217,14 @@ protected Object invokeInNoTx(InterceptorContext invocation, final EJBComponent
}

protected Object invokeInOurTx(InterceptorContext invocation, final EJBComponent component) throws Exception {
for (int i = 0; i < MAX_RETRIES; i++) {
Transaction tx = beginTransaction();
try {
return invocation.proceed();
} catch (Throwable t) {
handleExceptionInOurTx(invocation, t, tx, component);
} finally {
endTransaction(tx);
}
Transaction tx = beginTransaction();
try {
return invocation.proceed();
} catch (Throwable t) {
throw handleExceptionInOurTx(invocation, t, tx, component);
} finally {
endTransaction(tx);
}
throw new RuntimeException("UNREACHABLE");
}

protected Transaction beginTransaction() throws NotSupportedException, SystemException {
Expand Down
Expand Up @@ -47,9 +47,9 @@ public class TimerCMTTxInterceptor extends CMTTxInterceptor {
public static final InterceptorFactory FACTORY = new ImmediateInterceptorFactory(new TimerCMTTxInterceptor());

@Override
public void handleExceptionInOurTx(final InterceptorContext invocation, final Throwable t, final Transaction tx, final EJBComponent component) throws Exception {
public Exception handleExceptionInOurTx(final InterceptorContext invocation, final Throwable t, final Transaction tx, final EJBComponent component) {
EXCEPTION.set(t);
super.handleExceptionInOurTx(invocation, t, tx, component);
return super.handleExceptionInOurTx(invocation, t, tx, component);
}

@Override
Expand Down

0 comments on commit 28edce8

Please sign in to comment.