Search in sources :

Example 1 with SystemException

use of javax.transaction.SystemException in project hibernate-orm by hibernate.

the class XaTransactionImpl method commit.

public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
    if (status == Status.STATUS_MARKED_ROLLBACK) {
        log.trace("on commit, status was marked for rollback-only");
        rollback();
    } else {
        status = Status.STATUS_PREPARING;
        if (synchronizations != null) {
            for (int i = 0; i < synchronizations.size(); i++) {
                Synchronization s = (Synchronization) synchronizations.get(i);
                s.beforeCompletion();
            }
        }
        if (!runXaResourcePrepare()) {
            status = Status.STATUS_ROLLING_BACK;
        } else {
            status = Status.STATUS_PREPARED;
        }
        status = Status.STATUS_COMMITTING;
        if (connection != null) {
            try {
                connection.commit();
                connectionProvider.closeConnection(connection);
                connection = null;
            } catch (SQLException sqle) {
                status = Status.STATUS_UNKNOWN;
                throw new SystemException();
            }
        }
        runXaResourceCommitTx();
        status = Status.STATUS_COMMITTED;
        if (synchronizations != null) {
            for (int i = 0; i < synchronizations.size(); i++) {
                Synchronization s = (Synchronization) synchronizations.get(i);
                s.afterCompletion(status);
            }
        }
        // status = Status.STATUS_NO_TRANSACTION;
        jtaTransactionManager.endCurrent(this);
    }
}
Also used : SystemException(javax.transaction.SystemException) SQLException(java.sql.SQLException) Synchronization(javax.transaction.Synchronization)

Example 2 with SystemException

use of javax.transaction.SystemException in project hibernate-orm by hibernate.

the class DualNodeJtaTransactionImpl method commit.

public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, IllegalStateException, SystemException {
    if (status == Status.STATUS_MARKED_ROLLBACK) {
        log.trace("on commit, status was marked for rollback-only");
        rollback();
    } else {
        status = Status.STATUS_PREPARING;
        if (synchronizations != null) {
            for (int i = 0; i < synchronizations.size(); i++) {
                Synchronization s = (Synchronization) synchronizations.get(i);
                s.beforeCompletion();
            }
        }
        if (!runXaResourcePrepare()) {
            status = Status.STATUS_ROLLING_BACK;
        } else {
            status = Status.STATUS_PREPARED;
        }
        status = Status.STATUS_COMMITTING;
        if (connection != null) {
            try {
                connection.commit();
                connection.close();
            } catch (SQLException sqle) {
                status = Status.STATUS_UNKNOWN;
                throw new SystemException();
            }
        }
        runXaResourceCommitTx();
        status = Status.STATUS_COMMITTED;
        if (synchronizations != null) {
            for (int i = 0; i < synchronizations.size(); i++) {
                Synchronization s = (Synchronization) synchronizations.get(i);
                s.afterCompletion(status);
            }
        }
        // status = Status.STATUS_NO_TRANSACTION;
        jtaTransactionManager.endCurrent(this);
    }
}
Also used : SystemException(javax.transaction.SystemException) SQLException(java.sql.SQLException) Synchronization(javax.transaction.Synchronization)

Example 3 with SystemException

use of javax.transaction.SystemException in project hibernate-orm by hibernate.

the class DualNodeJtaTransactionImpl method rollback.

public void rollback() throws IllegalStateException, SystemException {
    status = Status.STATUS_ROLLING_BACK;
    runXaResourceRollback();
    status = Status.STATUS_ROLLEDBACK;
    if (connection != null) {
        try {
            connection.rollback();
            connection.close();
        } catch (SQLException sqle) {
            status = Status.STATUS_UNKNOWN;
            throw new SystemException();
        }
    }
    if (synchronizations != null) {
        for (int i = 0; i < synchronizations.size(); i++) {
            Synchronization s = (Synchronization) synchronizations.get(i);
            s.afterCompletion(status);
        }
    }
    // status = Status.STATUS_NO_TRANSACTION;
    jtaTransactionManager.endCurrent(this);
}
Also used : SystemException(javax.transaction.SystemException) SQLException(java.sql.SQLException) Synchronization(javax.transaction.Synchronization)

Example 4 with SystemException

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

the class TransactionManager method manage.

public static void manage(Transactional t) {
    UserTransaction utx = getUtx();
    try {
        utx.begin();
        if (t.joinTransaction) {
            t.em.joinTransaction();
        }
        t.transact();
        utx.commit();
    } catch (Exception e) {
        try {
            utx.rollback();
        } catch (SystemException se) {
            throw new WebApplicationException(se);
        }
        throw new WebApplicationException(e);
    } finally {
        t.em.close();
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) SystemException(javax.transaction.SystemException) WebApplicationException(javax.ws.rs.WebApplicationException) SystemException(javax.transaction.SystemException) WebApplicationException(javax.ws.rs.WebApplicationException) NamingException(javax.naming.NamingException)

Example 5 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)

Aggregations

SystemException (javax.transaction.SystemException)203 Transaction (javax.transaction.Transaction)73 RollbackException (javax.transaction.RollbackException)70 NotSupportedException (javax.transaction.NotSupportedException)46 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)41 HeuristicMixedException (javax.transaction.HeuristicMixedException)38 XAException (javax.transaction.xa.XAException)30 TransactionManager (javax.transaction.TransactionManager)25 UserTransaction (javax.transaction.UserTransaction)23 SQLException (java.sql.SQLException)20 Synchronization (javax.transaction.Synchronization)19 IOException (java.io.IOException)18 InvalidTransactionException (javax.transaction.InvalidTransactionException)17 Test (org.junit.Test)15 NamingException (javax.naming.NamingException)11 XAResource (javax.transaction.xa.XAResource)11 Connection (java.sql.Connection)10 LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)10 JavaEETransaction (com.sun.enterprise.transaction.api.JavaEETransaction)9 EJBException (javax.ejb.EJBException)8