use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManager method doCommit.
@Override
protected void doCommit(DefaultTransactionStatus status) {
JtaTransactionObject txObject = (JtaTransactionObject) status.getTransaction();
try {
int jtaStatus = txObject.getUserTransaction().getStatus();
if (jtaStatus == Status.STATUS_NO_TRANSACTION) {
// In any case, the transaction is already fully cleaned up.
throw new UnexpectedRollbackException("JTA transaction already completed - probably rolled back");
}
if (jtaStatus == Status.STATUS_ROLLEDBACK) {
// IllegalStateException expected on JBoss; call still necessary.
try {
txObject.getUserTransaction().rollback();
} catch (IllegalStateException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Rollback failure with transaction already marked as rolled back: " + ex);
}
}
throw new UnexpectedRollbackException("JTA transaction already rolled back (probably due to a timeout)");
}
txObject.getUserTransaction().commit();
} catch (RollbackException ex) {
throw new UnexpectedRollbackException("JTA transaction unexpectedly rolled back (maybe due to a timeout)", ex);
} catch (HeuristicMixedException ex) {
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_MIXED, ex);
} catch (HeuristicRollbackException ex) {
throw new HeuristicCompletionException(HeuristicCompletionException.STATE_ROLLED_BACK, ex);
} catch (IllegalStateException ex) {
throw new TransactionSystemException("Unexpected internal transaction state", ex);
} catch (SystemException ex) {
throw new TransactionSystemException("JTA failure on commit", ex);
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithSystemExceptionOnBegin.
@Test
public void jtaTransactionManagerWithSystemExceptionOnBegin() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION);
willThrow(new SystemException("system exception")).given(ut).begin();
try {
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
}
});
fail("Should have thrown CannotCreateTransactionException");
} catch (CannotCreateTransactionException ex) {
// expected
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException.
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithBeginException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
given(tm.suspend()).willReturn(tx);
willThrow(new SystemException()).given(ut).begin();
JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
}
});
fail("Should have thrown CannotCreateTransactionException");
} catch (CannotCreateTransactionException ex) {
// expected
}
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(tm).resume(tx);
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithSystemExceptionOnIsExisting.
@Test
public void jtaTransactionManagerWithSystemExceptionOnIsExisting() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
given(ut.getStatus()).willThrow(new SystemException("system exception"));
try {
JtaTransactionManager ptm = newJtaTransactionManager(ut);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// something transactional
}
});
fail("Should have thrown TransactionSystemException");
} catch (TransactionSystemException ex) {
// expected
}
}
use of javax.transaction.SystemException in project blueprints by tinkerpop.
the class Neo4jGraph method rollback.
public void rollback() {
if (null == tx.get()) {
return;
}
GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) getRawGraph();
TransactionManager transactionManager = graphDatabaseAPI.getTxManager();
try {
javax.transaction.Transaction t = transactionManager.getTransaction();
if (t == null || t.getStatus() == Status.STATUS_ROLLEDBACK) {
return;
}
tx.get().failure();
} catch (SystemException e) {
throw new RuntimeException(e);
} finally {
tx.get().finish();
tx.remove();
}
}
Aggregations