Example usage for javax.transaction.xa XAResource TMFAIL

List of usage examples for javax.transaction.xa XAResource TMFAIL

Introduction

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

Prototype

int TMFAIL

To view the source code for javax.transaction.xa XAResource TMFAIL.

Click Source Link

Document

Disassociates the caller and marks the transaction branch rollback-only.

Usage

From source file:org.apache.synapse.commons.transaction.TranscationManger.java

public static void rollbackTransaction(boolean insideSynapse, long key) throws Exception {
    int xaResourceStatus = XAResource.TMFAIL;
    try {/*from w ww  .  jav  a2 s. co  m*/
        if (log.isDebugEnabled()) {
            log.debug("rollbackTransaction()");
        }

        if (insideSynapse && transactions.get() == null) {
            log.warn(" ROLLBACK Thread Local null ");
            return;
        }

        if (insideSynapse && transactions.get().get(key) == null) {
            log.warn(" ROLLBACK Some How TX null ");
            return;
        }

        if (transactions.get().get(key) != null
                && javax.transaction.Status.STATUS_ACTIVE == transactions.get().get(key).getStatus()) {
            txManagers.get().get(key).rollback();
            xaResourceStatus = XAResource.TMFAIL;
        }

    } catch (Exception ex) {
        log.error(" ROLLBACK ERROR  : " + txManagers.get().get(key).getStatus());
        throw ex;
    } finally {
        // delist
        delistResource(xaResourceStatus, key);
    }

}

From source file:org.apache.synapse.commons.transaction.TranscationManger.java

public static void endTransaction(boolean insideSynapse, long key) throws Exception {
    int xaResourceStatus = XAResource.TMNOFLAGS;
    try {/*  w  w w . j  a v a2s . co m*/
        if (insideSynapse && transactions.get() == null) {
            log.warn(" END Thread Local null ");
            return;
        }

        if (insideSynapse && transactions.get().get(key) == null) {
            log.warn(" END Some How TX null ");
            return;
        }
        if (transactions.get().get(key) != null
                && javax.transaction.Status.STATUS_ACTIVE == transactions.get().get(key).getStatus()) {
            txManagers.get().get(key).commit();
            xaResourceStatus = XAResource.TMSUCCESS;

        }

    } catch (Exception ex) {
        xaResourceStatus = XAResource.TMFAIL;
        log.error(" END ERROR : " + txManagers.get().get(key).getStatus());
        throw ex;
    } finally {
        // delist
        delistResource(xaResourceStatus, key);
    }

}

From source file:org.eclipse.ecr.core.storage.sql.LockManager.java

/**
 * Calls the callable, inside a transaction if in cluster mode.
 * <p>//from   w ww.ja v a 2s  .  co m
 * Called under {@link #serializationLock}.
 */
protected Lock callInTransaction(Callable<Lock> callable) throws StorageException {
    Xid xid = null;
    boolean txStarted = false;
    boolean txSuccess = false;
    try {
        if (clusteringEnabled) {
            xid = new XidImpl(
                    "nuxeolockmanager." + System.currentTimeMillis() + "." + txCounter.incrementAndGet());
            try {
                mapper.start(xid, XAResource.TMNOFLAGS);
            } catch (XAException e) {
                throw new StorageException(e);
            }
            txStarted = true;
        }
        // else no need to process invalidations,
        // only this mapper writes locks

        // actual call
        Lock result;
        try {
            result = callable.call();
        } catch (StorageException e) {
            throw e;
        } catch (Exception e) {
            throw new StorageException(e);
        }

        txSuccess = true;
        return result;
    } finally {
        if (txStarted) {
            try {
                if (txSuccess) {
                    mapper.end(xid, XAResource.TMSUCCESS);
                    mapper.commit(xid, true);
                } else {
                    mapper.end(xid, XAResource.TMFAIL);
                    mapper.rollback(xid);
                }
            } catch (XAException e) {
                throw new StorageException(e);
            }
        }
    }
}

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

@Override
public void end(Xid xid, int flags) throws XAException {
    try {//w w  w .  j ava 2  s.c o  m
        xaresource.end(xid, flags);
        if (logger.isLogEnabled()) {
            logger.log("XA end on " + systemToString(xid));
        }
    } catch (NullPointerException e) {
        // H2 when no active transaction
        logger.error("XA end error on " + systemToString(xid), e);
        throw (XAException) new XAException(XAException.XAER_RMERR).initCause(e);
    } catch (XAException e) {
        if (flags != XAResource.TMFAIL) {
            logger.error("XA end error on " + systemToString(xid), e);
        }
        throw 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 {//from   ww  w .  java  2  s.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);
    }
}

From source file:org.wso2.andes.client.XASession_9_1.java

/**
 * Send endDtx command to server/* ww w .ja va2s  .c o m*/
 *
 * @param xid  a global transaction identifier to be associated with the resource
 * @param flag one of TMSUCCESS, TMFAIL, or TMSUSPEND.
 * @return XaStatus returned by server
 * @throws FailoverException when a connection issue is detected
 * @throws AMQException      when an error is detected in AMQ state manager
 */
XaStatus endDtx(Xid xid, int flag) throws FailoverException, AMQException, XAException {

    throwErrorIfClosed();

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Sending dtx.end for channel " + _channelId + ", xid " + xid);
    }

    DtxEndBody dtxEndBody = methodRegistry.createDtxEndBody(xid.getFormatId(), xid.getGlobalTransactionId(),
            xid.getBranchQualifier(), flag == XAResource.TMFAIL, flag == XAResource.TMSUSPEND);

    AMQMethodEvent amqMethodEvent = _connection._protocolHandler.syncWrite(dtxEndBody.generateFrame(_channelId),
            DtxEndOkBody.class);

    DtxEndOkBodyImpl response = (DtxEndOkBodyImpl) amqMethodEvent.getMethod();

    return XaStatus.valueOf(response.getXaResult());
}

From source file:org.wso2.carbon.rssmanager.core.dao.util.EntityManager.java

public synchronized void rollbackTransaction() throws RSSManagerException {
    if (log.isDebugEnabled()) {
        log.debug("rollbackTransaction()");
    }/*from   w  ww.  j a v a  2 s.c o  m*/
    if (log.isDebugEnabled()) {
        log.debug("this.getRSSTxManager().rollback()");
    }
    this.delistResource(XAResource.TMFAIL);
    this.getRSSTransactionManager().rollback();
    activeNestedTransactions.set(0);
}