Example usage for javax.transaction Transaction delistResource

List of usage examples for javax.transaction Transaction delistResource

Introduction

In this page you can find the example usage for javax.transaction Transaction delistResource.

Prototype

public boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException, SystemException;

Source Link

Document

Disassociate the resource specified from the transaction associated with the target Transaction object.

Usage

From source file:org.enhydra.jdbc.pool.StandardXAPoolDataSource.java

/**
 * Invoked when the application calls close()
 * on its representation of the connection
 *//* w  w w. jav  a 2s  . c  om*/
public void connectionClosed(ConnectionEvent event) {
    Object obj = event.getSource();
    log.debug("StandardXAPoolDataSource:connectionClosed");
    XAConnection xac = (XAConnection) obj; // cast it into an xaConnection

    Transaction tx = null;
    try {
        if (transactionManager == null) {
            TransactionManager tm = ((StandardXADataSource) xads).getTransactionManager();
            if (tm == null) {
                throw new NullPointerException("TM is null");
            } else
                // here we use tm instead to setup transactionManager = tm
                // if the current transactionManager property is null, it stays
                // there, and we continue to use the TM from the XADataSource
                tx = tm.getTransaction();
        } else {
            tx = transactionManager.getTransaction();
        }
        log.debug("StandardXAPoolDataSource:connectionClosed get a transaction");
    } catch (NullPointerException n) {
        // current is null: we are not in EJBServer.
        log.error("StandardXAPoolDataSource:connectionClosed should not be used outside an EJBServer");
    } catch (SystemException e) {
        log.error("StandardXAPoolDataSource:connectionClosed getTransaction failed:" + e);
    }

    // delist Resource if in transaction
    // We must keep the connection till commit or rollback
    if ((tx != null) && (((StandardXAConnection) xac).connectionHandle.isReallyUsed)) {
        try {
            tx.delistResource(xac.getXAResource(), XAResource.TMSUCCESS);
            // delist the xaResource
            log.debug("StandardXAPoolDataSource:connectionClosed the resourse is delisted");
        } catch (Exception e) {
            log.error("StandardXAPoolDataSource:connectionClosed Exception in connectionClosed:" + e);
        }
    }
    log.debug("StandardXAPoolDataSource:connectionClosed checkIn an object to the pool");
    pool.checkIn(obj); // return the connection to the pool
}

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

public static void delistResource(int flag, long key) throws Exception {
    Map<Long, XAResource> enlistedResources = enlistedXADataSources.get();
    XAResource resource = null;//  www  . ja  va 2  s . c o  m
    try {
        if (enlistedResources != null && !enlistedResources.isEmpty()) {
            Transaction tx = transactions.get().get(key);
            resource = enlistedResources.get(key);
            if (tx != null && resource != null) {
                tx.delistResource(resource, flag);
            }
        }

    } catch (Exception ex) {
        throw new Exception("Error occurred while delisting datasource " + "connection: " + ex.getMessage(),
                ex);
    } finally {
        removeConnectionUsed(key);
        removeTransaction(key);
        enlistedResources.remove(key);
    }
}

From source file:org.mule.test.integration.transaction.XAResourceManagerTestCase.java

@Test
public void testTxBehaviour() throws Exception {
    TestXAResourceManager rm = new TestXAResourceManager();
    rm.start();//from www  .j a va2 s  .c  o  m
    DefaultXASession s = rm.createSession();

    tm.begin();
    Transaction tx = tm.getTransaction();
    tx.enlistResource(s);

    tx.delistResource(s, XAResource.TMSUCCESS);
    tx.commit();
}

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

public synchronized void delistResource(int flag) throws RSSManagerException {
    Set<XAResource> enlistedResources = enlistedXADataSources.get();
    try {//  w  ww  . ja v  a2 s  .co m
        if (enlistedResources != null && !enlistedResources.isEmpty()) {
            Transaction tx = this.getRSSTransactionManager().getTransactionManager().getTransaction();
            Iterator<XAResource> itr = enlistedResources.iterator();
            while (itr.hasNext()) {
                XAResource resource = itr.next();
                if (tx != null) {
                    tx.delistResource(resource, flag);
                }
                itr.remove();
            }
        }
    } catch (Exception e) {
        throw new RSSManagerException(
                "Error occurred while delisting datasource " + "connection: " + e.getMessage(), e);
    }
}