Search in sources :

Example 66 with XAException

use of javax.transaction.xa.XAException in project jackrabbit by apache.

the class TransactionContext method prepare.

/**
     * Prepare the transaction identified by this context. Prepares changes on
     * all resources. If some resource reports an error on prepare,
     * automatically rollback changes on all other resources. Throw exception
     * at the end if errors were found.
     *
     * @throws XAException if an error occurs
     */
public synchronized void prepare() throws XAException {
    bindCurrentXid();
    status = STATUS_PREPARING;
    beforeOperation();
    TransactionException txe = null;
    for (int i = 0; i < resources.length; i++) {
        try {
            resources[i].prepare(this);
        } catch (TransactionException e) {
            txe = e;
            break;
        } catch (Exception e) {
            txe = new TransactionException("Error while preparing resource " + resources, e);
            break;
        }
    }
    afterOperation();
    status = STATUS_PREPARED;
    if (txe != null) {
        // force immediate rollback on error.
        try {
            rollback();
        } catch (XAException e) {
        /* ignore */
        }
        XAException e = new XAException(XAException.XA_RBOTHER);
        e.initCause(txe);
        throw e;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XAException(javax.transaction.xa.XAException)

Example 67 with XAException

use of javax.transaction.xa.XAException in project jackrabbit by apache.

the class TransactionContext method commit.

/**
     * Commit the transaction identified by this context. Commits changes on
     * all resources. If some resource reports an error on commit,
     * automatically rollback changes on all other resources. Throw
     * exception at the end if some commit failed.
     *
     * @throws XAException if an error occurs
     */
public synchronized void commit() throws XAException {
    if (status == STATUS_ROLLED_BACK) {
        throw new XAException(XAException.XA_HEURRB);
    }
    boolean heuristicCommit = false;
    bindCurrentXid();
    status = STATUS_COMMITTING;
    beforeOperation();
    TransactionException txe = null;
    for (int i = 0; i < resources.length; i++) {
        InternalXAResource resource = resources[i];
        if (txe != null) {
            try {
                resource.rollback(this);
            } catch (Exception e) {
                log.warn("Unable to rollback changes on " + resource, e);
            }
        } else {
            try {
                resource.commit(this);
                heuristicCommit = true;
            } catch (TransactionException e) {
                txe = e;
            } catch (Exception e) {
                txe = new TransactionException("Error while committing resource " + resource, e);
            }
        }
    }
    afterOperation();
    status = STATUS_COMMITTED;
    cleanCurrentXid();
    if (txe != null) {
        XAException e = null;
        if (heuristicCommit) {
            e = new XAException(XAException.XA_HEURMIX);
        } else {
            e = new XAException(XAException.XA_HEURRB);
        }
        e.initCause(txe);
        throw e;
    }
}
Also used : XAException(javax.transaction.xa.XAException) XAException(javax.transaction.xa.XAException)

Example 68 with XAException

use of javax.transaction.xa.XAException in project jackrabbit by apache.

the class UserTransactionImpl method begin.

/**
     * @see javax.transaction.UserTransaction#begin
     */
public void begin() throws NotSupportedException, SystemException {
    if (status != Status.STATUS_NO_TRANSACTION) {
        throw new IllegalStateException("Transaction already active");
    }
    try {
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.start(xid, XAResource.TMNOFLAGS);
        }
        status = Status.STATUS_ACTIVE;
    } catch (XAException e) {
        throw new SystemException("Unable to begin transaction: " + "XA_ERR=" + e.errorCode);
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) Iterator(java.util.Iterator)

Aggregations

XAException (javax.transaction.xa.XAException)68 IOException (java.io.IOException)20 Xid (javax.transaction.xa.Xid)19 SystemException (javax.transaction.SystemException)14 TransactionContext (com.hazelcast.transaction.TransactionContext)12 RollbackException (javax.transaction.RollbackException)8 XAResource (javax.transaction.xa.XAResource)8 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 Test (org.junit.Test)6 TransactionFailureException (org.neo4j.graphdb.TransactionFailureException)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 HashMap (java.util.HashMap)5 XaResource (org.neo4j.kernel.impl.transaction.xaframework.XaResource)4 ArrayList (java.util.ArrayList)3 InvalidRecordException (org.neo4j.kernel.impl.nioneo.store.InvalidRecordException)3 NodeRecord (org.neo4j.kernel.impl.nioneo.store.NodeRecord)3 PropertyIndexRecord (org.neo4j.kernel.impl.nioneo.store.PropertyIndexRecord)3 PropertyRecord (org.neo4j.kernel.impl.nioneo.store.PropertyRecord)3