Search in sources :

Example 46 with SystemException

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

the class WeldTransactionServices method registerSynchronization.

@Override
public void registerSynchronization(Synchronization synchronizedObserver) {
    try {
        final Synchronization synchronization;
        if (!jtsEnabled) {
            synchronization = synchronizedObserver;
        } else {
            synchronization = new JTSSynchronizationWrapper(synchronizedObserver);
        }
        injectedTransactionManager.getValue().getTransaction().registerSynchronization(synchronization);
    } catch (IllegalStateException e) {
        throw new RuntimeException(e);
    } catch (RollbackException e) {
        throw new RuntimeException(e);
    } catch (SystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : SystemException(javax.transaction.SystemException) Synchronization(javax.transaction.Synchronization) RollbackException(javax.transaction.RollbackException)

Example 47 with SystemException

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

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

the class TimerServiceImpl method registerSynchronization.

private void registerSynchronization(Synchronization synchronization) {
    try {
        final Transaction tx = this.getTransaction();
        // register for lifecycle events of transaction
        tx.registerSynchronization(synchronization);
    } catch (RollbackException e) {
        throw new EJBException(e);
    } catch (SystemException e) {
        throw new EJBException(e);
    }
}
Also used : Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) EJBException(javax.ejb.EJBException)

Example 49 with SystemException

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

the class DatabaseTimerPersistence method shouldRun.

@Override
public boolean shouldRun(TimerImpl timer, TransactionManager tm) {
    if (!allowExecution) {
        //timers never execute on this node
        return false;
    }
    String loadTimer = sql(UPDATE_RUNNING);
    Connection connection = null;
    PreparedStatement statement = null;
    try {
        try {
            connection = dataSource.getConnection();
            statement = connection.prepareStatement(loadTimer);
            statement.setString(1, TimerState.IN_TIMEOUT.name());
            setNodeName(TimerState.IN_TIMEOUT, statement, 2);
            statement.setString(3, timer.getId());
            statement.setString(4, TimerState.IN_TIMEOUT.name());
            statement.setString(5, TimerState.RETRY_TIMEOUT.name());
            if (timer.getNextExpiration() == null) {
                statement.setTimestamp(6, null);
            } else {
                statement.setTimestamp(6, timestamp(timer.getNextExpiration()));
            }
        } catch (SQLException e) {
            // something wrong with the preparation
            throw new RuntimeException(e);
        }
        tm.begin();
        int affected = statement.executeUpdate();
        tm.commit();
        return affected == 1;
    } catch (SQLException | SystemException | SecurityException | IllegalStateException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        // failed to update the DB
        try {
            tm.rollback();
        } catch (IllegalStateException | SecurityException | SystemException rbe) {
            EjbLogger.EJB3_TIMER_LOGGER.timerUpdateFailedAndRollbackNotPossible(rbe);
        }
        EjbLogger.EJB3_TIMER_LOGGER.debugf(e, "Timer %s not running due to exception ", timer);
        return false;
    } catch (NotSupportedException e) {
        // happen from tm.begin, no rollback necessary
        EjbLogger.EJB3_TIMER_LOGGER.timerNotRunning(e, timer);
        return false;
    } finally {
        safeClose(statement);
        safeClose(connection);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotSupportedException(javax.transaction.NotSupportedException)

Example 50 with SystemException

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

the class FileTimerPersistence method persistTimer.

private void persistTimer(final TimerImpl timer, boolean newTimer) {
    final Lock lock = getLock(timer.getTimedObjectId());
    try {
        final int status = transactionManager.getValue().getStatus();
        if (status == Status.STATUS_MARKED_ROLLBACK || status == Status.STATUS_ROLLEDBACK || status == Status.STATUS_ROLLING_BACK) {
            //no need to persist anyway
            return;
        }
        lock.lock();
        if (status == Status.STATUS_NO_TRANSACTION || status == Status.STATUS_UNKNOWN || isBeforeCompletion() || status == Status.STATUS_COMMITTED) {
            Map<String, TimerImpl> map = getTimers(timer.getTimedObjectId(), timer.getTimerService());
            if (timer.getState() == TimerState.CANCELED || timer.getState() == TimerState.EXPIRED) {
                map.remove(timer.getId());
                writeFile(timer);
            } else if (newTimer || map.containsKey(timer.getId())) {
                //if it is not a new timer and is not in the map then it has
                //been removed by another thread.
                map.put(timer.getId(), timer);
                writeFile(timer);
            }
        } else {
            final String key = timerTransactionKey(timer);
            Object existing = transactionSynchronizationRegistry.getValue().getResource(key);
            //check is there is already a persist sync for this timer
            if (existing == null) {
                transactionSynchronizationRegistry.getValue().registerInterposedSynchronization(new PersistTransactionSynchronization(lock, key, newTimer));
            }
            //update the most recent version of the timer to be persisted
            transactionSynchronizationRegistry.getValue().putResource(key, timer);
        }
    } catch (SystemException e) {
        throw new RuntimeException(e);
    } finally {
        lock.unlock();
    }
}
Also used : SystemException(javax.transaction.SystemException) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

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