use of javax.transaction.SystemException in project neo4j-mobile-android by neo4j-contrib.
the class TxManager method rollback.
public void rollback() throws IllegalStateException, SystemException {
assertTmOk("tx rollback");
Thread thread = Thread.currentThread();
TransactionImpl tx = txThreadMap.get(thread);
if (tx == null) {
throw new IllegalStateException("Not in transaction");
}
boolean hasAnyLocks = false;
try {
hasAnyLocks = finishHook.hasAnyLocks(tx);
if (tx.getStatus() == Status.STATUS_ACTIVE || tx.getStatus() == Status.STATUS_MARKED_ROLLBACK || tx.getStatus() == Status.STATUS_PREPARING) {
tx.setStatus(Status.STATUS_MARKED_ROLLBACK);
tx.doBeforeCompletion();
// delist resources?
try {
rolledBackTxCount.incrementAndGet();
tx.doRollback();
} catch (XAException e) {
log.log(Level.SEVERE, "Unable to rollback marked or active transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->", e);
setTmNotOk(e);
throw logAndReturn("TM error tx rollback", Exceptions.withCause(new SystemException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode), e));
}
tx.doAfterCompletion();
txThreadMap.remove(thread);
try {
if (tx.isGlobalStartRecordWritten()) {
getTxLog().txDone(tx.getGlobalId());
}
} catch (IOException e) {
log.log(Level.SEVERE, "Error writing transaction log", e);
setTmNotOk(e);
throw logAndReturn("TM error tx rollback", Exceptions.withCause(new SystemException("TM encountered a problem, " + " error writing transaction log"), e));
}
tx.setStatus(Status.STATUS_NO_TRANSACTION);
} else {
throw new IllegalStateException("Tx status is: " + getTxStatusAsString(tx.getStatus()));
}
} finally {
if (hasAnyLocks) {
finishHook.finishTransaction(tx.getEventIdentifier(), false);
}
}
}
use of javax.transaction.SystemException in project neo4j-mobile-android by neo4j-contrib.
the class PersistenceManager method delistResourcesForTransaction.
void delistResourcesForTransaction() throws NotInTransactionException {
Transaction tx = this.getCurrentTransaction();
if (tx == null) {
throw new NotInTransactionException();
}
NeoStoreTransaction con = txConnectionMap.get(tx);
if (con != null) {
try {
tx.delistResource(con.getXAResource(), XAResource.TMSUCCESS);
} catch (SystemException e) {
throw new TransactionFailureException("Failed to delist resource '" + con + "' from current transaction.", e);
}
}
}
use of javax.transaction.SystemException in project requery by requery.
the class ManagedTransaction method commit.
@Override
public void commit() {
if (initiatedTransaction) {
try {
transactionListener.beforeCommit(entities.types());
getUserTransaction().commit();
transactionListener.afterCommit(entities.types());
} catch (RollbackException | SystemException | HeuristicMixedException | HeuristicRollbackException e) {
throw new TransactionException(e);
}
}
try {
entities.clear();
} finally {
close();
}
}
use of javax.transaction.SystemException in project requery by requery.
the class ManagedTransaction method rollback.
@Override
public void rollback() {
if (!rolledBack) {
try {
if (!completed) {
transactionListener.beforeRollback(entities.types());
if (initiatedTransaction) {
try {
getUserTransaction().rollback();
} catch (SystemException e) {
throw new TransactionException(e);
}
} else if (active()) {
getSynchronizationRegistry().setRollbackOnly();
}
transactionListener.afterRollback(entities.types());
}
} finally {
rolledBack = true;
entities.clearAndInvalidate();
}
}
}
use of javax.transaction.SystemException in project spring-framework by spring-projects.
the class DataSourceJtaTransactionTests method doTestJtaTransactionWithPropagationRequiresNewAndBeginException.
private void doTestJtaTransactionWithPropagationRequiresNewAndBeginException(boolean suspendException, final boolean openOuterConnection, final boolean useTransactionAwareDataSource) throws Exception {
given(userTransaction.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
if (suspendException) {
given(transactionManager.suspend()).willThrow(new SystemException());
} else {
given(transactionManager.suspend()).willReturn(transaction);
willThrow(new SystemException()).given(userTransaction).begin();
}
given(connection.isReadOnly()).willReturn(true);
final DataSource dsToUse = useTransactionAwareDataSource ? new TransactionAwareDataSourceProxy(dataSource) : dataSource;
if (dsToUse instanceof TransactionAwareDataSourceProxy) {
((TransactionAwareDataSourceProxy) dsToUse).setReobtainTransactionalConnections(true);
}
JtaTransactionManager ptm = new JtaTransactionManager(userTransaction, transactionManager);
final TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Is new transaction", status.isNewTransaction());
Connection c = DataSourceUtils.getConnection(dsToUse);
try {
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
c.isReadOnly();
DataSourceUtils.releaseConnection(c, dsToUse);
c = DataSourceUtils.getConnection(dsToUse);
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
if (!openOuterConnection) {
DataSourceUtils.releaseConnection(c, dsToUse);
}
} catch (SQLException ex) {
}
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException {
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
assertTrue("Is new transaction", status.isNewTransaction());
Connection c = DataSourceUtils.getConnection(dsToUse);
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
DataSourceUtils.releaseConnection(c, dsToUse);
c = DataSourceUtils.getConnection(dsToUse);
assertTrue("Has thread connection", TransactionSynchronizationManager.hasResource(dsToUse));
DataSourceUtils.releaseConnection(c, dsToUse);
}
});
} finally {
if (openOuterConnection) {
try {
c.isReadOnly();
DataSourceUtils.releaseConnection(c, dsToUse);
} catch (SQLException ex) {
}
}
}
}
});
fail("Should have thrown TransactionException");
} catch (TransactionException ex) {
// expected
}
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
verify(userTransaction).begin();
if (suspendException) {
verify(userTransaction).rollback();
}
if (suspendException) {
verify(connection, atLeastOnce()).close();
} else {
verify(connection, never()).close();
}
}
Aggregations