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:com.taobao.metamorphosis.server.transaction.XATransaction.java

private void doPrePrepare() throws XAException, IOException {
    try {/*from  ww w .ja  v  a2  s .c  o  m*/
        this.prePrepare();
    } catch (final XAException e) {
        throw e;
    } catch (final Throwable e) {
        LOG.warn("PRE-PREPARE FAILED: ", e);
        this.rollback();
        final XAException xae = new XAException("PRE-PREPARE FAILED: Transaction rolled back.");
        xae.errorCode = XAException.XA_RBOTHER;
        xae.initCause(e);
        throw xae;
    }
}

From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java

public int prepare(Xid xid) throws XAException {

    InputStream is = null;//  w w w  .  j  a  v  a 2  s.c  o m
    try {
        if (file.exists()) {
            is = new FileInputStream(file);
            byte[] data = new byte[is.available()];
            is.read(data);
            oldDataMapping.put(xid, data);
        } else {
            oldDataMapping.put(xid, null);
        }
    } catch (Exception e) {
        log.error("", e);
        throw new XAException(XAException.XA_RBBASE);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
    return XA_OK;
}

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

private void checkConnectionConnected() throws XAException {
    if (!this.remotingClient.isConnected(this.serverUrl)) {
        throw new XAException(XAException.XAER_RMFAIL);
    }//from   w w  w  .j  ava  2  s. co m
}

From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java

public void rollback(Xid xid) throws XAException {
    byte[] data = oldDataMapping.get(xid);
    OutputStream os = null;//  w  w  w .java2  s .  c  o  m
    try {
        if (data == null) {
            file.deleteOnExit();
        } else {
            os = new FileOutputStream(file);
            os.write(data);
        }
    } catch (Exception e) {
        throw new XAException(XAException.XA_HEURHAZ);
    } finally {
        lockedXid = null;
        if (os != null) {
            try {
                os.close();
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }

}

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);
    }/* ww w .j  ava  2s. 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.taobao.metamorphosis.server.transaction.XATransaction.java

@Override
public void rollback() throws XAException, IOException {

    if (LOG.isDebugEnabled()) {
        LOG.debug("XA Transaction rollback: " + this.xid);
    }//w w w.  jav  a  2s  . c  om

    switch (this.getState()) {
    case START_STATE:
        // 1 phase rollback no work done.
        this.setStateFinished();
        break;
    case IN_USE_STATE:
        // 1 phase rollback work done.
        this.setStateFinished();
        this.transactionStore.rollback(this.getTransactionId());
        break;
    case PREPARED_STATE:
        // 2 phase rollback work done.
        this.setStateFinished();
        this.transactionStore.rollback(this.getTransactionId());
        break;
    case FINISHED_STATE:
        // failure to commit
        this.transactionStore.rollback(this.getTransactionId());
        break;
    default:
        throw new XAException("Invalid state");
    }

}

From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java

public int prepare(Xid xid) throws XAException {
    InputStream is = null;//ww  w.ja va2 s .  com
    try {
        for (File f : modifiedDataMapping.get(xid).keySet()) {
            if (f.exists()) {
                is = new FileInputStream(f);
                byte[] data = new byte[is.available()];
                is.read(data);
                oldDataMapping.get(xid).put(f, data);
            } else {
                oldDataMapping.get(xid).put(f, null);
            }
        }
    } catch (Exception e) {
        log.error("", e);
        throw new XAException(XAException.XA_RBBASE);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
    return XA_OK;
}

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);
    }/*  w w  w  . j  a v  a 2 s.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.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java

public void rollback(Xid xid) throws XAException {
    for (File file : oldDataMapping.get(xid).keySet()) {
        OutputStream os = null;//  www.jav a 2s .co  m
        try {
            byte[] data = oldDataMapping.get(xid).get(file);
            if (data != null) {
                os = new FileOutputStream(file);
                os.write(oldDataMapping.get(xid).get(file));
            } else {
                file.deleteOnExit();
            }
        } catch (Exception e) {
            throw new XAException(XAException.XA_HEURHAZ);
        } finally {
            if (os != null) {
                try {
                    os.close();
                } catch (Exception e) {
                    log.error("", e);
                }
            }
            lockedXid = null;
            modifiedDataMapping.remove(xid);
            oldDataMapping.remove(xid);
        }
    }
}

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

@Override
public boolean isSameRM(final XAResource xaResource) throws XAException {
    if (xaResource == null) {
        return false;
    }/*  ww w.jav  a2s.  c  om*/
    if (!(xaResource instanceof TransactionContext)) {
        return false;
    }
    final TransactionContext xar = (TransactionContext) xaResource;
    try {
        return this.getResourceManagerId().equals(xar.getResourceManagerId());
    } catch (final Throwable e) {
        throw (XAException) new XAException("Could not get resource manager id.").initCause(e);
    }
}