Search in sources :

Example 1 with AbstractTransaction

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);
    }
}
Also used : InterceptorContext(org.jboss.invocation.InterceptorContext) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction) EJBException(javax.ejb.EJBException) EJBException(javax.ejb.EJBException) ObjectStreamException(java.io.ObjectStreamException)

Example 2 with AbstractTransaction

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;
}
Also used : ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction) NoSuchEJBException(javax.ejb.NoSuchEJBException) EJBException(javax.ejb.EJBException) NoSuchEJBException(javax.ejb.NoSuchEJBException) RollbackException(javax.transaction.RollbackException) NoSuchEntityException(javax.ejb.NoSuchEntityException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) EJBTransactionRolledbackException(javax.ejb.EJBTransactionRolledbackException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 3 with AbstractTransaction

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);
    }
}
Also used : SystemException(javax.transaction.SystemException) ContextTransactionSynchronizationRegistry(org.wildfly.transaction.client.ContextTransactionSynchronizationRegistry) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction)

Example 4 with AbstractTransaction

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;
    });
}
Also used : ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction)

Example 5 with AbstractTransaction

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();
                    }
                });
            }
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UserTransactionRegistry(org.jboss.tm.usertx.UserTransactionRegistry) AssociationListener(org.wildfly.transaction.client.AssociationListener) AbstractTransaction(org.wildfly.transaction.client.AbstractTransaction)

Aggregations

AbstractTransaction (org.wildfly.transaction.client.AbstractTransaction)5 EJBException (javax.ejb.EJBException)2 SystemException (javax.transaction.SystemException)2 ContextTransactionManager (org.wildfly.transaction.client.ContextTransactionManager)2 ObjectStreamException (java.io.ObjectStreamException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 RemoteException (java.rmi.RemoteException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EJBTransactionRolledbackException (javax.ejb.EJBTransactionRolledbackException)1 NoSuchEJBException (javax.ejb.NoSuchEJBException)1 NoSuchEntityException (javax.ejb.NoSuchEntityException)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 RollbackException (javax.transaction.RollbackException)1 InterceptorContext (org.jboss.invocation.InterceptorContext)1 UserTransactionRegistry (org.jboss.tm.usertx.UserTransactionRegistry)1 AssociationListener (org.wildfly.transaction.client.AssociationListener)1 ContextTransactionSynchronizationRegistry (org.wildfly.transaction.client.ContextTransactionSynchronizationRegistry)1