public void finalize () throws Throwable { try { cleanup (); } finally { super.finalize (); } }
/** * @see javax.sql.DataSource#getLogWriter() */ public PrintWriter getLogWriter () throws SQLException { return pool.getLogWriter (); }
/** * @see javax.sql.DataSource#getLoginTimeout() */ public int getLoginTimeout () throws SQLException { return pool.getLoginTimeout (); }
while ( timerNeeded_ ) { Thread.sleep ( timeout_ ); enumm = getOldConnections (); test ( pc , true ); if ( LOGGER.isDebugEnabled() ) LOGGER.logDebug ( "ConnectionPool: connection is fine, keeping it in pool: " + pc); putInPool ( pc ); else if ( getSize () < maxSize_ ) { putInPool ( newConn ); LOGGER .logDebug ( "ConnectionPool: replacing invalidated connection " if ( getSize () < maxSize_ ) { PooledConnection newConn = source_ .getPooledConnection (); putInPool ( newConn ); LOGGER .logDebug ( "ConnectionPool: connection invalid, replacing it: "
test ( retVal , false ); try { test ( retVal , false ); retVal = getPooledConnection();
/** * Puts back a connection after usage. This method should be called by * DataSource objects. * * @param conn * The connection. If the connection has been invalidated, or if * the pool is large enough, then this method will actually close * the connection. */ public synchronized void putBack ( XPooledConnection conn ) { if ( !conn.getInvalidated () && getSize () < maxSize_ ) { if ( LOGGER.isDebugEnabled() ) LOGGER.logDebug ( "Putting connection back in pool: " + conn.toString () ); putInPool ( conn ); } else { try { if ( LOGGER.isDebugEnabled() ) LOGGER.logDebug ( "Pool: closing connection: " + conn.toString () ); conn.close (); // closes underlying connection } catch ( SQLException err ) { } } }
/** * @see javax.sql.DataSource#setLogWriter(java.io.PrintWriter) */ public void setLogWriter ( PrintWriter pw ) throws SQLException { pool.setLogWriter ( pw ); }
/** * @see javax.sql.ConnectionEventListener#connectionClosed(javax.sql.ConnectionEvent) */ public synchronized void connectionClosed ( ConnectionEvent event ) { // called when the Pooled Connection is resubmitted to the pool // remove ThreadLocal mapping XPooledConnection source = (XPooledConnection) event.getSource (); Set values = previousConnections.entrySet (); Iterator it = values.iterator (); while ( it.hasNext () ) { Map.Entry entry = (Map.Entry) it.next (); Connection c = (Connection) entry.getValue (); ThreadLocalConnection tlc = (ThreadLocalConnection) Proxy .getInvocationHandler ( c ); if ( tlc.usesConnection ( source ) ) { it.remove (); } } source.removeConnectionEventListener ( this ); pool.putBack ( source ); }
/** * @see com.atomikos.jdbc.HeuristicDataSource#getConnection(com.atomikos.icatch.HeuristicMessage) */ public Connection getConnection ( HeuristicMessage msg ) throws SQLException { DTPPooledConnection ret = (DTPPooledConnection) pool_ .getPooledConnection (); ret.addConnectionEventListener ( this ); return ret.getConnection ( msg ); }
pool = new ConnectionPool ( poolSize, factory, connectionTimeout, testQuery , testOnBorrow ); previousConnections = new HashMap (); this.jndiName = jndiName;
/** * @see javax.sql.DataSource */ public void setLogWriter ( PrintWriter pw ) throws SQLException { pool_.setLogWriter ( pw ); }
/** * @see javax.sql.ConnectionEventListener#connectionClosed(javax.sql.ConnectionEvent) */ public void connectionClosed ( ConnectionEvent arg ) { DTPPooledConnection pc = (DTPPooledConnection) arg.getSource (); if ( pc.isDiscarded () ) { pc.removeConnectionEventListener ( this ); pool_.putBack ( pc ); } }
/** * @see com.atomikos.jdbc.HeuristicDataSource#getConnection(com.atomikos.icatch.HeuristicMessage) */ public synchronized Connection getConnection ( HeuristicMessage msg ) throws SQLException { // ThreadLocalConnection ret = ( ThreadLocalConnection ) // previousConnections.get(); Connection proxy = (Connection) previousConnections.get ( Thread .currentThread () ); if ( proxy == null ) { // no previous connection -> get one from pool NonXAPooledConnectionImp pc = (NonXAPooledConnectionImp) pool .getPooledConnection (); pc.addConnectionEventListener ( this ); proxy = (Connection) ThreadLocalConnection.newInstance ( pc ); previousConnections.put ( Thread.currentThread (), proxy ); } // here we are certain that proxy is not null -> increase the use count ThreadLocalConnection previous = (ThreadLocalConnection) Proxy .getInvocationHandler ( proxy ); // if ( previous.isStale() ) System.out.println ( "WARNING: STALE // CONNECTION STILL MAPPED TO THREAD"); previous.incUseCount (); previous.addHeuristicMessage ( msg ); return proxy; }
pool_ = new ConnectionPool ( poolSize, fact, connectionTimeout, testQuery , testOnBorrow );
/** * Closes the datasource (and shuts down the pool). * */ public void close () { pool.cleanup (); removeFromMap ( jndiName ); }
/** * @see javax.sql.DataSource */ public int getLoginTimeout () throws SQLException { return pool_.getLoginTimeout (); }
/** * @see javax.sql.DataSource */ public PrintWriter getLogWriter () throws SQLException { return pool_.getLogWriter (); }
/** * Cleans up the instance, and closes the pool. */ public void close () { pool_.cleanup (); removeFromMap ( resource_.getName () ); if ( autoRegister_ ) Configuration.removeResource ( resource_.getName () ); }