Example usage for javax.transaction.xa XAException XA_RBROLLBACK

List of usage examples for javax.transaction.xa XAException XA_RBROLLBACK

Introduction

In this page you can find the example usage for javax.transaction.xa XAException XA_RBROLLBACK.

Prototype

int XA_RBROLLBACK

To view the source code for javax.transaction.xa XAException XA_RBROLLBACK.

Click Source Link

Document

Indicates that the rollback was caused by an unspecified reason.

Usage

From source file:org.apache.hadoop.hbase.client.transactional.JtaXAResource.java

public void commit(final Xid xid, final boolean onePhase) throws XAException {
    LOG.trace("commit [" + xid.toString() + "] " + (onePhase ? "one phase" : "two phase"));
    TransactionState state = xidToTransactionState.remove(xid);
    if (state == null) {
        throw new XAException(XAException.XAER_NOTA);
    }/*from ww w .  ja  v a2  s .  com*/
    try {
        if (onePhase) {
            transactionManager.tryCommit(state);
        } else {
            transactionManager.doCommit(state);
        }
    } catch (CommitUnsuccessfulException e) {
        throw new XAException(XAException.XA_RBROLLBACK);
    } catch (UnsuccessfulDDLException e) {
        throw new XAException(XAException.XA_RBROLLBACK);
    } catch (IOException e) {
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(e);
        throw xae;
    } finally {
        threadLocalTransactionState.remove();
    }

}

From source file:org.apache.slide.common.AbstractXAServiceBase.java

public void commit(Xid xid, boolean onePhase) throws XAException {
    TransactionalResource ts = getTransactionalResource(xid);
    if (ts == null) {
        throw new XAException(XAException.XAER_NOTA);
    }/*from ww  w .  j av a 2s  . co m*/

    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine("Committing transaction branch " + ts);
    }

    if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
        throw new XAException(XAException.XA_RBROLLBACK);
    }

    if (ts.getStatus() != STATUS_PREPARED) {
        if (onePhase) {
            ts.prepare();
        } else {
            throw new XAException(XAException.XAER_PROTO);
        }
    }
    ts.commit();
    setCurrentlyActiveTransactionalResource(null);
    removeActiveTransactionalResource(xid);
    removeSuspendedTransactionalResource(xid);
}

From source file:org.apache.slide.common.AbstractXAServiceBase.java

public int prepare(Xid xid) throws XAException {
    TransactionalResource ts = getTransactionalResource(xid);
    if (ts == null) {
        throw new XAException(XAException.XAER_NOTA);
    }//w  w w .j  a  v a  2  s .c om

    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine("Preparing transaction branch " + ts);
    }

    if (ts.getStatus() == STATUS_MARKED_ROLLBACK) {
        throw new XAException(XAException.XA_RBROLLBACK);
    }

    int result = ts.prepare();
    ts.setStatus(STATUS_PREPARED);
    return result;
}

From source file:org.apache.slide.store.txfile.AbstractTxFileStoreService.java

public synchronized int prepare(Xid xid) throws XAException {
    Object txId = wrap(xid);//  w w w  .  j  a  v  a2 s.c  o  m
    Thread currentThread = Thread.currentThread();
    getLogger().log("Thread " + currentThread + " prepares transaction branch " + txId, getLogChannel(),
            DEBUG_LEVEL);
    try {
        int status = rm.prepareTransaction(txId);
        switch (status) {
        case ResourceManager.PREPARE_SUCCESS_READONLY:
            return XA_RDONLY;
        case ResourceManager.PREPARE_SUCCESS:
            return XA_OK;
        default:
            throw new XAException(XAException.XA_RBROLLBACK);
        }
    } catch (ResourceManagerException e) {
        getLogger().log("Thread " + currentThread + " failed to prepare transaction branch " + txId, e,
                getLogChannel(), Logger.CRITICAL);
        throw createXAException(e);
    }
}

From source file:org.apache.slide.store.txfile.TxXMLFileDescriptorsStore.java

