org.geotools.data.jdbc
Class ConnectionPool

java.lang.Object
  extended byorg.geotools.data.jdbc.ConnectionPool

public final class ConnectionPool
extends java.lang.Object

Provides a ConnectionPool that can be used by multiple data sources to get connections to a single database.

This class should not be subclassed.

Version:
$Id: ConnectionPool.java 17701 2006-01-23 00:00:51Z desruisseaux $ Last Modified: $Date: 2003/11/05 15:37:02 $
Author:
Sean Geoghegan, Defence Science and Technology Organisation, $Author: cholmesny $

Constructor Summary
ConnectionPool(javax.sql.ConnectionPoolDataSource cpDataSource)
          Creates a new Connection Pool using a ConnectionPoolDataSource.
 
Method Summary
 void close()
          Closes all the PooledConnections in the the ConnectionPool.
 java.sql.Connection getConnection()
          Gets a Connection from the Connection Pool.
 boolean isClosed()
          Checks whether the ConnectionPool has been closed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(javax.sql.ConnectionPoolDataSource cpDataSource)
Creates a new Connection Pool using a ConnectionPoolDataSource.

This constructor will also spawn a thread for cleaning the connection pool every 30 seconds.

Parameters:
cpDataSource - The Connection Pool Data Source to get PooledConnections from.
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Gets a Connection from the Connection Pool.

If no available connections exist a new connection will be created and added to the pool. When the returned connection is closed it will be added to the connection pool for other requests to this method.

Returns:
A Connection from the ConnectionPool.
Throws:
java.sql.SQLException - If an error occurs getting the connection or if the connection pool has been closed by a previous call to close().

close

public void close()
Closes all the PooledConnections in the the ConnectionPool. The current behaviour is to first close all the used connections, then close all the available connections. This method will also set the state of the ConnectionPool to closed, caused any future calls to getConnection to throw an SQLException.


isClosed

public boolean isClosed()
Checks whether the ConnectionPool has been closed.

Returns:
True if the connection pool is closed. If the Pool is closed future calls to getConnection will throw an SQLException.


Copyright © GeoTools. All Rights Reserved.