Search in sources :

Example 26 with XAException

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

the class ClientXASession method getXAException.

private XAException getXAException(RemoteException e) {
    XAException exception = new XAException("Remote operation failed");
    exception.initCause(e);
    return exception;
}
Also used : XAException(javax.transaction.xa.XAException)

Example 27 with XAException

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

the class XASessionImpl method start.

/**
     * {@inheritDoc}
     * <p>
     * If <code>TMNOFLAGS</code> is specified, we create a new transaction
     * context and associate it with this resource.
     * If <code>TMJOIN</code> is specified, this resource should use the
     * same transaction context as another, already known transaction.
     * If <code>TMRESUME</code> is specified, we should resume work on
     * a transaction context that was suspended earlier.
     * All other flags generate an <code>XAException</code> of type
     * <code>XAER_INVAL</code>
     */
public void start(Xid xid, int flags) throws XAException {
    if (isAssociated()) {
        log.error("Resource already associated with a transaction.");
        throw new XAException(XAException.XAER_PROTO);
    }
    TransactionContext tx = txGlobal.get(xid);
    if (flags == TMNOFLAGS) {
        if (tx != null) {
            throw new XAException(XAException.XAER_DUPID);
        }
        tx = createTransaction(xid);
    } else if (flags == TMJOIN) {
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
    } else if (flags == TMRESUME) {
        if (tx == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
        if (!tx.isSuspended()) {
            log.error("Unable to resume: transaction not suspended.");
            throw new XAException(XAException.XAER_PROTO);
        }
        tx.setSuspended(false);
    } else {
        throw new XAException(XAException.XAER_INVAL);
    }
    associate(tx);
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(org.apache.jackrabbit.data.core.TransactionContext)

Example 28 with XAException

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

the class XASessionImpl method end.

/**
     * {@inheritDoc}
     * <p>
     * If <code>TMSUCCESS</code> is specified, we disassociate this session
     * from the transaction specified.
     * If <code>TMFAIL</code> is specified, we disassociate this session from
     * the transaction specified and mark the transaction rollback only.
     * If <code>TMSUSPEND</code> is specified, we disassociate this session
     * from the transaction specified.
     * All other flags generate an <code>XAException</code> of type
     * <code>XAER_INVAL</code>
     * <p>
     * It is legal for a transaction association to be suspended and then
     * ended (either with <code>TMSUCCESS</code> or <code>TMFAIL</code>)
     * without having been resumed again.
     */
public void end(Xid xid, int flags) throws XAException {
    TransactionContext tx = txGlobal.get(xid);
    if (tx == null) {
        throw new XAException(XAException.XAER_NOTA);
    }
    if (flags == TMSUSPEND) {
        if (!isAssociated()) {
            log.error("Resource not associated with a transaction.");
            throw new XAException(XAException.XAER_PROTO);
        }
        associate(null);
        tx.setSuspended(true);
    } else if (flags == TMFAIL || flags == TMSUCCESS) {
        if (!tx.isSuspended()) {
            if (!isAssociated()) {
                log.error("Resource not associated with a transaction.");
                throw new XAException(XAException.XAER_PROTO);
            }
            associate(null);
        } else {
            tx.setSuspended(false);
        }
    } else {
        throw new XAException(XAException.XAER_INVAL);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionContext(org.apache.jackrabbit.data.core.TransactionContext)

Example 29 with XAException

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

the class UserTransactionImpl method rollback.

/**
     * @see javax.transaction.UserTransaction#rollback
     */
public void rollback() throws IllegalStateException, SecurityException, SystemException {
    if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {
        throw new IllegalStateException("Transaction not active");
    }
    try {
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.end(xid, XAResource.TMFAIL);
        }
        status = Status.STATUS_ROLLING_BACK;
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.rollback(xid);
        }
        status = Status.STATUS_ROLLEDBACK;
    } catch (XAException e) {
        SystemException se = new SystemException("Unable to rollback transaction: XA_ERR=" + e.errorCode);
        se.initCause(e.getCause());
        throw se;
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) Iterator(java.util.Iterator)

Example 30 with XAException

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

the class UserTransactionImpl method commit.

/**
     * @see javax.transaction.UserTransaction#commit
     */
public void commit() throws HeuristicMixedException, HeuristicRollbackException, IllegalStateException, RollbackException, SecurityException, SystemException {
    if (status != Status.STATUS_ACTIVE) {
        throw new IllegalStateException("Transaction not active");
    }
    try {
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.end(xid, XAResource.TMSUCCESS);
        }
        status = Status.STATUS_PREPARING;
        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
            XAResource resource = (XAResource) it.next();
            XidImpl xid = (XidImpl) xaResources.get(resource);
            resource.prepare(xid);
        }
        status = Status.STATUS_PREPARED;
        status = Status.STATUS_COMMITTING;
        if (distributedThreadAccess) {
            Thread distributedThread = new Thread() {

                public void run() {
                    try {
                        for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
                            XAResource resource = (XAResource) it.next();
                            XidImpl xid = (XidImpl) xaResources.get(resource);
                            resource.commit(xid, false);
                        }
                    } catch (Exception e) {
                        throw new RuntimeException(e.getMessage());
                    }
                }
            };
            distributedThread.start();
            distributedThread.join(1000);
            if (distributedThread.isAlive()) {
                throw new SystemException("Commit from different thread but same XID must not block");
            }
        } else {
            for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
                XAResource resource = (XAResource) it.next();
                XidImpl xid = (XidImpl) xaResources.get(resource);
                resource.commit(xid, false);
            }
        }
        status = Status.STATUS_COMMITTED;
    } catch (XAException e) {
        if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
            RollbackException re = new RollbackException("Transaction rolled back: XA_ERR=" + e.errorCode);
            re.initCause(e.getCause());
            throw re;
        } else {
            SystemException se = new SystemException("Unable to commit transaction: XA_ERR=" + e.errorCode);
            se.initCause(e.getCause());
            throw se;
        }
    } catch (InterruptedException e) {
        throw new SystemException("Thread.join() interrupted");
    }
}
Also used : XAResource(javax.transaction.xa.XAResource) XAException(javax.transaction.xa.XAException) SystemException(javax.transaction.SystemException) Iterator(java.util.Iterator) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) XAException(javax.transaction.xa.XAException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

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