fixed tx join interceptor handling
This commit is contained in:
@ -15,10 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business;
|
package de.muehlencord.shared.account.business;
|
||||||
|
|
||||||
|
import javax.ejb.ApplicationException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
|
@ApplicationException(rollback=true)
|
||||||
public class ControllerException extends Exception {
|
public class ControllerException extends Exception {
|
||||||
|
|
||||||
private static final long serialVersionUID = 5190280225284514859L;
|
private static final long serialVersionUID = 5190280225284514859L;
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.util;
|
package de.muehlencord.shared.account.util;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.ControllerException;
|
|
||||||
import javax.annotation.Priority;
|
import javax.annotation.Priority;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.interceptor.AroundInvoke;
|
import javax.interceptor.AroundInvoke;
|
||||||
@ -27,7 +26,6 @@ import static javax.transaction.Transactional.TxType.REQUIRED;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
@ -46,10 +44,8 @@ public class AccountTransactionJoinInterceptor {
|
|||||||
@AccountPU
|
@AccountPU
|
||||||
private EntityManager em;
|
private EntityManager em;
|
||||||
|
|
||||||
|
|
||||||
@AroundInvoke
|
@AroundInvoke
|
||||||
public Object joinTransaction(InvocationContext context) throws Exception {
|
public Object joinTransaction(InvocationContext context) throws Exception {
|
||||||
try {
|
|
||||||
if (em == null) {
|
if (em == null) {
|
||||||
return context.proceed();
|
return context.proceed();
|
||||||
} else {
|
} else {
|
||||||
@ -61,16 +57,5 @@ public class AccountTransactionJoinInterceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context.proceed();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
package de.muehlencord.shared.account.util;
|
package de.muehlencord.shared.account.util;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.ControllerException;
|
|
||||||
import javax.annotation.Priority;
|
import javax.annotation.Priority;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.interceptor.AroundInvoke;
|
import javax.interceptor.AroundInvoke;
|
||||||
@ -32,7 +31,6 @@ public class ApplicationTransactionJoinInterceptor {
|
|||||||
|
|
||||||
@AroundInvoke
|
@AroundInvoke
|
||||||
public Object joinTransaction(InvocationContext context) throws Exception {
|
public Object joinTransaction(InvocationContext context) throws Exception {
|
||||||
try {
|
|
||||||
if (em == null) {
|
if (em == null) {
|
||||||
return context.proceed();
|
return context.proceed();
|
||||||
} else {
|
} else {
|
||||||
@ -44,16 +42,5 @@ public class ApplicationTransactionJoinInterceptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return context.proceed();
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user