use of org.wildfly.transaction.client.AbstractTransaction in project wildfly by wildfly.
the class StatefulSessionComponentInstance method execute.
private Object execute(final Interceptor interceptor, final Method method, final Object... parameters) {
if (interceptor == null)
return null;
final InterceptorContext interceptorContext = new InterceptorContext();
// we need the method so this does not count as a lifecycle invocation
interceptorContext.setMethod(method);
interceptorContext.putPrivateData(Component.class, getComponent());
interceptorContext.putPrivateData(ComponentInstance.class, this);
interceptorContext.putPrivateData(InvokeMethodOnTargetInterceptor.PARAMETERS_KEY, parameters);
interceptorContext.setContextData(new HashMap<String, Object>());
interceptorContext.setTarget(getInstance());
final AbstractTransaction transaction = ContextTransactionManager.getInstance().getTransaction();
interceptorContext.setTransactionSupplier(() -> transaction);
try {
return interceptor.processInvocation(interceptorContext);
} catch (Error e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new EJBException(e);
}
}
use of org.wildfly.transaction.client.AbstractTransaction 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.AbstractTransaction in project wildfly by wildfly.
the class TransactionSynchronizationRegistryWrapper method registerInterposedSynchronization.
@Override
public void registerInterposedSynchronization(Synchronization sync) throws IllegalStateException {
try {
AbstractTransaction tx = ContextTransactionManager.getInstance().getTransaction();
if (tx == null) {
throw TransactionLogger.ROOT_LOGGER.noActiveTransactionToRegisterSynchronization(sync);
}
JCAOrderedLastSynchronizationList jcaOrderedLastSynchronization = (JCAOrderedLastSynchronizationList) tx.getResource(key);
if (jcaOrderedLastSynchronization == null) {
final ContextTransactionSynchronizationRegistry tsr = ContextTransactionSynchronizationRegistry.getInstance();
synchronized (key) {
jcaOrderedLastSynchronization = (JCAOrderedLastSynchronizationList) tx.getResource(key);
if (jcaOrderedLastSynchronization == null) {
jcaOrderedLastSynchronization = new JCAOrderedLastSynchronizationList();
tx.putResource(key, jcaOrderedLastSynchronization);
tsr.registerInterposedSynchronization(jcaOrderedLastSynchronization);
}
}
}
jcaOrderedLastSynchronization.registerInterposedSynchronization(sync);
} catch (SystemException e) {
throw new IllegalStateException(e);
}
}
use of org.wildfly.transaction.client.AbstractTransaction in project wildfly by wildfly.
the class TransactionUtil method registerSynchronization.
public static void registerSynchronization(EntityManager entityManager, String puScopedName, TransactionSynchronizationRegistry tsr, TransactionManager transactionManager) {
SessionSynchronization sessionSynchronization = new SessionSynchronization(entityManager, puScopedName);
tsr.registerInterposedSynchronization(sessionSynchronization);
final AbstractTransaction transaction = ((ContextTransactionManager) transactionManager).getTransaction();
doPrivileged((PrivilegedAction<Void>) () -> {
transaction.registerAssociationListener(sessionSynchronization);
return null;
});
}
use of org.wildfly.transaction.client.AbstractTransaction in project wildfly by wildfly.
the class TransactionManagerService method start.
public void start(final StartContext context) throws StartException {
final UserTransactionRegistry registry = registryInjector.getValue();
LocalTransactionContext.getCurrent().registerCreationListener((txn, createdBy) -> {
if (createdBy == CreationListener.CreatedBy.USER_TRANSACTION) {
if (WildFlySecurityManager.isChecking()) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
txn.registerAssociationListener(new AssociationListener() {
private final AtomicBoolean first = new AtomicBoolean();
public void associationChanged(final AbstractTransaction t, final boolean a) {
if (a && first.compareAndSet(false, true))
registry.userTransactionStarted();
}
});
return null;
});
} else {
txn.registerAssociationListener(new AssociationListener() {
private final AtomicBoolean first = new AtomicBoolean();
public void associationChanged(final AbstractTransaction t, final boolean a) {
if (a && first.compareAndSet(false, true))
registry.userTransactionStarted();
}
});
}
}
});
}
Aggregations