Search in sources :

Example 1 with LocalTransaction

use of org.wildfly.transaction.client.LocalTransaction in project wildfly by wildfly.

the class JBossContextXATerminator method startWork.

/**
     * <p>
     * Start work gets imported transaction and assign it to current thread.
     * <p>
     * This method mimics behavior of Narayana's {@link JBossXATerminator}.
     */
@Override
public void startWork(Work work, Xid xid) throws WorkCompletedException {
    LocalTransaction transaction = null;
    try {
        ImportResult<LocalTransaction> transactionImportResult = localTransactionContext.findOrImportTransaction(xid, 0);
        transaction = transactionImportResult.getTransaction();
        ContextTransactionManager.getInstance().resume(transaction);
    } catch (XAException xae) {
        throw TransactionLogger.ROOT_LOGGER.cannotFindOrImportInflowTransaction(xid, work, xae);
    } catch (InvalidTransactionException ite) {
        throw TransactionLogger.ROOT_LOGGER.importedInflowTransactionIsInactive(xid, work, ite);
    } catch (SystemException se) {
        throw TransactionLogger.ROOT_LOGGER.cannotResumeInflowTransactionUnexpectedError(transaction, work, se);
    }
}
Also used : XAException(javax.transaction.xa.XAException) LocalTransaction(org.wildfly.transaction.client.LocalTransaction) SystemException(javax.transaction.SystemException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Example 2 with LocalTransaction

use of org.wildfly.transaction.client.LocalTransaction 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);
    }
}
Also used : ContextTransactionManager(org.wildfly.transaction.client.ContextTransactionManager) LocalTransaction(org.wildfly.transaction.client.LocalTransaction) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Aggregations

InvalidTransactionException (javax.transaction.InvalidTransactionException)2 LocalTransaction (org.wildfly.transaction.client.LocalTransaction)2 SystemException (javax.transaction.SystemException)1 XAException (javax.transaction.xa.XAException)1 ContextTransactionManager (org.wildfly.transaction.client.ContextTransactionManager)1