Example usage for javax.transaction.xa XAException XAER_NOTA

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

Introduction

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

Prototype

int XAER_NOTA

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

Click Source Link

Document

The XID is not valid.

Usage

From source file:com.alibaba.napoli.metamorphosis.client.transaction.TransactionContext.java

@Override
public void start(final Xid xid, final int flags) throws XAException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Start: " + xid);
    }/*  w  w  w.  ja  va2  s. c om*/

    if ((flags & TMJOIN) == TMJOIN || (flags & TMRESUME) == TMRESUME) {
        // resumexid?xid
        if (!this.equals(this.associatedXid, xid)) {
            throw new XAException(XAException.XAER_NOTA);
        }
    }

    if (this.isInLocalTransaction()) {
        throw new XAException(XAException.XAER_PROTO);
    }
    if (this.associatedXid != null) {
        throw new XAException(XAException.XAER_DUPID);
    }
    this.setXid(xid);
}

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  www.  j a  v  a  2 s.  co m*/
    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 forget(Xid xid) throws XAException {
    if (getLoggerFacade().isFineEnabled()) {
        getLoggerFacade().logFine("Forgetting transaction branch " + xid);
    }// www.j  a  v  a2 s . 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);
    }/*from   www  .  j av  a 2  s .com*/

    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 .  jav  a  2 s .  c o  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 ava2 s .  co  m

    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);
    }//w w  w.j  av a2 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 w ww.  j a v  a2 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);
    }/*from w ww  . ja  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.txfile.AbstractTxFileStoreService.java

protected XAException createXAException(ResourceManagerException e) {
    if (e.getStatus() == ResourceManagerException.ERR_DUP_TX) {
        return new XAException(XAException.XAER_DUPID);
    } else if (e.getStatus() == ResourceManagerException.ERR_TXID_INVALID) {
        return new XAException(XAException.XAER_NOTA);
    } else {//from   ww w  .jav a 2s  .c o m
        return new XAException(e.toString());
    }
}