Search in sources :

Example 51 with NotSupportedException

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);
}
Also used : Transaction(javax.transaction.Transaction) NotSupportedException(javax.transaction.NotSupportedException) Test(org.junit.Test)

Example 52 with NotSupportedException

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);
    }
}
Also used : Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) PreparedStatement(java.sql.PreparedStatement) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) XAResource(javax.transaction.xa.XAResource) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) Transaction(javax.transaction.Transaction) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotSupportedException(javax.transaction.NotSupportedException) XAConnection(javax.sql.XAConnection)

Example 53 with NotSupportedException

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);
        }
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotSupportedException(javax.transaction.NotSupportedException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) FileMeta(org.commonjava.util.partyline.impl.infinispan.model.FileMeta)

Aggregations

NotSupportedException (javax.transaction.NotSupportedException)53 SystemException (javax.transaction.SystemException)42 RollbackException (javax.transaction.RollbackException)22 HeuristicMixedException (javax.transaction.HeuristicMixedException)20 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)20 Transaction (javax.transaction.Transaction)17 UserTransaction (javax.transaction.UserTransaction)11 TransactionManager (javax.transaction.TransactionManager)10 SQLException (java.sql.SQLException)8 NamingException (javax.naming.NamingException)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 InvalidTransactionException (javax.transaction.InvalidTransactionException)5 Connection (java.sql.Connection)4 GeneralException (org.apache.openjpa.util.GeneralException)4 File (java.io.File)3 NucleusDataStoreException (org.datanucleus.exceptions.NucleusDataStoreException)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 InputStream (java.io.InputStream)2