Example usage for javax.transaction.xa XAException XAER_PROTO

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

Introduction

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

Prototype

int XAER_PROTO

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

Click Source Link

Document

Routine was invoked in an inproper context.

Usage

From source file:com.taobao.metamorphosis.server.transaction.Transaction.java

public void prePrepare() throws Exception {
    // Is it ok to call prepare now given the state of the
    // transaction?
    switch (this.state) {
    case START_STATE:
    case IN_USE_STATE:
        break;/*from  ww w.j  a va2 s.c o  m*/
    default:
        final XAException xae = new XAException("Prepare cannot be called now.");
        xae.errorCode = XAException.XAER_PROTO;
        throw xae;
    }
}

From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java

private void illegalStateTransition(final String callName) throws XAException {
    final XAException xae = new XAException("Cannot call " + callName + " now.");
    xae.errorCode = XAException.XAER_PROTO;
    throw xae;/*from  w  ww .j ava  2s  .c  o m*/
}

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

@Override
public void commit(final Xid xid, final boolean onePhase) throws XAException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Commit: " + xid);
    }/*  ww w. j  av  a2 s.  co m*/

    XATransactionId x;
    if (xid == null || this.equals(this.associatedXid, xid)) {
        throw new XAException(XAException.XAER_PROTO);
    } else {
        x = new XATransactionId(xid);
    }

    MetaStatLog.addStat(null, StatConstants.TX_COMMIT);
    this.checkConnectionConnected();
    try {

        // Notify the server that the tx was committed back
        final TransactionInfo info = new TransactionInfo(x, this.sessionId,
                onePhase ? TransactionInfo.TransactionType.COMMIT_ONE_PHASE
                        : TransactionInfo.TransactionType.COMMIT_TWO_PHASE);

        this.syncSendXATxCommand(info);
    } finally {
        this.associatedSession.removeContext(this);
        this.logTxTime();
    }

}

From source file:com.taobao.metamorphosis.server.transaction.XATransaction.java

private void checkForPreparedState(final boolean onePhase) throws XAException {
    if (!onePhase) {
        final XAException xae = new XAException(
                "Cannot do 2 phase commit if the transaction has not been prepared.");
        xae.errorCode = XAException.XAER_PROTO;
        throw xae;
    }//from w ww  .j a  va 2 s  . com
}

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

@Override
public void end(final Xid xid, final int flags) throws XAException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("End: " + xid);
    }/*from  w  ww  . j av a2s  .c om*/

    if (this.isInLocalTransaction()) {
        throw new XAException(XAException.XAER_PROTO);
    }

    if ((flags & (TMSUSPEND | TMFAIL)) != 0) {
        // You can only suspend the associated xid.
        if (!this.equals(this.associatedXid, xid)) {
            throw new XAException(XAException.XAER_PROTO);
        }

        // TODO implement resume?
        this.setXid(null);
    } else if ((flags & TMSUCCESS) == TMSUCCESS) {

        if (this.equals(this.associatedXid, xid)) {
            this.setXid(null);
        }
    } else {
        throw new XAException(XAException.XAER_INVAL);
    }

}

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

@Override
public void forget(final Xid xid) throws XAException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Forget: " + xid);
    }//from  w  w w. j  a v a  2s  . co  m

    XATransactionId x;
    if (xid == null) {
        throw new XAException(XAException.XAER_PROTO);
    }
    if (this.equals(this.associatedXid, xid)) {
        x = (XATransactionId) this.transactionId;
    } else {
        x = new XATransactionId(xid);
    }

    final TransactionInfo info = new TransactionInfo(x, this.sessionId, TransactionInfo.TransactionType.FORGET);
    this.syncSendXATxCommand(info);
}

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

@Override
public int prepare(final Xid xid) throws XAException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Prepare: " + xid);
    }/* w  w  w  .j a  v  a  2 s  . c o  m*/

    XATransactionId x;

    // ???endprepare?associatedXid?null
    if (xid == null || this.equals(this.associatedXid, xid)) {
        throw new XAException(XAException.XAER_PROTO);
    } else {
        x = new XATransactionId(xid);
    }
    MetaStatLog.addStat(null, StatConstants.TX_PREPARE);

    final TransactionInfo info = new TransactionInfo(x, this.sessionId,
            TransactionInfo.TransactionType.PREPARE);

    final BooleanCommand response = this.syncSendXATxCommand(info);
    final int result = Integer.parseInt(response.getErrorMsg());
    if (XAResource.XA_RDONLY == result) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("XA_RDONLY from prepare: " + xid);
        }
    }
    return result;

}

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

@Override
public void rollback(final Xid xid) throws XAException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Rollback: " + xid);
    }// w  w w  .  j a v a  2s. com

    XATransactionId x;
    if (xid == null) {
        throw new XAException(XAException.XAER_PROTO);
    }
    if (this.equals(this.associatedXid, xid)) {
        x = (XATransactionId) this.transactionId;
    } else {
        x = new XATransactionId(xid);
    }
    MetaStatLog.addStat(null, StatConstants.TX_ROLLBACK);
    this.checkConnectionConnected();
    try {

        final TransactionInfo info = new TransactionInfo(x, this.sessionId,
                TransactionInfo.TransactionType.ROLLBACK);
        this.syncSendXATxCommand(info);
    } finally {
        this.associatedSession.removeContext(this);
        this.logTxTime();
    }

}

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);
    }//from ww w. ja va  2s  .com

    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.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 . ja  v  a2 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);
}