Search in sources :

Example 1 with NotSupportedException

use of javax.transaction.NotSupportedException 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 2 with NotSupportedException

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

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

the class TxnTimeOutDUnitTest method runTest3.

public static void runTest3(Object o) throws SystemException, NotSupportedException, NamingException, InterruptedException {
    boolean exceptionOccurred = false;
    int sleeptime = ((Integer) o).intValue();
    Context ctx = cache.getJNDIContext();
    UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
    utx.begin();
    utx.setTransactionTimeout(sleeptime);
    Thread.sleep(sleeptime * 2000);
    try {
        utx.commit();
    } catch (Exception e) {
        exceptionOccurred = true;
    }
    if (!exceptionOccurred) {
        fail("exception did not occur although was supposed to occur");
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) NamingException(javax.naming.NamingException) IOException(java.io.IOException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 4 with NotSupportedException

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

the class TransactionManagerImpl method begin.

/**
   * Create a new transaction and associate it with the current thread if none exists with the
   * current thread else throw an exception since nested transactions are not supported
   * 
   * Create a global transaction and associate the transaction created with the global transaction
   * 
   * @throws NotSupportedException - Thrown if the thread is already associated with a transaction
   *         and the Transaction Manager implementation does not support nested transactions.
   * @throws SystemException - Thrown if the transaction manager encounters an unexpected error
   *         condition.
   * 
   * @see javax.transaction.TransactionManager#begin()
   */
public void begin() throws NotSupportedException, SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    LogWriterI18n log = TransactionUtils.getLogWriterI18n();
    if (log.fineEnabled()) {
        log.fine("TransactionManager.begin() invoked");
    }
    Thread thread = Thread.currentThread();
    if (transactionMap.get(thread) != null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_BEGIN_NESTED_TRANSACTION_IS_NOT_SUPPORTED.toLocalizedString();
        if (VERBOSE)
            log.fine(exception);
        throw new NotSupportedException(exception);
    }
    try {
        TransactionImpl transaction = new TransactionImpl();
        transactionMap.put(thread, transaction);
        GlobalTransaction globalTransaction = new GlobalTransaction();
        globalTransactionMap.put(transaction, globalTransaction);
        globalTransaction.addTransaction(transaction);
        globalTransaction.setStatus(Status.STATUS_ACTIVE);
    } catch (Exception e) {
        String exception = LocalizedStrings.TransactionManagerImpl_BEGIN__SYSTEMEXCEPTION_DUE_TO_0.toLocalizedString(new Object[] { e });
        if (log.severeEnabled())
            log.severe(LocalizedStrings.TransactionManagerImpl_BEGIN__SYSTEMEXCEPTION_DUE_TO_0, new Object[] { e });
        throw new SystemException(exception);
    }
}
Also used : SystemException(javax.transaction.SystemException) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) NotSupportedException(javax.transaction.NotSupportedException) 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 5 with NotSupportedException

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

the class JtaIsolationDelegate method doInNewTransaction.

private <T> T doInNewTransaction(HibernateCallable<T> callable, TransactionManager transactionManager) {
    try {
        // start the new isolated transaction
        transactionManager.begin();
        try {
            T result = callable.call();
            // if everything went ok, commit the isolated transaction
            transactionManager.commit();
            return result;
        } catch (Exception e) {
            try {
                transactionManager.rollback();
            } catch (Exception ignore) {
                LOG.unableToRollbackIsolatedTransaction(e, ignore);
            }
            throw new HibernateException("Could not apply work", e);
        }
    } catch (SystemException e) {
        throw new HibernateException("Unable to start isolated transaction", e);
    } catch (NotSupportedException e) {
        throw new HibernateException("Unable to start isolated transaction", e);
    }
}
Also used : SystemException(javax.transaction.SystemException) HibernateException(org.hibernate.HibernateException) NotSupportedException(javax.transaction.NotSupportedException) NotSupportedException(javax.transaction.NotSupportedException) SQLException(java.sql.SQLException) SystemException(javax.transaction.SystemException) HibernateException(org.hibernate.HibernateException)

Aggregations

NotSupportedException (javax.transaction.NotSupportedException)51 SystemException (javax.transaction.SystemException)39 RollbackException (javax.transaction.RollbackException)19 HeuristicMixedException (javax.transaction.HeuristicMixedException)17 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)17 Transaction (javax.transaction.Transaction)17 UserTransaction (javax.transaction.UserTransaction)11 SQLException (java.sql.SQLException)8 TransactionManager (javax.transaction.TransactionManager)8 NamingException (javax.naming.NamingException)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 InvalidTransactionException (javax.transaction.InvalidTransactionException)5 Connection (java.sql.Connection)4 GeneralException (org.apache.openjpa.util.GeneralException)4 File (java.io.File)3 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2