se.kmr.scam.local.pool
Class ConnectionPool

java.lang.Object
  extended byse.kmr.scam.local.pool.ConnectionPool
All Implemented Interfaces:
DataSource

public class ConnectionPool
extends Object
implements DataSource

A ConnectionPool manages a set of connections that can be allocated and reused.

When created, a ConnectionPool is associated with a specific ConnectionFactory, which creates new connections when asked.

The pool has operating parameters that can be set in its constructor by means of a Properties object:

A client of this class allocates a connection by calling getConnection(). A maximum wait time can be specified on this call. When the client is done with the connection, the client calls releaseConnection(connection)

Version:
$Revision: 1.4 $
See Also:
ConnectionFactory, Connection, PoolEntry

Constructor Summary
ConnectionPool(ConnectionFactory factory, int minEntries, int maxEntries)
          Creates a connection pool with specified properties using the specified pooled connection factory
 
Method Summary
 void close()
          Closes the pool, first closing all the unallocated entries
 Connection getConnection()
          Allocates an entry from the pool, creating one if necessary (if the pool is not at maximum size).
 Connection getConnection(long timeout)
          Allocates an entry from the pool, creating one if necessary (if the pool is not at maximum size).
 Connection getConnection(String name, String pw)
           
 int getLoginTimeout()
           
 PrintWriter getLogWriter()
           
 void refresh()
          Refreshes the entries in the pool.
 void releaseConnection(Connection con)
          Releases a resource back to the pool
 void setLoginTimeout(int time)
           
 void setLogWriter(PrintWriter writer)
           
 String toString()
          Returns the pool as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionPool

public ConnectionPool(ConnectionFactory factory,
                      int minEntries,
                      int maxEntries)
               throws SQLException
Creates a connection pool with specified properties using the specified pooled connection factory

Parameters:
factory - the factory class that creates new instances of the pooled connection.
Throws:
PoolException - if the pool cannot be created.
SQLException
Method Detail

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface DataSource

setLoginTimeout

public void setLoginTimeout(int time)
Specified by:
setLoginTimeout in interface DataSource

getLogWriter

public PrintWriter getLogWriter()
Specified by:
getLogWriter in interface DataSource

setLogWriter

public void setLogWriter(PrintWriter writer)
Specified by:
setLogWriter in interface DataSource

getConnection

public Connection getConnection(String name,
                                String pw)
Specified by:
getConnection in interface DataSource

close

public void close()
Closes the pool, first closing all the unallocated entries


getConnection

public Connection getConnection(long timeout)
                         throws SQLException
Allocates an entry from the pool, creating one if necessary (if the pool is not at maximum size). If no entry is available, waits up to the specified number of milliseconds for one to become available.

Parameters:
timeout - the maximum number of milliseconds to wait before giving up. A value of -1 means to wait indefinitely.
Returns:
the allocated underlying connection or null if one cannot be allocated.
Throws:
SQLException

getConnection

public Connection getConnection()
                         throws SQLException
Allocates an entry from the pool, creating one if necessary (if the pool is not at maximum size). If no entry is available, waits indefinitely for one to become available.

Specified by:
getConnection in interface DataSource
Returns:
the allocated Connection, or null if one cannot be allocated.
Throws:
SQLException

refresh

public void refresh()
             throws SQLException
Refreshes the entries in the pool. This involves:

Throws:
SQLException

releaseConnection

public void releaseConnection(Connection con)
Releases a resource back to the pool

Parameters:
con - the underlying pooled con

toString

public String toString()
Returns the pool as a string



Copyright © 2003 SCAM. All Rights Reserved.