fixed tx join interceptor handling
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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,50 +26,36 @@ import static javax.transaction.Transactional.TxType.REQUIRED;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||
*/
|
||||
@Transactional(value = REQUIRED)
|
||||
@Interceptor
|
||||
@Priority(value=AccountTransactionJoinInterceptor.PRIORITY)
|
||||
@Priority(value = AccountTransactionJoinInterceptor.PRIORITY)
|
||||
public class AccountTransactionJoinInterceptor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AccountTransactionJoinInterceptor.class);
|
||||
|
||||
// attach behind the interceptor of the container
|
||||
public static final int PRIORITY = Interceptor.Priority.PLATFORM_BEFORE+250;
|
||||
public static final int PRIORITY = Interceptor.Priority.PLATFORM_BEFORE + 250;
|
||||
|
||||
@Inject
|
||||
@AccountPU
|
||||
private EntityManager em;
|
||||
|
||||
|
||||
@AroundInvoke
|
||||
public Object joinTransaction(InvocationContext context) throws Exception {
|
||||
try {
|
||||
if (em == null) {
|
||||
return context.proceed();
|
||||
} else {
|
||||
if (em.isJoinedToTransaction()) {
|
||||
LOGGER.trace("transaction already joined");
|
||||
} else {
|
||||
LOGGER.trace("joining transaction");
|
||||
em.joinTransaction();
|
||||
}
|
||||
}
|
||||
if (em == null) {
|
||||
return context.proceed();
|
||||
} catch (ControllerException ex) {
|
||||
} else {
|
||||
if (em.isJoinedToTransaction()) {
|
||||
em.getTransaction().rollback();
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Transaction rolled back");
|
||||
}
|
||||
LOGGER.trace("transaction already joined");
|
||||
} else {
|
||||
LOGGER.trace("joining transaction");
|
||||
em.joinTransaction();
|
||||
}
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw ex;
|
||||
}
|
||||
return context.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,28 +31,16 @@ public class ApplicationTransactionJoinInterceptor {
|
||||
|
||||
@AroundInvoke
|
||||
public Object joinTransaction(InvocationContext context) throws Exception {
|
||||
try {
|
||||
if (em == null) {
|
||||
return context.proceed();
|
||||
} else {
|
||||
if (em.isJoinedToTransaction()) {
|
||||
LOGGER.trace("transaction already joined");
|
||||
} else {
|
||||
LOGGER.trace("joining transaction");
|
||||
em.joinTransaction();
|
||||
}
|
||||
}
|
||||
if (em == null) {
|
||||
return context.proceed();
|
||||
} catch (ControllerException ex) {
|
||||
} else {
|
||||
if (em.isJoinedToTransaction()) {
|
||||
em.getTransaction().rollback();
|
||||
if (LOGGER.isTraceEnabled()) {
|
||||
LOGGER.trace("Transaction rolled back");
|
||||
}
|
||||
LOGGER.trace("transaction already joined");
|
||||
} else {
|
||||
LOGGER.trace("joining transaction");
|
||||
em.joinTransaction();
|
||||
}
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
throw ex;
|
||||
}
|
||||
return context.proceed();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user