Search in sources :

Example 11 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException in project graphdb by neo4j-attic.

the class TxManager method rollbackCommit.

private void rollbackCommit(Thread thread, TransactionImpl tx) throws HeuristicMixedException, RollbackException, SystemException {
    try {
        tx.doRollback();
    } catch (XAException e) {
        e.printStackTrace();
        log.severe("Unable to rollback marked transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
        setTmNotOk();
        throw new HeuristicMixedException("Unable to rollback " + " ---> error code for rollback: " + e.errorCode);
    }
    tx.doAfterCompletion();
    txThreadMap.remove(thread);
    try {
        if (tx.isGlobalStartRecordWritten()) {
            getTxLog().txDone(tx.getGlobalId());
        }
    } catch (IOException e) {
        e.printStackTrace();
        log.severe("Error writing transaction log");
        setTmNotOk();
        throw new SystemException("TM encountered a problem, " + " error writing transaction log," + e);
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
    throw new RollbackException("Failed to commit, transaction rolledback");
}
Also used : XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException)

Example 12 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException in project spring-framework by spring-projects.

the class JtaTransactionManagerTests method jtaTransactionManagerWithHeuristicMixedExceptionOnCommit.

@Test
public void jtaTransactionManagerWithHeuristicMixedExceptionOnCommit() throws Exception {
    UserTransaction ut = mock(UserTransaction.class);
    given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
    willThrow(new HeuristicMixedException("heuristic exception")).given(ut).commit();
    try {
        JtaTransactionManager ptm = newJtaTransactionManager(ut);
        TransactionTemplate tt = new TransactionTemplate(ptm);
        tt.execute(new TransactionCallbackWithoutResult() {

            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                // something transactional
                TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {

                    @Override
                    public void afterCompletion(int status) {
                        assertTrue("Correct completion status", status == TransactionSynchronization.STATUS_UNKNOWN);
                    }
                });
            }
        });
        fail("Should have thrown HeuristicCompletionException");
    } catch (HeuristicCompletionException ex) {
        // expected
        assertTrue(ex.getOutcomeState() == HeuristicCompletionException.STATE_MIXED);
    }
    verify(ut).begin();
}
Also used : UserTransaction(javax.transaction.UserTransaction) JtaTransactionManager(org.springframework.transaction.jta.JtaTransactionManager) HeuristicMixedException(javax.transaction.HeuristicMixedException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) TransactionSynchronizationAdapter(org.springframework.transaction.support.TransactionSynchronizationAdapter) Test(org.junit.Test)

Example 13 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException in project galley by Commonjava.

the class FastLocalCacheProvider method copy.

@Override
public void copy(ConcreteResource from, ConcreteResource to) throws IOException {
    final String fromNFSPath = getKeyForResource(from);
    final String toNFSPath = getKeyForResource(to);
    //FIXME: there is no good solution here for thread locking as there are two resource needs to be locked. If handled not correctly, will cause dead lock
    InputStream nfsFrom = null;
    OutputStream nfsTo = null;
    try {
        //FIXME: need to think about this lock of the re-entrant way and ISPN lock wait
        nfsOwnerCache.beginTransaction();
        nfsOwnerCache.lock(fromNFSPath, toNFSPath);
        plCacheProvider.copy(from, to);
        nfsFrom = new FileInputStream(getNFSDetachedFile(from));
        File nfsToFile = getNFSDetachedFile(to);
        if (!nfsToFile.exists() && !nfsToFile.isDirectory()) {
            if (!nfsToFile.getParentFile().exists()) {
                nfsToFile.getParentFile().mkdirs();
            }
            try {
                nfsToFile.createNewFile();
            } catch (IOException e) {
                logger.error("[galley] New nfs file created not properly.", e);
            }
        }
        nfsTo = new FileOutputStream(nfsToFile);
        IOUtils.copy(nfsFrom, nfsTo);
        //FIXME: need to use put?
        nfsOwnerCache.putIfAbsent(toNFSPath, getCurrentNodeIp());
        nfsOwnerCache.commit();
    } catch (NotSupportedException | SystemException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
        logger.error("[galley] Transaction error for nfs cache during file copying.", e);
        try {
            nfsOwnerCache.rollback();
        } catch (SystemException se) {
            final String errorMsg = "[galley] Transaction rollback error for nfs cache during file copying.";
            logger.error(errorMsg, se);
            throw new IllegalStateException(errorMsg, se);
        }
    } finally {
        IOUtils.closeQuietly(nfsFrom);
        IOUtils.closeQuietly(nfsTo);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) FileInputStream(java.io.FileInputStream) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) FileOutputStream(java.io.FileOutputStream) HeuristicMixedException(javax.transaction.HeuristicMixedException) NotSupportedException(javax.transaction.NotSupportedException) File(java.io.File)

Example 14 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException 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)

Aggregations

HeuristicMixedException (javax.transaction.HeuristicMixedException)14 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)12 SystemException (javax.transaction.SystemException)12 RollbackException (javax.transaction.RollbackException)11 XAException (javax.transaction.xa.XAException)6 IOException (java.io.IOException)5 NotSupportedException (javax.transaction.NotSupportedException)5 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 InvalidTransactionException (javax.transaction.InvalidTransactionException)2 Transaction (javax.transaction.Transaction)2 XAResource (javax.transaction.xa.XAResource)2 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)2 TransactionException (io.requery.TransactionException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 SQLException (java.sql.SQLException)1