Example usage for javax.transaction.xa XAException XAException

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

Introduction

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

Prototype

public XAException(int errcode) 

Source Link

Document

Create an XAException with a given error code.

Usage

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

public int prepare(final Xid xid) throws XAException {
    LOG.trace("prepare [" + xid.toString() + "] ");
    TransactionState state = xidToTransactionState.get(xid);
    int status;/*from   w w w  . j  a v  a 2 s . c om*/
    try {
        status = this.transactionManager.prepareCommit(state);
    } catch (CommitUnsuccessfulException e) {
        XAException xae = new XAException(XAException.XA_HEURRB);
        xae.initCause(e);
        throw xae;
    } catch (IOException e) {
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(e);
        throw xae;
    }

    switch (status) {
    case TransactionalReturn.COMMIT_OK:
        return XAResource.XA_OK;
    case TransactionalReturn.COMMIT_OK_READ_ONLY:
        return XAResource.XA_RDONLY;
    default:
        throw new XAException(XAException.XA_RBPROTO);
    }
}

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

public void forget(Xid xid) throws XAException {
    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine("Forgetting transaction branch " + xid);
    }/*from w  w  w  .  j  ava 2s .co  m*/
    TransactionalResource ts = getTransactionalResource(xid);
    if (ts == null) {
        throw new XAException(XAException.XAER_NOTA);
    }
    setCurrentlyActiveTransactionalResource(null);
    removeActiveTransactionalResource(xid);
    removeSuspendedTransactionalResource(xid);
}

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);
    }//  w w  w. j av a  2  s. c  o 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 void rollback(Xid xid) throws XAException {
    TransactionalResource ts = getTransactionalResource(xid);

    if (ts == null) {
        setCurrentlyActiveTransactionalResource(null);
        throw new XAException(XAException.XAER_NOTA);
    }/*  w  w  w  .  j  a va 2 s  . co  m*/

    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine("Rolling back transaction branch " + ts);
    }
    try {
        ts.rollback();
    } finally {
        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  ww .j ava  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.common.AbstractXAServiceBase.java

public void end(Xid xid, int flags) throws XAException {
    TransactionalResource ts = getActiveTransactionalResource(xid);
    if (ts == null) {
        setCurrentlyActiveTransactionalResource(null);
        throw new XAException(XAException.XAER_NOTA);
    }/*from w  ww  .ja  v  a 2 s . co  m*/
    if (getCurrentlyActiveTransactionalResource() == null) {
        throw new XAException(XAException.XAER_INVAL);
    }
    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine(new StringBuffer(128).append("Thread ").append(Thread.currentThread())
                .append(flags == TMSUSPEND ? " suspends" : flags == TMFAIL ? " fails" : " ends")
                .append(" work on behalf of transaction branch ").append(ts).toString());
    }

    switch (flags) {
    case TMSUSPEND:
        ts.suspend();
        addSuspendedTransactionalResource(xid, ts);
        removeActiveTransactionalResource(xid);
        break;
    case TMFAIL:
        ts.setStatus(STATUS_MARKED_ROLLBACK);
        break;
    case TMSUCCESS:
        break;
    }
    setCurrentlyActiveTransactionalResource(null);
}

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

public void start(Xid xid, int flags) throws XAException {
    if (getCurrentlyActiveTransactionalResource() != null) {
        throw new XAException(XAException.XAER_INVAL);
    }//from  ww w  . j  a v a  2  s  .c o m
    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine(new StringBuffer(128).append("Thread ").append(Thread.currentThread())
                .append(flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes")
                .append(" work on behalf of transaction branch ").append(xid).toString());
    }

    TransactionalResource ts;
    switch (flags) {
    // a new transaction
    case TMNOFLAGS:
    case TMJOIN:
    default:
        try {
            ts = createTransactionResource(xid);
            ts.begin();
        } catch (Exception e) {
            getLoggerFacade().logSevere("Could not create new transactional  resource", e);
            throw new XAException(e.getMessage());
        }
        break;
    case TMRESUME:
        ts = getSuspendedTransactionalResource(xid);
        if (ts == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
        ts.resume();
        removeSuspendedTransactionalResource(xid);
        break;
    }
    setCurrentlyActiveTransactionalResource(ts);
    addAcitveTransactionalResource(xid, ts);
}

From source file:org.apache.slide.store.impl.rdbms.AbstractRDBMSStore.java

public void start(Xid xid, int flags) throws XAException {
    TransactionalResource resource = getCurrentlyActiveTransactionalResource();
    if (resource != null) {
        throw new XAException(XAException.XAER_INVAL);
    }/*  w ww  .  j  av a2s  . c  o  m*/
    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine(new StringBuffer(128).append("Thread ").append(Thread.currentThread())
                .append(flags == TMNOFLAGS ? " starts" : flags == TMJOIN ? " joins" : " resumes")
                .append(" work on behalf of transaction branch ").append(xid).toString());
    }

    TransactionalResource ts;
    switch (flags) {
    // a new transaction
    case TMNOFLAGS:
    case TMJOIN:
    default:
        try {
            ts = createTransactionResource(xid);
            ts.begin();
        } catch (Exception e) {
            getLoggerFacade().logSevere("Could not create new transactional  resource", e);
            throw new XAException(e.getMessage());
        }
        break;
    case TMRESUME:
        ts = getSuspendedTransactionalResource(xid);
        if (ts == null) {
            throw new XAException(XAException.XAER_NOTA);
        }
        ts.resume();
        removeSuspendedTransactionalResource(xid);
        break;
    }
    setCurrentlyActiveTransactionalResource(ts);
    addAcitveTransactionalResource(xid, ts);
}

From source file:org.apache.slide.store.mem.AbstractTransientStore.java

public void commit(Xid xid, boolean onePhase) throws XAException {
    debug("commit {0} {1}", xid, onePhase ? "true" : "false");
    try {/* w  w w.ja v a2  s .  c o  m*/
        this.xaResource.commit(xid, onePhase);
    } catch (ConflictException e) {
        this.xaResource.rollback(xid);
        // TODO it would be great if we could throw something
        // that would (on the webdav layer) leads to a 409 Conflict
        // instead of 500 Internal Server Error
        throw new XAException(XAException.XA_RBOTHER); // ??
    }
}

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

public synchronized int prepare(Xid xid) throws XAException {
    Object txId = wrap(xid);//from   w w w . java2 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);
    }
}