Search in sources :

Example 86 with TransactionManager

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

the class CMTTxInterceptor method required.

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

Example 87 with TransactionManager

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

the class CMTTxInterceptor method mandatory.

protected Object mandatory(InterceptorContext invocation, final EJBComponent component) throws Exception {
    final TransactionManager tm = component.getTransactionManager();
    Transaction tx = tm.getTransaction();
    if (tx == null) {
        throw EjbLogger.ROOT_LOGGER.txRequiredForInvocation(invocation);
    }
    return invokeInCallerTx(invocation, tx, component);
}
Also used : Transaction(javax.transaction.Transaction) TransactionManager(javax.transaction.TransactionManager)

Example 88 with TransactionManager

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

the class CMTTxInterceptor method supports.

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

Example 89 with TransactionManager

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

the class LifecycleCMTTxInterceptor method notSupported.

@Override
protected Object notSupported(InterceptorContext invocation, EJBComponent component) throws Exception {
    TransactionManager tm = component.getTransactionManager();
    Transaction tx = tm.getTransaction();
    int status = (tx != null) ? tx.getStatus() : Status.STATUS_NO_TRANSACTION;
    // then skip suspend/resume of associated tx since JTS refuses to resume a completed tx
    switch(status) {
        case Status.STATUS_NO_TRANSACTION:
        case Status.STATUS_COMMITTED:
        case Status.STATUS_ROLLEDBACK:
            {
                return this.invokeInNoTx(invocation, component);
            }
        default:
            {
                Transaction suspendedTx = tm.suspend();
                try {
                    return this.invokeInNoTx(invocation, component);
                } finally {
                    if (suspendedTx != null) {
                        tm.resume(suspendedTx);
                    }
                }
            }
    }
}
Also used : Transaction(javax.transaction.Transaction) LocalTransaction(org.wildfly.transaction.client.LocalTransaction) ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) TransactionManager(javax.transaction.TransactionManager)

Example 90 with TransactionManager

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

the class StatefulBMTInterceptor method handleInvocation.

@Override
protected Object handleInvocation(final InterceptorContext invocation) throws Exception {
    final StatefulSessionComponentInstance instance = (StatefulSessionComponentInstance) invocation.getPrivateData(ComponentInstance.class);
    TransactionManager tm = getComponent().getTransactionManager();
    assert tm.getTransaction() == null : "can't handle BMT transaction, there is a transaction active";
    // Is the instance already associated with a transaction?
    Transaction tx = instance.getTransaction();
    if (tx != null) {
        // then resume that transaction.
        instance.setTransaction(null);
        tm.resume(tx);
    }
    try {
        return invocation.proceed();
    } catch (Throwable e) {
        throw this.handleException(invocation, e);
    } finally {
        checkBadStateful();
        // Is the instance finished with the transaction?
        Transaction newTx = tm.getTransaction();
        //always set it, even if null
        instance.setTransaction(newTx);
        if (newTx != null) {
            // remember the association
            // and suspend it.
            tm.suspend();
        }
    }
}
Also used : Transaction(javax.transaction.Transaction) StatefulSessionComponentInstance(org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance) TransactionManager(javax.transaction.TransactionManager) ComponentInstance(org.jboss.as.ee.component.ComponentInstance) StatefulSessionComponentInstance(org.jboss.as.ejb3.component.stateful.StatefulSessionComponentInstance)

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