Example usage for org.apache.commons.transaction.util.xa TransactionalResource begin

List of usage examples for org.apache.commons.transaction.util.xa TransactionalResource begin

Introduction

In this page you can find the example usage for org.apache.commons.transaction.util.xa TransactionalResource begin.

Prototype

public void begin() throws XAException;

Source Link

Usage

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  w  w. j a  v a 2s . 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 w  w .j av  a2 s .com
    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);
}