use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class LifecycleCMTTxInterceptor method beginTransaction.
protected Transaction beginTransaction(final TransactionManager tm) throws NotSupportedException, SystemException {
if (tm instanceof ContextTransactionManager) {
final ContextTransactionManager contextTransactionManager = (ContextTransactionManager) tm;
int timeout = contextTransactionManager.getTransactionTimeout();
final LocalTransaction transaction = LocalTransactionContext.getCurrent().beginTransaction(timeout, false);
try {
contextTransactionManager.resume(transaction);
} catch (InvalidTransactionException e) {
// should not be possible
throw new IllegalStateException(e);
}
return transaction;
} else {
return super.beginTransaction(tm);
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class CMTTxInterceptor method invokeInOurTx.
protected Object invokeInOurTx(InterceptorContext invocation, final EJBComponent component) throws Exception {
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
tm.begin();
final AbstractTransaction tx = tm.getTransaction();
Object result = null;
Exception except = null;
try {
result = invocation.proceed();
} catch (Throwable t) {
ApplicationExceptionDetails ae = component.getApplicationException(t.getClass(), invocation.getMethod());
try {
try {
throw t;
} catch (EJBException | RemoteException e) {
throw e;
} catch (RuntimeException e) {
if (ae != null && !ae.isRollback()) {
except = e;
} else if (ae != null && ae.isRollback()) {
throw e;
} else {
throw new EJBException(e);
}
} catch (Exception e) {
throw e;
} catch (Error e) {
throw EjbLogger.ROOT_LOGGER.unexpectedError(e);
} catch (Throwable e) {
throw new EJBException(new UndeclaredThrowableException(e));
}
} catch (Throwable t2) {
if (ae == null || ae.isRollback())
setRollbackOnly(tx, t2);
endTransaction(tx, t2);
throw t2;
}
}
boolean rolledBack = safeGetStatus(tx) == Status.STATUS_MARKED_ROLLBACK;
endTransaction(tx);
if (except != null) {
throw except;
}
if (rolledBack)
ourTxRolledBack();
return result;
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class CMTTxInterceptor method notSupported.
protected Object notSupported(InterceptorContext invocation, final EJBComponent component) throws Exception {
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
Transaction tx = tm.getTransaction();
if (tx != null) {
safeSuspend();
final Object result;
try {
result = invokeInNoTx(invocation, component);
} catch (Throwable t) {
safeResume(tx, t);
throw t;
}
safeResume(tx);
return result;
} else {
return invokeInNoTx(invocation, component);
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class CMTTxInterceptor method processInvocation.
public Object processInvocation(InterceptorContext invocation) throws Exception {
final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
final int oldTimeout = tm.getTransactionTimeout();
try {
final MethodIntf methodIntf = MethodIntfHelper.of(invocation);
final Method method = invocation.getMethod();
final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, method);
final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, method);
switch(attr) {
case MANDATORY:
return mandatory(invocation, component);
case NEVER:
return never(invocation, component);
case NOT_SUPPORTED:
return notSupported(invocation, component);
case REQUIRED:
final ComponentView view = invocation.getPrivateData(ComponentView.class);
if (view != null && view.isAsynchronous(method)) {
// method are exactly the same as REQUIRES_NEW.
return requiresNew(invocation, component, timeoutInSeconds);
}
return required(invocation, component, timeoutInSeconds);
case REQUIRES_NEW:
return requiresNew(invocation, component, timeoutInSeconds);
case SUPPORTS:
return supports(invocation, component);
default:
throw EjbLogger.ROOT_LOGGER.unknownTxAttributeOnInvocation(attr, invocation);
}
} finally {
// See also https://issues.jboss.org/browse/WFTC-44
tm.setTransactionTimeout(oldTimeout == ContextTransactionManager.getGlobalDefaultTransactionTimeout() ? 0 : oldTimeout);
}
}
use of org.wildfly.transaction.client.ContextTransactionManager in project wildfly by wildfly.
the class CMTTxInterceptor method requiresNew.
protected Object requiresNew(InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception {
final ContextTransactionManager tm = ContextTransactionManager.getInstance();
if (timeout != -1) {
tm.setTransactionTimeout(timeout);
}
Transaction tx = tm.getTransaction();
if (tx != null) {
safeSuspend();
final Object result;
try {
result = invokeInOurTx(invocation, component);
} catch (Throwable t) {
safeResume(tx, t);
throw t;
}
safeResume(tx);
return result;
} else {
return invokeInOurTx(invocation, component);
}
}
Aggregations