com.altair.hwm.database.dbmodel
Class HWMDBCxnPool

java.lang.Object
  extended by com.altair.hwm.database.dbmodel.HWMDBCxnPool
All Implemented Interfaces:
java.lang.Runnable

public class HWMDBCxnPool
extends java.lang.Object
implements java.lang.Runnable

Title: HWMDBCxnPool

Description: This class handles the database connection pool. This has been modified to suit Altair's requirements

Company: Altair Engineering, Inc.

A class for preallocating, recycling, and managing JDBC connections. Taken from Core Servlets and JavaServer Pages from Prentice Hall and Sun Microsystems Press, http://www.coreservlets.com/. © 2000 Marty Hall; may be freely used or adapted.


Constructor Summary
HWMDBCxnPool(java.lang.String strSQLInfoClass, java.lang.String strURL, int nPort, java.lang.String strDBName, java.lang.String strUser, java.lang.String strPwd, int nInitialCxns, int nMaxCxns)
          Constructor
 
Method Summary
 void CloseAllConnections()
          Close all the connections.
 void FreeConnection(java.sql.Connection cxn)
          Make the cxn available to other clients.
 java.sql.Connection GetConnection()
          Returns a free connection.
 HWMDatabaseInfo GetDatabaseInfo()
          Returns the database info class
 int GetTotalConnections()
          Returns the total connections created
 java.lang.String GetURL()
          Returns the URL of the databse
 java.lang.String GetUser()
          Returns the user name who connects to the database
 void run()
          The run method of the thread
 java.lang.String toString()
          String representation of this class
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HWMDBCxnPool

public HWMDBCxnPool(java.lang.String strSQLInfoClass,
                    java.lang.String strURL,
                    int nPort,
                    java.lang.String strDBName,
                    java.lang.String strUser,
                    java.lang.String strPwd,
                    int nInitialCxns,
                    int nMaxCxns)
             throws java.lang.Exception
Constructor

Parameters:
strSQLInfoClass - The SQL info class which will be used for connecting to DB
strURL - The URL to the db machine
nPort - The port to which the DB server is listening to
strDBName - The DB name to connect to
strUser - The user name
strPwd - The password
nInitialCxns - The initial number of connections
nMaxCxns - The maximum number of connections allowed
Throws:
java.lang.Exception
Method Detail

GetConnection

public java.sql.Connection GetConnection()
                                  throws java.sql.SQLException
Returns a free connection. If there are no more free connections, then a new connection is created until the max limit is recahed. If the max limit is reached, then an exception is thrown

Returns:
Connection Connection to database
Throws:
java.sql.SQLException

run

public void run()
The run method of the thread

Specified by:
run in interface java.lang.Runnable

FreeConnection

public void FreeConnection(java.sql.Connection cxn)
Make the cxn available to other clients. This will also notify the clients waiting for a free cxn (so that they do not have to wait until the new cxn is created)

Parameters:
cxn - the connection that needs to be made available

GetTotalConnections

public int GetTotalConnections()
Returns the total connections created

Returns:
int The total connections created

CloseAllConnections

public void CloseAllConnections()
Close all the connections. Use with caution: be sure no connections are in use before calling. Note that you are not required to call this when done with a ConnectionPool, since connections are guaranteed to be closed when garbage collected. But this method gives more control regarding when the connections are closed.


GetUser

public java.lang.String GetUser()
Returns the user name who connects to the database

Returns:
String User who connects to the database

GetURL

public java.lang.String GetURL()
Returns the URL of the databse

Returns:
String URL of the database

GetDatabaseInfo

public HWMDatabaseInfo GetDatabaseInfo()
Returns the database info class

Returns:
HWMdatabaseInfo The database info class

toString

public java.lang.String toString()
String representation of this class

Overrides:
toString in class java.lang.Object
Returns:
String String representation of this class