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