fixed tx join interceptor handling

This commit is contained in:
2019-04-27 14:07:31 +01:00
parent 70829f9204
commit 4f3c3d4673
3 changed files with 21 additions and 46 deletions

View File

@ -15,10 +15,13 @@
*/
package de.muehlencord.shared.account.business;
import javax.ejb.ApplicationException;
/**
*
* @author joern.muehlencord
*/
@ApplicationException(rollback=true)
public class ControllerException extends Exception {
private static final long serialVersionUID = 5190280225284514859L;

View File

@ -15,7 +15,6 @@
*/
package de.muehlencord.shared.account.util;
import de.muehlencord.shared.account.business.ControllerException;
import javax.annotation.Priority;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
@ -27,7 +26,6 @@ import static javax.transaction.Transactional.TxType.REQUIRED;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Joern Muehlencord <joern at muehlencord.de>
@ -46,10 +44,8 @@ public class AccountTransactionJoinInterceptor {
@AccountPU
private EntityManager em;
@AroundInvoke
public Object joinTransaction(InvocationContext context) throws Exception {
try {
if (em == null) {
return context.proceed();
} else {
@ -61,16 +57,5 @@ public class AccountTransactionJoinInterceptor {
}
}
return context.proceed();
} catch (ControllerException ex) {
if (em.isJoinedToTransaction()) {
em.getTransaction().rollback();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Transaction rolled back");
}
}
throw ex;
} catch (Exception ex) {
throw ex;
}
}
}

View File

@ -1,6 +1,5 @@
package de.muehlencord.shared.account.util;
import de.muehlencord.shared.account.business.ControllerException;
import javax.annotation.Priority;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
@ -32,7 +31,6 @@ public class ApplicationTransactionJoinInterceptor {
@AroundInvoke
public Object joinTransaction(InvocationContext context) throws Exception {
try {
if (em == null) {
return context.proceed();
} else {
@ -44,16 +42,5 @@ public class ApplicationTransactionJoinInterceptor {
}
}
return context.proceed();
} catch (ControllerException ex) {
if (em.isJoinedToTransaction()) {
em.getTransaction().rollback();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Transaction rolled back");
}
}
throw ex;
} catch (Exception ex) {
throw ex;
}
}
}