use of javax.transaction.NotSupportedException in project graphdb by neo4j-attic.
the class TestJtaCompliance method testNestedTransactions.
/**
* o Tests if nested transactions are supported
*
* TODO: if supported, do some testing :)
*/
@Test
public void testNestedTransactions() throws Exception {
assertTrue(tm.getTransaction() == null);
tm.begin();
Transaction txParent = tm.getTransaction();
assertTrue(txParent != null);
try {
tm.begin();
// ok supported
// some tests that might be valid for true nested support
// Transaction txChild = tm.getTransaction();
// assertTrue( txChild != txParent );
// tm.commit();
// assertTrue( txParent == tm.getTransaction() );
} catch (NotSupportedException e) {
// well no nested transactions
}
tm.commit();
assertTrue(tm.getStatus() == Status.STATUS_NO_TRANSACTION);
}
use of javax.transaction.NotSupportedException in project aries by apache.
the class TxDBServlet method insertIntoTransaction.
/**
* This method demonstrates how to enlist JDBC connection into Transaction according OSGi enterprise specification.
*
* @param xads XADataSource
* @param tm TransactionManager
* @param value which will be inserted into table
* @param toCommit Specify if the transaction will be committed or rolledback
* @throws SQLException
* @throws GenericJTAException
*/
private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException {
XAConnection xaConnection = xads.getXAConnection();
Connection connection = xaConnection.getConnection();
XAResource xaResource = xaConnection.getXAResource();
try {
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
insertStatement.setString(1, value);
insertStatement.executeUpdate();
if (toCommit) {
transaction.commit();
} else {
transaction.rollback();
}
} catch (RollbackException e) {
throw new GenericJTAException(e);
} catch (SecurityException e) {
throw new GenericJTAException(e);
} catch (IllegalStateException e) {
throw new GenericJTAException(e);
} catch (HeuristicMixedException e) {
throw new GenericJTAException(e);
} catch (HeuristicRollbackException e) {
throw new GenericJTAException(e);
} catch (SystemException e) {
throw new GenericJTAException(e);
} catch (NotSupportedException e) {
throw new GenericJTAException(e);
}
}
use of javax.transaction.NotSupportedException in project partyline by Commonjava.
the class InfinispanJFS method updateDominantLocks.
@Override
public void updateDominantLocks(String path, UnlockStatus unlockStatus) {
// Do nothing if dominance did not change
if (!unlockStatus.isDominanceChanged()) {
return;
}
TransactionManager transactionManager = metadataCache.getAdvancedCache().getTransactionManager();
try {
transactionManager.begin();
FileMeta meta = metadataCache.get(path);
if (unlockStatus.getDominantLockLevel() == null) {
meta.removeLock(this.nodeKey);
} else {
meta.setLock(this.nodeKey, unlockStatus.getDominantLockLevel());
}
metadataCache.put(path, meta);
} catch (NotSupportedException | SystemException e) {
try {
transactionManager.rollback();
} catch (SystemException e1) {
LoggerFactory.getLogger(getClass().getName()).error("System Exception during transaction rollback involving path: " + path, e1);
}
} finally {
try {
transactionManager.commit();
} catch (RollbackException | HeuristicMixedException | HeuristicRollbackException | SystemException e) {
LoggerFactory.getLogger(getClass().getName()).error("Exception during transaction commit involving path: " + path, e);
}
}
}
Aggregations