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);
}
}
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);
}
}
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");
}
}
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);
}
}
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);
}
}
Aggregations