Example usage for javax.transaction.xa XAResource TMSUCCESS

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

Introduction

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

Prototype

int TMSUCCESS

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

Click Source Link

Document

Disassociates caller from a transaction branch.

Usage

From source file:org.mule.transport.jms.xa.SessionInvocationHandler.java

public boolean delist() throws Exception {
    if (!isEnlisted()) {
        return false;
    }//w  w  w .ja  v  a  2  s  .  com

    if (logger.isDebugEnabled()) {
        logger.debug("Delistment request: " + this);
    }

    Transaction transaction = TransactionCoordination.getInstance().getTransaction();
    if (transaction == null) {
        throw new IllegalTransactionStateException(CoreMessages.noMuleTransactionAvailable());
    }
    if (!(transaction instanceof XaTransaction)) {
        throw new IllegalTransactionStateException(CoreMessages.notMuleXaTransaction(transaction));
    }

    if (isEnlisted()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Delisting resource " + xaResource + " in xa transaction " + transaction);
        }

        enlisted = !((XaTransaction) transaction).delistResource(xaResource, XAResource.TMSUCCESS);
    }
    return !isEnlisted();
}

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

protected static void commit(Session session, Xid xid) throws XAException {
    XAResource xaresource = ((SessionImpl) session).getXAResource();
    xaresource.end(xid, XAResource.TMSUCCESS);
    xaresource.commit(xid, true);//from www . j a  va 2  s.c o  m
}

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

@Test
public void testRollback() throws Exception {
    if (!DatabaseHelper.DATABASE.supportsXA()) {
        return;//from   w  ww . j  a  v  a 2s .  c  om
    }

    Session session = repository.getConnection();
    XAResource xaresource = ((SessionImpl) session).getXAResource();
    Node root = session.getRootNode();
    Node nodea = session.addChildNode(root, "foo", null, "TestDoc", false);
    nodea.setSimpleProperty("tst:title", "old");
    assertEquals("old", nodea.getSimpleProperty("tst:title").getString());
    session.save();

    /*
     * rollback before save (underlying XAResource saw no updates)
     */
    Xid xid = new XidImpl("11111111111111111111111111111111");
    xaresource.start(xid, XAResource.TMNOFLAGS);
    nodea = session.getNodeByPath("/foo", null);
    nodea.setSimpleProperty("tst:title", "new");
    xaresource.end(xid, XAResource.TMSUCCESS);
    xaresource.prepare(xid);
    xaresource.rollback(xid);
    nodea = session.getNodeByPath("/foo", null);
    assertEquals("old", nodea.getSimpleProperty("tst:title").getString());

    /*
     * rollback after save (underlying XAResource does a rollback too)
     */
    xid = new XidImpl("22222222222222222222222222222222");
    xaresource.start(xid, XAResource.TMNOFLAGS);
    nodea = session.getNodeByPath("/foo", null);
    nodea.setSimpleProperty("tst:title", "new");
    session.save();
    xaresource.end(xid, XAResource.TMSUCCESS);
    xaresource.prepare(xid);
    xaresource.rollback(xid);
    nodea = session.getNodeByPath("/foo", null);
    assertEquals("old", nodea.getSimpleProperty("tst:title").getString());
}

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

@Test
public void testSaveOnCommit() throws Exception {
    if (!DatabaseHelper.DATABASE.supportsXA()) {
        return;/*from ww  w  .  ja  v  a  2  s. co  m*/
    }

    Session session = repository.getConnection(); // init
    session.save();

    XAResource xaresource = ((SessionImpl) session).getXAResource();

    // first transaction
    Xid xid = new XidImpl("11111111111111111111111111111111");
    xaresource.start(xid, XAResource.TMNOFLAGS);
    Node root = session.getRootNode();
    assertNotNull(root);
    session.addChildNode(root, "foo", null, "TestDoc", false);
    // let end do an implicit save
    xaresource.end(xid, XAResource.TMSUCCESS);
    xaresource.prepare(xid);
    xaresource.commit(xid, false);

    // should have saved, clearing caches should be harmless
    ((SessionImpl) session).clearCaches();

    // second transaction
    xid = new XidImpl("22222222222222222222222222222222");
    xaresource.start(xid, XAResource.TMNOFLAGS);
    Node foo = session.getNodeByPath("/foo", null);
    assertNotNull(foo);
    xaresource.end(xid, XAResource.TMSUCCESS);
    int outcome = xaresource.prepare(xid);
    if (outcome == XAResource.XA_OK) {
        // Derby doesn't allow rollback if prepare returned XA_RDONLY
        xaresource.rollback(xid);
    }
}

From source file:org.seasar.karrta.jcr.intercepter.JcrTransactionInterceptor.java

public Object invoke(MethodInvocation invocation) throws Throwable {
    Thread currentThread = Thread.currentThread();
    if (this.sessionManager_.isExist(currentThread)) {
        return invocation.proceed();
    }//from   ww w . j  ava 2  s  .c  om

    logger_.debug("::: [Begin Transaction] ::: [" + currentThread + "] :::");

    // check in jcr-session.
    XASession session = (XASession) sessionManager_.borrowObject(currentThread);
    Xid xid = new Xid() {
        public byte[] getBranchQualifier() {
            return new byte[0];
        }

        public int getFormatId() {
            return 0;
        }

        public byte[] getGlobalTransactionId() {
            return new byte[0];
        }
    };
    XAResource xares = session.getXAResource();
    xares.start(xid, XAResource.TMNOFLAGS);

    Object result = null;
    try {
        for (Method m : invocation.getThis().getClass().getMethods()) {
            if ("setOcmQueryManager".equals(m.getName())) {
                m.invoke(invocation.getThis(), this.ocmFactory.getQueryManager());
            }
            if ("setQueryManager".equals(m.getName())) {
                m.invoke(invocation.getThis(), session.getWorkspace().getQueryManager());
            }
        }
        result = invocation.proceed();

        xares.end(xid, XAResource.TMSUCCESS);
        xares.prepare(xid);
        xares.commit(xid, false);

    } catch (Exception e) {
        e.printStackTrace();
        xares.rollback(xid);

    } finally {
        // check out jcr-session.
        this.sessionManager_.returnSession(currentThread, session);
        logger_.debug("::: [End Transaction] ::: [" + currentThread + "] :::");
    }
    return result;
}

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

public synchronized void endTransaction() throws RSSManagerException {
    if (log.isDebugEnabled()) {
        log.debug("endTransaction()");
    }//from   ww  w.  j  a v  a 2  s . c  o m
    activeNestedTransactions.set(activeNestedTransactions.get() - 1);
    /* commit all only if we are at the outer most transaction */
    if (activeNestedTransactions.get() == 0) {
        this.delistResource(XAResource.TMSUCCESS);
        this.getRSSTransactionManager().commit();
    } else if (activeNestedTransactions.get() < 0) {
        activeNestedTransactions.set(0);
    }
}