Search in sources :

Example 1 with HeuristicMixedException

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

the class TxManager method commit.

private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
    // mark as commit in log done TxImpl.doCommit()
    Throwable commitFailureCause = null;
    int xaErrorCode = -1;
    if (tx.getResourceCount() == 0) {
        tx.setStatus(Status.STATUS_COMMITTED);
    } else {
        try {
            tx.doCommit();
        } catch (XAException e) {
            xaErrorCode = e.errorCode;
            e.printStackTrace();
            log.severe("Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode);
            if (tx.getStatus() == Status.STATUS_COMMITTED) {
                // this should never be
                setTmNotOk();
                throw new TransactionFailureException("commit threw exception but status is committed?", e);
            }
        } catch (Throwable t) {
            t.printStackTrace();
            commitFailureCause = t;
        }
    }
    if (tx.getStatus() != Status.STATUS_COMMITTED) {
        try {
            tx.doRollback();
        } catch (XAException e) {
            e.printStackTrace();
            log.severe("Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->");
            setTmNotOk();
            if (commitFailureCause != null) {
                commitFailureCause.printStackTrace();
            }
            throw new HeuristicMixedException("Unable to rollback ---> error code in commit: " + xaErrorCode + " ---> 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);
        if (commitFailureCause == null) {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode);
        } else {
            throw new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause);
        }
    }
    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);
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException)

Example 2 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException in project neo4j-mobile-android by neo4j-contrib.

the class TxManager method commit.

private void commit(Thread thread, TransactionImpl tx) throws SystemException, HeuristicMixedException, HeuristicRollbackException {
    // mark as commit in log done TxImpl.doCommit()
    Throwable commitFailureCause = null;
    int xaErrorCode = -1;
    if (tx.getResourceCount() == 0) {
        tx.setStatus(Status.STATUS_COMMITTED);
    } else {
        try {
            tx.doCommit();
        } catch (XAException e) {
            xaErrorCode = e.errorCode;
            log.log(Level.SEVERE, "Commit failed, status=" + getTxStatusAsString(tx.getStatus()) + ", errorCode=" + xaErrorCode, e);
            if (tx.getStatus() == Status.STATUS_COMMITTED) {
                // this should never be
                setTmNotOk(e);
                throw logAndReturn("TM error tx commit", new TransactionFailureException("commit threw exception but status is committed?", e));
            }
        } catch (Throwable t) {
            log.log(Level.SEVERE, "Commit failed", t);
            commitFailureCause = t;
        }
    }
    if (tx.getStatus() != Status.STATUS_COMMITTED) {
        try {
            tx.doRollback();
        } catch (Throwable e) {
            log.log(Level.SEVERE, "Unable to rollback transaction. " + "Some resources may be commited others not. " + "Neo4j kernel should be SHUTDOWN for " + "resource maintance and transaction recovery ---->", e);
            setTmNotOk(e);
            String commitError;
            if (commitFailureCause != null) {
                commitError = "error in commit: " + commitFailureCause;
            } else {
                commitError = "error code in commit: " + xaErrorCode;
            }
            String rollbackErrorCode = "Uknown error code";
            if (e instanceof XAException) {
                rollbackErrorCode = Integer.toString(((XAException) e).errorCode);
            }
            throw logAndReturn("TM error tx commit", Exceptions.withCause(new HeuristicMixedException("Unable to rollback ---> " + commitError + " ---> error code for rollback: " + rollbackErrorCode), 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 commit", Exceptions.withCause(new SystemException("TM encountered a problem, " + " error writing transaction log"), e));
        }
        tx.setStatus(Status.STATUS_NO_TRANSACTION);
        if (commitFailureCause == null) {
            throw logAndReturn("TM error tx commit", new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + "error code was: " + xaErrorCode));
        } else {
            throw logAndReturn("TM error tx commit", Exceptions.withCause(new HeuristicRollbackException("Failed to commit, transaction rolledback ---> " + commitFailureCause), commitFailureCause));
        }
    }
    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 commit", Exceptions.withCause(new SystemException("TM encountered a problem, " + " error writing transaction log"), e));
    }
    tx.setStatus(Status.STATUS_NO_TRANSACTION);
}
Also used : TransactionFailureException(org.neo4j.graphdb.TransactionFailureException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) IOException(java.io.IOException)

Example 3 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException in project neo4j-mobile-android by neo4j-contrib.

the class TxManager method rollbackCommit.

private void rollbackCommit(Thread thread, TransactionImpl tx) throws HeuristicMixedException, RollbackException, SystemException {
    try {
        tx.doRollback();
    } catch (XAException e) {
        log.log(Level.SEVERE, "Unable to rollback marked 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 commit", Exceptions.withCause(new HeuristicMixedException("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 commit", Exceptions.withCause(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 4 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException 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();
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) TransactionException(io.requery.TransactionException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException)

Example 5 with HeuristicMixedException

use of javax.transaction.HeuristicMixedException 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);
    }
}
Also used : HeuristicRollbackException(javax.transaction.HeuristicRollbackException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) SystemException(javax.transaction.SystemException) HeuristicMixedException(javax.transaction.HeuristicMixedException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) UnexpectedRollbackException(org.springframework.transaction.UnexpectedRollbackException) HeuristicCompletionException(org.springframework.transaction.HeuristicCompletionException)

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