Example usage for javax.sql ConnectionEvent getSource

List of usage examples for javax.sql ConnectionEvent getSource

Introduction

In this page you can find the example usage for javax.sql ConnectionEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

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

/**
 * Invoked when the application calls close()
 * on its representation of the connection
 *///from   w  w  w.j  a  va 2 s . co m
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:com.alibaba.wasp.jdbcx.JdbcConnectionPool.java

/**
 * INTERNAL/*from  w w  w .j  av a2  s .c o  m*/
 */
public void connectionClosed(ConnectionEvent event) {
    PooledConnection pc = (PooledConnection) event.getSource();
    pc.removeConnectionEventListener(this);
    recycleConnection(pc);
}

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

/**
 * connectionErrorOccurred and connectionClosed are methods
 * from ConnectionEventListener interface
 *
 * Invoked when a fatal connection error occurs,
 * just before an SQLException is thrown to the application
 */// w  w  w .j  ava 2 s  .c  om
public void connectionErrorOccurred(ConnectionEvent event) {
    Object obj = event.getSource();
    PooledConnection pc = (PooledConnection) obj;
    pool.nextGeneration(pc);
    pool.removeLockedObject(pc); // remove the object from the locked pool
    expire(pc); // kill the connection (from super)
    log.debug("StandardXAPoolDataSource:connectionErrorOccurred remove the object from the pool");
}

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

/**
 * Invoked when the application calls close()
 * on its representation of the connection
 *//*from  w  ww .j av a2 s  .  co m*/
public void connectionClosed(ConnectionEvent event) {
    log.debug("StandardPoolDataSource:connectionClosed close the connection");
    Object obj = event.getSource();
    pool.checkIn(obj);
}