Search in sources :

Example 1 with InvalidTransactionException

use of javax.transaction.InvalidTransactionException in project geode by apache.

the class TransactionManagerImpl method resume.

/**
   * @see javax.transaction.TransactionManager#resume(javax.transaction.Transaction)
   */
public void resume(Transaction txn) throws InvalidTransactionException, IllegalStateException, SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    if (txn == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_RESUME_CANNOT_RESUME_A_NULL_TRANSACTION.toLocalizedString();
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new InvalidTransactionException(exception);
    }
    GlobalTransaction gtx = getGlobalTransaction(txn);
    if (gtx == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_RESUME_CANNOT_RESUME_A_NULL_TRANSACTION.toLocalizedString();
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new InvalidTransactionException(exception);
    }
    gtx.resume();
    try {
        Thread thread = Thread.currentThread();
        transactionMap.put(thread, txn);
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPLRESUMETRANSACTION_RESUMED);
    } catch (Exception e) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_RESUME_ERROR_IN_LISTING_THREAD_TO_TRANSACTION_MAP_DUE_TO_0.toLocalizedString(e);
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
}
Also used : SystemException(javax.transaction.SystemException) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InvalidTransactionException(javax.transaction.InvalidTransactionException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) CancelException(org.apache.geode.CancelException)

Example 2 with InvalidTransactionException

use of javax.transaction.InvalidTransactionException 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 3 with InvalidTransactionException

use of javax.transaction.InvalidTransactionException 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 4 with InvalidTransactionException

use of javax.transaction.InvalidTransactionException 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)

Example 5 with InvalidTransactionException

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

the class InfinispanBatcher method resumeBatch.

@Override
public BatchContext resumeBatch(TransactionBatch batch) {
    TransactionBatch existingBatch = CURRENT_BATCH.get();
    // Trivial case - nothing to suspend/resume
    if (batch == existingBatch)
        return PASSIVE_BATCH_CONTEXT;
    Transaction tx = (batch != null) ? batch.getTransaction() : null;
    // Non-tx case, just swap thread local
    if ((batch == null) || (tx == null)) {
        CURRENT_BATCH.set(batch);
        return () -> {
            CURRENT_BATCH.set(existingBatch);
        };
    }
    try {
        if (existingBatch != null) {
            Transaction existingTx = this.tm.suspend();
            if (existingBatch.getTransaction() != existingTx) {
                throw new IllegalStateException();
            }
        }
        this.tm.resume(tx);
        CURRENT_BATCH.set(batch);
        return () -> {
            try {
                this.tm.suspend();
                if (existingBatch != null) {
                    try {
                        this.tm.resume(existingBatch.getTransaction());
                        CURRENT_BATCH.set(existingBatch);
                    } catch (InvalidTransactionException e) {
                        throw new CacheException(e);
                    }
                } else {
                    CURRENT_BATCH.remove();
                }
            } catch (SystemException e) {
                throw new CacheException(e);
            }
        };
    } catch (SystemException | InvalidTransactionException e) {
        throw new CacheException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) CacheException(org.infinispan.commons.CacheException) InvalidTransactionException(javax.transaction.InvalidTransactionException)

Aggregations

InvalidTransactionException (javax.transaction.InvalidTransactionException)6 SystemException (javax.transaction.SystemException)4 HeuristicMixedException (javax.transaction.HeuristicMixedException)2 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)2 RollbackException (javax.transaction.RollbackException)2 LocalTransaction (org.wildfly.transaction.client.LocalTransaction)2 LocalTransactionException (javax.resource.spi.LocalTransactionException)1 NotSupportedException (javax.transaction.NotSupportedException)1 Transaction (javax.transaction.Transaction)1 TransactionManager (javax.transaction.TransactionManager)1 XAException (javax.transaction.xa.XAException)1 CancelException (org.apache.geode.CancelException)1 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)1 SystemException (org.apache.openejb.SystemException)1 CacheException (org.infinispan.commons.CacheException)1 ContextTransactionManager (org.wildfly.transaction.client.ContextTransactionManager)1