Search in sources :

Example 41 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class MessageEndpointInvocationHandler method afterDelivery.

@Override
public void afterDelivery() throws ResourceException {
    final TransactionManager tm = getTransactionManager();
    try {
        if (currentTx != null) {
            if (currentTx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
                tm.rollback();
            else
                tm.commit();
            currentTx = null;
        }
        if (previousTx != null) {
            tm.resume(previousTx);
            previousTx = null;
        }
    } catch (InvalidTransactionException e) {
        throw new LocalTransactionException(e);
    } catch (HeuristicMixedException e) {
        throw new LocalTransactionException(e);
    } catch (SystemException e) {
        throw new LocalTransactionException(e);
    } catch (HeuristicRollbackException e) {
        throw new LocalTransactionException(e);
    } catch (RollbackException e) {
        throw new LocalTransactionException(e);
    } finally {
        WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
        previousClassLoader = null;
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) LocalTransactionException(javax.resource.spi.LocalTransactionException) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) HeuristicMixedException(javax.transaction.HeuristicMixedException) InvalidTransactionException(javax.transaction.InvalidTransactionException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException)

Example 42 with TransactionManager

use of javax.transaction.TransactionManager 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 TransactionManager tm = component.getTransactionManager();
    final int oldTimeout = getCurrentTransactionTimeout(component);
    try {
        final MethodIntf methodIntf = MethodIntfHelper.of(invocation);
        final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
        final int timeoutInSeconds = component.getTransactionTimeout(methodIntf, invocation.getMethod());
        switch(attr) {
            case MANDATORY:
                return mandatory(invocation, component);
            case NEVER:
                return never(invocation, component);
            case NOT_SUPPORTED:
                return notSupported(invocation, component);
            case REQUIRED:
                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 {
        tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout);
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) TransactionAttributeType(javax.ejb.TransactionAttributeType)

Example 43 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class CMTTxInterceptor method notSupported.

protected Object notSupported(InterceptorContext invocation, final EJBComponent component) throws Exception {
    final TransactionManager tm = component.getTransactionManager();
    Transaction tx = tm.getTransaction();
    if (tx != null) {
        tm.suspend();
        try {
            return invokeInNoTx(invocation, component);
        } finally {
            tm.resume(tx);
        }
    } else {
        return invokeInNoTx(invocation, component);
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager)

Example 44 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class CMTTxInterceptor method requiresNew.

protected Object requiresNew(InterceptorContext invocation, final EJBComponent component, final int timeout) throws Exception {
    final TransactionManager tm = component.getTransactionManager();
    if (timeout != -1) {
        tm.setTransactionTimeout(timeout);
    }
    Transaction tx = tm.getTransaction();
    if (tx != null) {
        tm.suspend();
        try {
            return invokeInOurTx(invocation, tm, component);
        } finally {
            tm.resume(tx);
        }
    } else {
        return invokeInOurTx(invocation, tm, component);
    }
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager)

Example 45 with TransactionManager

use of javax.transaction.TransactionManager in project wildfly by wildfly.

the class EjbBMTInterceptor method handleInvocation.

@Override
protected Object handleInvocation(final InterceptorContext invocation) throws Exception {
    final EJBComponent ejbComponent = getComponent();
    TransactionManager tm = ejbComponent.getTransactionManager();
    assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
    boolean exceptionThrown = false;
    try {
        return invocation.proceed();
    } catch (Throwable ex) {
        exceptionThrown = true;
        checkStatelessDone(ejbComponent, invocation, tm, ex);
        //we should never get here, as checkStatelessDone should re-throw
        throw (Exception) ex;
    } finally {
        try {
            if (!exceptionThrown)
                checkStatelessDone(ejbComponent, invocation, tm, null);
        } finally {
            tm.suspend();
        }
    }
}
Also used : TransactionManager(javax.transaction.TransactionManager) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Aggregations

TransactionManager (javax.transaction.TransactionManager)110 Test (org.junit.Test)40 Transaction (javax.transaction.Transaction)24 SystemException (javax.transaction.SystemException)22 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)15 UserTransaction (javax.transaction.UserTransaction)14 JtaTransactionCoordinatorImpl (org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl)12 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)11 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)9 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)9 Method (java.lang.reflect.Method)7 EntityManager (javax.persistence.EntityManager)7 NotSupportedException (javax.transaction.NotSupportedException)7 RollbackException (javax.transaction.RollbackException)7 SynchronizationCollectorImpl (org.hibernate.test.resource.common.SynchronizationCollectorImpl)6 TestForIssue (org.hibernate.testing.TestForIssue)6 IOException (java.io.IOException)5 InitialContext (javax.naming.InitialContext)5 DataSource (javax.sql.DataSource)5 JtaPlatform (org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform)5