public synchronized int prepare(Xid xid) throws XAException {
    Object txId = wrap(xid);//from w  w w.j a  v  a 2 s  .  com
    getLogger().log("Thread " + Thread.currentThread() + " prepares transaction branch " + txId, LOG_CHANNEL,
            Logger.DEBUG);
    try {
        if (deferSaving) {
            // save all descriptors registered for saving
            TxContext txContext = (TxContext) activeContexts.get(txId);
            if (txContext == null)
                txContext = (TxContext) suspendedContexts.get(txId);
            // really should not, but only to be sure...
            if (txContext != null) {
                try {
                    txContext.saveDescriptors();
                } catch (ObjectNotFoundException onfe) {
                    getLogger().log("Thread " + Thread.currentThread()
                            + " failed to prepare transaction branch " + txId, onfe, LOG_CHANNEL,
                            Logger.CRITICAL);
                    throw new XAException(onfe.toString());
                } catch (ServiceAccessException sae) {
                    getLogger().log("Thread " + Thread.currentThread()
                            + " failed to prepare transaction branch " + txId, sae, LOG_CHANNEL,
                            Logger.CRITICAL);
                    throw new XAException(sae.toString());
                }
            } else {
                getLogger().log("Thread " + Thread.currentThread()
                        + " could prepare *unknown* transaction branch " + txId, LOG_CHANNEL, Logger.WARNING);
            }
        }
        int status = rm.prepareTransaction(txId);
        switch (status) {
        case ResourceManager.PREPARE_SUCCESS_READONLY:
            return XA_RDONLY;
        case ResourceManager.PREPARE_SUCCESS:
            return XA_OK;
        default:
            throw new XAException(XAException.XA_RBROLLBACK);
        }
    } catch (ResourceManagerException e) {
        getLogger().log("Thread " + Thread.currentThread() + " failed to prepare transaction branch " + txId, e,
                LOG_CHANNEL, Logger.CRITICAL);
        throw createXAException(e);
    }
}

From source file:org.mule.util.xa.DefaultXASession.java

public void commit(Xid xid, boolean onePhase) throws XAException {
    if (xid == null) {
        throw new XAException(XAException.XAER_PROTO);
    }/*from  w w  w.  java 2 s  .c o  m*/
    AbstractTransactionContext context = resourceManager.getActiveTransactionalResource(xid);
    if (context == null) {
        throw new XAException(XAException.XAER_NOTA);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Committing transaction branch " + xid);
    }
    if (context.status == Status.STATUS_MARKED_ROLLBACK) {
        throw new XAException(XAException.XA_RBROLLBACK);
    }

    try {
        if (context.status != Status.STATUS_PREPARED) {
            if (onePhase) {
                resourceManager.prepareTransaction(context);
            } else {
                throw new XAException(XAException.XAER_PROTO);
            }
        }
        resourceManager.commitTransaction(context);
    } catch (ResourceManagerException e) {
        throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
    }
    resourceManager.removeActiveTransactionalResource(xid);
    resourceManager.removeSuspendedTransactionalResource(xid);
}

From source file:org.mule.util.xa.DefaultXASession.java

public int prepare(Xid xid) throws XAException {
    if (xid == null) {
        throw new XAException(XAException.XAER_PROTO);
    }/* w  w  w.j  a va 2 s.c  om*/

    AbstractTransactionContext context = resourceManager.getTransactionalResource(xid);
    if (context == null) {
        throw new XAException(XAException.XAER_NOTA);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Preparing transaction branch " + xid);
    }

    if (context.status == Status.STATUS_MARKED_ROLLBACK) {
        throw new XAException(XAException.XA_RBROLLBACK);
    }

    try {
        return resourceManager.prepareTransaction(context);
    } catch (ResourceManagerException e) {
        throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.TestSQLBackend.java

protected static void rollback(Session session, Xid xid) throws XAException {
    XAResource xaresource = ((SessionImpl) session).getXAResource();
    boolean rollback = true;
    try {/* w  w w  .j  a  v  a2s  .c o  m*/
        xaresource.end(xid, XAResource.TMFAIL);
    } catch (XAException e) {
        if (e.errorCode == XAException.XA_RBROLLBACK // Derby
                || e.errorCode == XAException.XA_RBDEADLOCK // Derby
                || e.getMessage().startsWith("XA_RBDEADLOCK") // MySQL
        ) {
            rollback = false;
        } else {
            throw e;
        }
    }
    if (rollback) {
        xaresource.rollback(xid);
    }
}