Search in sources :

Example 51 with SystemException

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

the class FileTimerPersistence method mostRecentEntityVersion.

/**
     * Returns either the loaded entity or the most recent version of the entity that has
     * been persisted in this transaction.
     */
private TimerImpl mostRecentEntityVersion(final TimerImpl timerImpl) {
    try {
        final int status = transactionManager.getValue().getStatus();
        if (status == Status.STATUS_UNKNOWN || status == Status.STATUS_NO_TRANSACTION) {
            return timerImpl;
        }
        final String key = timerTransactionKey(timerImpl);
        TimerImpl existing = (TimerImpl) transactionSynchronizationRegistry.getValue().getResource(key);
        return existing != null ? existing : timerImpl;
    } catch (SystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : SystemException(javax.transaction.SystemException) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl)

Example 52 with SystemException

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

the class StatefulBMTInterceptor method checkBadStateful.

private void checkBadStateful() {
    int status = Status.STATUS_NO_TRANSACTION;
    TransactionManager tm = getComponent().getTransactionManager();
    try {
        status = tm.getStatus();
    } catch (SystemException ex) {
        EjbLogger.ROOT_LOGGER.failedToGetStatus(ex);
    }
    switch(status) {
        case Status.STATUS_COMMITTING:
        case Status.STATUS_MARKED_ROLLBACK:
        case Status.STATUS_PREPARING:
        case Status.STATUS_ROLLING_BACK:
            try {
                tm.rollback();
            } catch (Exception ex) {
                EjbLogger.ROOT_LOGGER.failedToRollback(ex);
            }
            EjbLogger.ROOT_LOGGER.transactionNotComplete(getComponent().getComponentName(), statusAsString(status));
    }
}
Also used : SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) SystemException(javax.transaction.SystemException)

Example 53 with SystemException

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

Example 54 with SystemException

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

the class InfinispanBatcher method createBatch.

@Override
public TransactionBatch createBatch() {
    if (this.tm == null)
        return NON_TX_BATCH;
    TransactionBatch batch = CURRENT_BATCH.get();
    if (batch != null) {
        return batch.interpose();
    }
    try {
        this.tm.suspend();
        this.tm.begin();
        Transaction tx = this.tm.getTransaction();
        tx.registerSynchronization(CURRENT_BATCH_REMOVER);
        batch = new InfinispanBatch(tx);
        CURRENT_BATCH.set(batch);
        return batch;
    } catch (RollbackException | SystemException | NotSupportedException e) {
        throw new CacheException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) CacheException(org.infinispan.commons.CacheException) RollbackException(javax.transaction.RollbackException) NotSupportedException(javax.transaction.NotSupportedException)

Example 55 with SystemException

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

the class EJBComponent method setRollbackOnly.

public void setRollbackOnly() throws IllegalStateException {
    if (isBeanManagedTransaction()) {
        throw EjbLogger.ROOT_LOGGER.failToCallSetRollbackOnlyOnNoneCMB();
    }
    try {
        // get the transaction manager
        TransactionManager tm = getTransactionManager();
        // check if there's a tx in progress. If not, then it's an error to call setRollbackOnly()
        if (tm.getTransaction() == null) {
            throw EjbLogger.ROOT_LOGGER.failToCallSetRollbackOnlyWithNoTx();
        }
        // set rollback
        tm.setRollbackOnly();
    } catch (SystemException se) {
        EjbLogger.ROOT_LOGGER.setRollbackOnlyFailed(se);
    }
}
Also used : SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager)

Aggregations

SystemException (javax.transaction.SystemException)102 Transaction (javax.transaction.Transaction)34 RollbackException (javax.transaction.RollbackException)29 NotSupportedException (javax.transaction.NotSupportedException)22 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)18 IOException (java.io.IOException)16 HeuristicMixedException (javax.transaction.HeuristicMixedException)16 UserTransaction (javax.transaction.UserTransaction)14 XAException (javax.transaction.xa.XAException)13 Test (org.junit.Test)12 TransactionManager (javax.transaction.TransactionManager)11 SQLException (java.sql.SQLException)10 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)10 InvalidTransactionException (javax.transaction.InvalidTransactionException)9 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)8 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)8 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)8 XAResource (javax.transaction.xa.XAResource)7 Synchronization (javax.transaction.Synchronization)6 File (java.io.File)5