public class JDBCConnectionPool
extends java.lang.Object
implements java.io.Serializable
Direct references to this class and its methods should only be made by
the JDBCPoolManager
class.
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<JDBCConnectionInfo> |
ivAllConnections
The list of all JDBC connections ever created by the pool.
|
private int |
ivCheckedOut
The number of checked out connections from the pool.
|
private java.lang.String |
ivDriverName
The name of the JDBC driver class for the driver used to access this
connection pool's database.
|
private java.util.ArrayList<JDBCConnectionInfo> |
ivFreeConnections
The pool of free JDBC connections available for use.
|
private int |
ivMaxConns
The maximum number of open connections.
|
private java.lang.String |
ivName
The connection pool name.
|
private java.lang.String |
ivPassword
The password for a connection.
|
private java.lang.String |
ivSQLName
The SQL collection name for a connection.
|
private java.util.ArrayList<java.lang.String> |
ivTableNames
A collection of the database table and view names, derived from the
database associated with the connection pool.
|
private long |
ivTimeOut
The number of milliseconds to wait for a connection if none is available
and the maximum limit is reached.
|
private java.lang.String |
ivURL
The URL for the database.
|
private java.util.Hashtable<JDBCConnectionInfo,java.lang.String> |
ivUsedConnections
A list of the in-use JDBC connections.
|
private java.lang.String |
ivUserId
The user id for a connection.
|
private static long |
serialVersionUID
The class' serialization version id.
|
Constructor and Description |
---|
JDBCConnectionPool(java.lang.String name,
java.lang.String url,
java.lang.String sqlname,
java.lang.String userid,
java.lang.String password,
int maxconns,
int initconns,
int waittimeout)
Constructs a new
JDBCConnectionPool object. |
Modifier and Type | Method and Description |
---|---|
private void |
addToUsedList(JDBCConnectionInfo cninf,
java.lang.String consumer)
Adds the given JDBC connection info object to the list of used connection
info objects.
|
void |
freeConnection(JDBCConnectionInfo cninf)
Frees a used JDBC connection info object.
|
JDBCConnectionInfo |
getConnection()
Retrieves a JDBC connection info object from the pool.
|
private JDBCConnectionInfo |
getConnection(java.lang.String consumer,
long timeout)
Retrieves a JDBC connection info object from the pool using the given
maximum wait time.
|
private java.lang.String |
getConnectionConsumer()
Returns the consumer of a connection (the reference point within the code
where a connection is being requested or returned).
|
protected java.lang.String |
getConnectionConsumers()
Returns a sorted list of the connection consumers associated with the
connections currently in-use, suitable for display in a listbox (list
is delimited by newline character).
|
protected java.lang.String |
getConnectionStats()
Returns string containing information on total number of connections,
number of checked out connections, and number of available ones.
|
private JDBCConnectionInfo |
getPooledConnection()
Retrieves a JDBC connection info object if one is available from the pool.
|
java.lang.String |
getPoolName()
Returns the connection pool's name.
|
java.lang.String |
getRevisedSQL(java.lang.String sqlstmt)
Returns the given sql statement with revisions based on the current rules
for revising sql statements (sql collection name, etc.).
|
java.lang.String |
getRevisedSQLForTestOnly(java.lang.String sqlname,
java.lang.String sqlstmt)
Returns the given sql statement with revisions based on the given sql
collection name.
|
java.lang.String |
getSQLName()
Returns the connection pool's SQL collection name.
|
private void |
initializePool(int initconns)
Opens the initial JDBC connections for the pool.
|
private void |
initializeTableNames()
Initializes the collection of database table and view names.
|
private boolean |
isConnectionOK(JDBCConnectionInfo cninf)
Checks if the given JDBC connection info object is functioning properly.
|
boolean |
isDB2e()
Answers if this connection pool uses an IBM DB2 Everyplace database.
|
boolean |
isDB2i()
Answers if this connection pool uses an IBM DB2 System i (AS/400) database.
|
boolean |
isDB2iNative()
Answers if this connection pool uses an IBM DB2 System i (AS/400) database
in native mode (i.e.
|
boolean |
isDB2w()
Answers if this connection pool uses an IBM DB2 Windows database.
|
boolean |
isDerby()
Answers if this connection pool uses an Apache Derby (IBM Cloudscape)
database.
|
private JDBCConnectionInfo |
newConnection()
Retrieves a newly created JDBC connection info object.
|
void |
release()
Releases all JDBC connection info objects in the pool.
|
private java.lang.String |
removeFromUsedList(JDBCConnectionInfo cninf)
Removes the given JDBC connection info object from the list of used
connection info objects.
|
private java.lang.String |
reviseForSQLName(java.lang.String sqlname,
java.lang.String sqlstmt)
Returns the given sql statement with the database sql collection name
inserted into the statement prior to all occurrences of table or view
names.
|
private boolean |
searchTableNames(java.lang.String name)
Answers if
ivTableNames contains a given name, regardless of case. |
private static final long serialVersionUID
private java.lang.String ivName
private java.lang.String ivURL
private java.lang.String ivSQLName
private java.lang.String ivUserId
private java.lang.String ivPassword
private int ivMaxConns
private long ivTimeOut
private java.lang.String ivDriverName
private java.util.ArrayList<java.lang.String> ivTableNames
private int ivCheckedOut
private java.util.ArrayList<JDBCConnectionInfo> ivFreeConnections
private java.util.ArrayList<JDBCConnectionInfo> ivAllConnections
private java.util.Hashtable<JDBCConnectionInfo,java.lang.String> ivUsedConnections
public JDBCConnectionPool(java.lang.String name, java.lang.String url, java.lang.String sqlname, java.lang.String userid, java.lang.String password, int maxconns, int initconns, int waittimeout)
JDBCConnectionPool
object.
Any Exception
s possibly caused by the system unavailability
are ignored here (only logged) because, by the time the application asks
for a connection from the pool, the connection might then be successfully
created. If the problem still persists, it is handled at that time.name
- (String) The connection pool name.url
- (String) The JDBC URL for the database.sqlname
- (String) The SQL collection name for a connection.userid
- (String) The user id for a connection.password
- (String) The password for a connection.maxconns
- (int) The maximum number of connections in the pool.
0 means no limit.initconns
- (int) The number of initial connections to open for
the pool.waittimeout
- (int) The number of seconds to wait for a connection
if none is available and the maximum limit is reached.public void freeConnection(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The connection info object to free.public JDBCConnectionInfo getConnection() throws java.sql.SQLException
Exception
is logged and then thrown back to
the invoker.java.sql.SQLException
- - if a connection info object cannot be retrieved.private JDBCConnectionInfo getConnection(java.lang.String consumer, long timeout) throws java.sql.SQLException
consumer
- (String) The connection consumer (the reference point
within the code where the connection is being requested).timeout
- (long) The maximum wait time for a connection.java.sql.SQLException
- - if a connection info object cannot be retrieved.private java.lang.String getConnectionConsumer()
protected java.lang.String getConnectionConsumers()
protected java.lang.String getConnectionStats()
private JDBCConnectionInfo getPooledConnection() throws java.sql.SQLException
newConnection
method.java.sql.SQLException
- - if a connection info object cannot be retrieved.public java.lang.String getPoolName()
public java.lang.String getRevisedSQL(java.lang.String sqlstmt)
sqlstmt
- (String) The sql statement that is to be revised.public java.lang.String getRevisedSQLForTestOnly(java.lang.String sqlname, java.lang.String sqlstmt)
FOR TESTING ONLY. NOT INTENDED FOR PRODUCTION.
sqlname
- (String) The sql collection name that is to be used for
testing the revisions.sqlstmt
- (String) The sql statement that is to be revised.public java.lang.String getSQLName()
private void initializePool(int initconns) throws java.lang.Exception
initconns
- (int) The number of initial connections.java.lang.Exception
- - if an error occurs while opening the
connections.private void initializeTableNames() throws java.lang.Exception
ivTableNames
array list with the table names and view names that
exist in the database associated with this connection pool.java.lang.Exception
- - if an error occurs while creating the
collection.private boolean isConnectionOK(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The connection info object to check.true
if the connection info object is okay,
otherwise false
.public boolean isDB2e()
true
if this is a DB2 Everyplace database,
otherwise false
.public boolean isDB2i()
true
if this is a DB2 System i database,
otherwise false
.public boolean isDB2iNative()
true
if this is a DB2 System i native database,
otherwise false
.public boolean isDB2w()
true
if this is a DB2 Windows database,
otherwise false
.public boolean isDerby()
true
if this is an Apache Derby database,
otherwise false
.private JDBCConnectionInfo newConnection() throws java.sql.SQLException
java.sql.SQLException
- - if a connection info object cannot be created.public void release()
private java.lang.String reviseForSQLName(java.lang.String sqlname, java.lang.String sqlstmt)
sqlname
- (String) The sql collection name that is to be used for
the insertions.sqlstmt
- (String) The sql statement that is to revised.private boolean searchTableNames(java.lang.String name)
ivTableNames
contains a given name, regardless of case.name
- (String) The table or view name to be searched for.true
if the name was found, otherwise
false
.private void addToUsedList(JDBCConnectionInfo cninf, java.lang.String consumer)
cninf
- (JDBCConnectionInfo) The connection info object to add to
the list.consumer
- (String) The connection's consumer.private java.lang.String removeFromUsedList(JDBCConnectionInfo cninf)
cninf
- (JDBCConnectionInfo) The connection info object to remove
from the list.