com.ge.research.utils.db
Class SingleConnectionManager

java.lang.Object
  extended bycom.ge.research.utils.db.SingleConnectionManager
All Implemented Interfaces:
ConnectionBroker, javax.sql.DataSource

public class SingleConnectionManager
extends java.lang.Object
implements ConnectionBroker

A connection broker that keeps at most a single connection to a database active and available for use.

Version:
$Revision: 1.1 $ $Date: 2006/08/11 00:17:26 $
Author:
garbiras
Created on:
Mar 30, 2005

Field Summary
 
Fields inherited from interface com.ge.research.utils.db.ConnectionBroker
DB_ATTEMPTS_KEY, DB_CONNTIMEOUT_KEY, DB_DRIVER_KEY, DB_MAXCONN_KEY, DB_MINCONN_KEY, DB_PWD_KEY, DB_URL_KEY, DB_USERNAME_KEY, DB_WAITTIME_KEY, MAX_CONNECTIONS, MIN_CONNECTIONS
 
Constructor Summary
SingleConnectionManager(java.lang.String resourceFile)
          Constructs the connection manager using the database connection information contained in the resource bundle argument name.
 
Method Summary
 void freeConnection(java.sql.Connection c)
          Returns the connection from use and releases it back tot he pool of available connections which can be accessed by requestors.
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String username, java.lang.String password)
           
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
           
 int getMaxConnections()
          Returns the current setting for the maximum allowable size of the connection pool.
 int getMaxDbAttempts()
          Returns the current setting for the maximum number of consecutive attempts at requesting a connection from the pool (without obtaining a free connection), before generating an error.
 int getMinConnections()
          Returns the current setting for the minimum allowable size of the connection pool.
 int getNumberFreeConnections()
          Returns the number of currently free and available connections in the pool
 long getTimeout()
          Returns the current setting for the number of milliseconds to keep pooled connections not in use active and open.
 boolean isConnectionOpen()
          Checks the status of the connection, returning true if the connection can be used
 void setLoginTimeout(int i)
           
 void setLogWriter(java.io.PrintWriter out)
           
 void setMaxConnections(int num)
          Sets the maximum allowable size of the connection pool.
 void setMaxDbAttempts(int i)
          Sets the maximum number of consecutive attempts allowed when requesting a connection from the pool (without obtaining a free connection), before generating an error.
 void setMinConnections(int num)
          Sets the minimum allowable size of the connection pool.
 void setTimeout(long l)
          Sets the number of milliseconds to keep pooled connections not in use active and open.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SingleConnectionManager

public SingleConnectionManager(java.lang.String resourceFile)
                        throws java.lang.Exception
Constructs the connection manager using the database connection information contained in the resource bundle argument name.

Parameters:
resourceFile - the resource bundle name
Throws:
java.lang.Exception - If the resource bundle information could not be loaded, or the database driver could not be registered.
Method Detail

freeConnection

public void freeConnection(java.sql.Connection c)
Description copied from interface: ConnectionBroker
Returns the connection from use and releases it back tot he pool of available connections which can be accessed by requestors.

Specified by:
freeConnection in interface ConnectionBroker
Parameters:
c - the connection to return to the available pool

getConnection

public java.sql.Connection getConnection()
Specified by:
getConnection in interface javax.sql.DataSource

getConnection

public java.sql.Connection getConnection(java.lang.String username,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface javax.sql.DataSource

getLogWriter

public java.io.PrintWriter getLogWriter()
                                 throws java.sql.SQLException
Specified by:
getLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getMaxConnections

public int getMaxConnections()
Description copied from interface: ConnectionBroker
Returns the current setting for the maximum allowable size of the connection pool.

Specified by:
getMaxConnections in interface ConnectionBroker
Returns:
The maximum allowable size of the connection pool

getMaxDbAttempts

public int getMaxDbAttempts()
Description copied from interface: ConnectionBroker
Returns the current setting for the maximum number of consecutive attempts at requesting a connection from the pool (without obtaining a free connection), before generating an error.

Specified by:
getMaxDbAttempts in interface ConnectionBroker
Returns:
The maximum number of attempts to obtain a free connection from the pool

getMinConnections

public int getMinConnections()
Description copied from interface: ConnectionBroker
Returns the current setting for the minimum allowable size of the connection pool.

Specified by:
getMinConnections in interface ConnectionBroker
Returns:
The minimum allowable size of the connection pool

getNumberFreeConnections

public int getNumberFreeConnections()
Description copied from interface: ConnectionBroker
Returns the number of currently free and available connections in the pool

Specified by:
getNumberFreeConnections in interface ConnectionBroker
Returns:
The number of currently free and available connections in the pool

getTimeout

public long getTimeout()
                throws java.lang.UnsupportedOperationException
Description copied from interface: ConnectionBroker
Returns the current setting for the number of milliseconds to keep pooled connections not in use active and open.

Specified by:
getTimeout in interface ConnectionBroker
Returns:
The number of milliseconds to keep pooled connections not in use active and open
Throws:
java.lang.UnsupportedOperationException

isConnectionOpen

public final boolean isConnectionOpen()
Checks the status of the connection, returning true if the connection can be used

Returns:
true if the connection is not null and has not been closed by an application or the database; false otherwise.

setLoginTimeout

public void setLoginTimeout(int i)
Specified by:
setLoginTimeout in interface javax.sql.DataSource

setLogWriter

public void setLogWriter(java.io.PrintWriter out)
                  throws java.sql.SQLException
Specified by:
setLogWriter in interface javax.sql.DataSource
Throws:
java.sql.SQLException

setMaxConnections

public void setMaxConnections(int num)
                       throws java.lang.UnsupportedOperationException
Description copied from interface: ConnectionBroker
Sets the maximum allowable size of the connection pool.

Specified by:
setMaxConnections in interface ConnectionBroker
Parameters:
num - the maximum allowable size of the connection pool
Throws:
java.lang.UnsupportedOperationException

setMaxDbAttempts

public void setMaxDbAttempts(int i)
Description copied from interface: ConnectionBroker
Sets the maximum number of consecutive attempts allowed when requesting a connection from the pool (without obtaining a free connection), before generating an error.

Specified by:
setMaxDbAttempts in interface ConnectionBroker
Parameters:
i - the maximum number of attempts to obtain a free connection from the pool

setMinConnections

public void setMinConnections(int num)
                       throws java.lang.UnsupportedOperationException
Description copied from interface: ConnectionBroker
Sets the minimum allowable size of the connection pool.

Specified by:
setMinConnections in interface ConnectionBroker
Parameters:
num - the minimum allowable size of the connection pool
Throws:
java.lang.UnsupportedOperationException

setTimeout

public void setTimeout(long l)
                throws java.lang.UnsupportedOperationException
Description copied from interface: ConnectionBroker
Sets the number of milliseconds to keep pooled connections not in use active and open.

Specified by:
setTimeout in interface ConnectionBroker
Parameters:
l - the number of milliseconds to keep pooled connections not in use active and open
Throws:
java.lang.UnsupportedOperationException