dke.smwp
Class ConnectionPool

java.lang.Object
  |
  +--dke.smwp.ConnectionPool

public class ConnectionPool
extends java.lang.Object

Pool which handles database connections.

Version:
1.0
Author:
Werner Enser

Field Summary
private  java.util.Hashtable _connections
          stores all open connections
private  java.lang.String _dbURL
          database url
static java.lang.String _errorText
          internal error text
private  int _increment
          number of connections which are being opened if available connections run out
private  java.lang.String _password
          database password
private  java.lang.String _user
          database username
private static boolean DEBUG
          debug variable
private static ConnectionPool instance
          connection pool instance
 
Constructor Summary
private ConnectionPool(java.lang.String dbURL, java.lang.String user, java.lang.String password, java.lang.String driverClassName, int initialConnections, int increment)
          default constructor - initializes ConnectionPool and creates database connections (number of initial connections defined by initialConnections
 
Method Summary
protected  void finalize()
          closes all connections wthin pool
 java.sql.Connection getConnection()
          gets the connection handle
static ConnectionPool getInstance()
          gets the sole instance of ConnectionPool
 void returnConnection(java.sql.Connection returned)
          returns the connection handle to the connection pool
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
debug variable

_errorText

public static java.lang.String _errorText
internal error text

_connections

private java.util.Hashtable _connections
stores all open connections

_increment

private int _increment
number of connections which are being opened if available connections run out

_dbURL

private java.lang.String _dbURL
database url

_user

private java.lang.String _user
database username

_password

private java.lang.String _password
database password

instance

private static ConnectionPool instance
connection pool instance
Constructor Detail

ConnectionPool

private ConnectionPool(java.lang.String dbURL,
                       java.lang.String user,
                       java.lang.String password,
                       java.lang.String driverClassName,
                       int initialConnections,
                       int increment)
default constructor - initializes ConnectionPool and creates database connections (number of initial connections defined by initialConnections
Parameters:
dbURL - database url
user - database username
password - database password
driverClassName - class name (e.g. oracle.jdbc.driver.OracleDriver)
initialConnection - number of opened connections by default
increment - number of connections which are opened if available connections are running out
Method Detail

getInstance

public static ConnectionPool getInstance()
gets the sole instance of ConnectionPool
Returns:
sole instance of ConnectionPool

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
gets the connection handle
Returns:
connection handle
Throws:
java.sql.SQLException - testing open connection failed

returnConnection

public void returnConnection(java.sql.Connection returned)
returns the connection handle to the connection pool
Parameters:
returned - connection handle

finalize

protected void finalize()
                 throws java.lang.Throwable
closes all connections wthin pool
Overrides:
finalize in class java.lang.Object