planetj.database.connection
Class DataEngineConnectionPool

java.lang.Object
  |
  +--planetj.database.connection.DataEngineConnectionPool
All Implemented Interfaces:
DataEngineDataSource, javax.sql.DataSource, Runnable

public final class DataEngineConnectionPool
extends Object
implements Runnable, DataEngineDataSource


Nested Class Summary
static class DataEngineConnectionPool.RunningTotal
           
 
Field Summary
static int INFINITE_ORPHAN_TIMEOUT
           
static Comparator RUNNING_TOTAL_AVERAGE_COMPARATOR
           
 
Constructor Summary
DataEngineConnectionPool(String driver, String server, String pAlias, String login, String password, int minConnections, int maxConnections, int maxConnSeconds, int orphanTimeout)
           
 
Method Summary
 void addListener(IConnectionListener listener)
          Adds a listener to this connection pool
 void destroy()
          Closes down this connection pool.
 void destroy(int pMaxWaitMilliseconds)
          Closes down this connection pool.
 String dump()
          Method used for debugging purposes.
 String dumpHTML()
          Method used for debugging purposes.
 boolean freeConnection(Connection connection)
          Frees a connection, returning it to the pool so others can use it.
 ConnectionPoolReport generateApproximateReport()
          Creates a ConnectionPoolReport from the information in this connection pool.
 ConnectionPoolReport generateExactReport(boolean clearStatistics)
          Creates a ConnectionPoolReport from the information in this connection pool.
 long getAge(DataEngineConnection connection)
           
 String getAlias()
          Gets the alias for the database system to which this connection pool's connections are conntected.
 Connection getConnection()
          Gets an available connection from the connection pool
 Connection getConnection(DataEngineConnection connection)
          Attempts to get the specified connection from the connection pool
 Connection getConnection(String sql)
          Gets a Connection which will be used to execute the specified SQL.
 Connection getConnection(String userID, String password)
          Gets a connection for the specified userid and password.
 int[] getConnectionUsageCounts()
          Returns information about the amount of usage this connection pool has seen.
 String getCreationTimeText()
          Gets a String containing the time the pool was created.
 DataEngineConnectionPool.RunningTotal getGrandTotal()
          Gets information about all sql statements run from this connection pool.
 int getLoginTimeout()
          Gets the amount of time this ConnectionPool will wait as it attempts to login to the database.
 PrintWriter getLogWriter()
          Gets the print writer used for logging.
 int getMaximumConnections()
          Gets the maximum size of this connection pool.
 int getMinimumConnections()
          Gets the minimum size of this connection pool.
 PreparedStatementManager getPreparedStatementManager()
          Gets this connection pool's prepared statement manager
 DataEngineConnectionPool.RunningTotal getQueryTotal()
          Gets information about queries run from this connection pool.
 ConnectionPoolReportDescriptor getReportDescriptor()
          Gets the report descriptor for this connection pool
 int getSize()
          Gets the number of connections in this connection pool.
 Map getStatementMap()
          Gets the Map of statements that have been executed from this connection pool
 int getTimeoutSeconds()
          If no connections have been retrieved from this connection pool after this amount of time, then this connection pool will close itself.
 DataEngineConnectionPool.RunningTotal getUpdateTotal()
          Gets information about updates run from this connection pool.
 String getURL()
          Gets the url for the database system to which this connection pool's connections are conntected.
 int getUseCount()
          Gets the number of connections in this connection pool that are currently in use.
 DataEngineConnectionPool.RunningTotal getWaitTotal()
          Gets information about the connection requests that have had to wait (from this connection pool).
static int idOfConnection(DataEngineConnection connection)
           
 boolean isAvailable()
          Tests if this connection pool is available for use
 void queryExecuted(String sql, long begin, long time)
          Records a query that has executed, and the time it took to execute.
 void reconnect()
          Shuts down all of the connections in the connection pool and restarts them.
 void reconnect(int pMaxWaitMilliseconds)
          Shuts down all of the connections in the connection pool and restarts them.
 void removeListener(IConnectionListener listener)
          Removes a listener from this connection pool
 void run()
           
 void setLoginTimeout(int arg1)
          Sets the amount of time this connection pool will wait for when attempting to login to the database.
 void setLogWriter(PrintWriter arg1)
          Sets the print writer used for logging.
 void setReportDescriptor(ConnectionPoolReportDescriptor descriptor)
          Sets the report descriptor for this connection pool
 void setTimeoutSeconds(int newTimeoutSeconds)
          If no connections have been retrieved from this connection pool after this amount of time, then this connection pool will close itself.
 void statementExecuted(String sql, long begin, long time)
          Records a statement that has executed, and the time it took to execute.
 void updateExecuted(String sql, long begin, long time)
          Records an update that has executed, and the time it took to execute.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INFINITE_ORPHAN_TIMEOUT

public static final int INFINITE_ORPHAN_TIMEOUT
See Also:
Constant Field Values

RUNNING_TOTAL_AVERAGE_COMPARATOR

public static final Comparator RUNNING_TOTAL_AVERAGE_COMPARATOR
Constructor Detail

DataEngineConnectionPool

public DataEngineConnectionPool(String driver,
                                String server,
                                String pAlias,
                                String login,
                                String password,
                                int minConnections,
                                int maxConnections,
                                int maxConnSeconds,
                                int orphanTimeout)
                         throws SQLException
Method Detail

addListener

public void addListener(IConnectionListener listener)
Adds a listener to this connection pool


destroy

public void destroy()
Closes down this connection pool. Connections that are in use when this method is invoked are given 10 seconds to be freed before they are forcibly shut down.


destroy

public void destroy(int pMaxWaitMilliseconds)
Closes down this connection pool.

Parameters:
pMaxWaitMilliseconds - The maximum time to wait for connections which are in use when this method is invoked to be freed. After this amount of time, any connections still in use are forcible shut down.

dump

public String dump()
Method used for debugging purposes. Outputs all information for each connection contained within the connection pool.


dumpHTML

public String dumpHTML()
Method used for debugging purposes. Outputs all information for each connection contained within the connection pool. This will be outputed in HTML format


freeConnection

public boolean freeConnection(Connection connection)
Frees a connection, returning it to the pool so others can use it.

Parameters:
connection - The connection to free
Returns:
true if the connection was freed, false otherwise

generateApproximateReport

public ConnectionPoolReport generateApproximateReport()
Creates a ConnectionPoolReport from the information in this connection pool. This method does not lock the connection pool as it generates the report, so individual statistics in the report may reflect the connection pool's state at slightly different points in time. The generateExactReport() method captures the connection pool's state at a single point in time.

Returns:
The ConnectionPoolReport containing information about how this connection pools was used, or null if monitoring is turned off.

generateExactReport

public ConnectionPoolReport generateExactReport(boolean clearStatistics)
Creates a ConnectionPoolReport from the information in this connection pool. This method locks the connection pool as it generates the report (this may slightly hurt performance, but ensures a more accurate report).

Parameters:
clearStatistics - If all of the stored performance statistics should be cleared after the report is generated.
Returns:
The ConnectionPoolReport containing information about how this connection pools was used, or null if monitoring is turned off.

getAge

public long getAge(DataEngineConnection connection)

getAlias

public String getAlias()
Gets the alias for the database system to which this connection pool's connections are conntected.


getConnection

public Connection getConnection()
                         throws SQLException
Gets an available connection from the connection pool

Specified by:
getConnection in interface javax.sql.DataSource
SQLException

getConnection

public Connection getConnection(String sql)
                         throws DataEngineException
Gets a Connection which will be used to execute the specified SQL. The returned Connection may be selected from all of the available connections based on the SQL statement passed in

Specified by:
getConnection in interface DataEngineDataSource
DataEngineException

getConnection

public Connection getConnection(String userID,
                                String password)
                         throws SQLException
Gets a connection for the specified userid and password. This method is not supported.

Specified by:
getConnection in interface javax.sql.DataSource
SQLException

getConnection

public Connection getConnection(DataEngineConnection connection)
                         throws DataEngineException
Attempts to get the specified connection from the connection pool

Returns:
If the connection is available, it is checked out from the pool and returned. If not, null is returned.
DataEngineException

getConnectionUsageCounts

public int[] getConnectionUsageCounts()

Returns information about the amount of usage this connection pool has seen. In the returned array, the value at position x indicates the number of times a connection was requested when x connections were already in use. So the value at position 0 is how many times a connection was requested when no connections were in use. The value at position 1 is the number of times a connection was requested when 1 connection was already in use, and so on.

The total sum of all the values in the array is the total number of connections that have been requested.

This method is not synchronized, so the values may not represent the exact state of the connection pool at any specific time


getCreationTimeText

public String getCreationTimeText()
Gets a String containing the time the pool was created.


getGrandTotal

public DataEngineConnectionPool.RunningTotal getGrandTotal()
Gets information about all sql statements run from this connection pool.


getLoginTimeout

public int getLoginTimeout()
                    throws SQLException
Gets the amount of time this ConnectionPool will wait as it attempts to login to the database. This method is not supported

Specified by:
getLoginTimeout in interface javax.sql.DataSource
SQLException

getLogWriter

public PrintWriter getLogWriter()
                         throws SQLException
Gets the print writer used for logging. This method is not supported

Specified by:
getLogWriter in interface javax.sql.DataSource
SQLException

getMaximumConnections

public int getMaximumConnections()
Gets the maximum size of this connection pool.


getMinimumConnections

public int getMinimumConnections()
Gets the minimum size of this connection pool.


getPreparedStatementManager

public PreparedStatementManager getPreparedStatementManager()
Gets this connection pool's prepared statement manager


getQueryTotal

public DataEngineConnectionPool.RunningTotal getQueryTotal()
Gets information about queries run from this connection pool.


getReportDescriptor

public ConnectionPoolReportDescriptor getReportDescriptor()
Gets the report descriptor for this connection pool


getSize

public int getSize()
Gets the number of connections in this connection pool. This method is not synchronized - other threads may see a different value.


getStatementMap

public Map getStatementMap()
Gets the Map of statements that have been executed from this connection pool


getTimeoutSeconds

public int getTimeoutSeconds()
If no connections have been retrieved from this connection pool after this amount of time, then this connection pool will close itself. (The exact amount of inactive time that must pass before this pool is shutdown will vary, but it will be equal to or greater than this value.) A negative value indicates that this connection pool will not shut down due to inactivity.


getUpdateTotal

public DataEngineConnectionPool.RunningTotal getUpdateTotal()
Gets information about updates run from this connection pool.


getURL

public String getURL()
Gets the url for the database system to which this connection pool's connections are conntected.


getUseCount

public int getUseCount()
Gets the number of connections in this connection pool that are currently in use. This method is not synchronized - other threads may see a different value


getWaitTotal

public DataEngineConnectionPool.RunningTotal getWaitTotal()
Gets information about the connection requests that have had to wait (from this connection pool). The RunningTotal keeps track of the amount of time that connection requests have had to wait (because when they first came in there were no available connections). Only connection requests that were forced to wait are represented in the returned RunningTotal.


idOfConnection

public static int idOfConnection(DataEngineConnection connection)

isAvailable

public boolean isAvailable()
Tests if this connection pool is available for use


queryExecuted

public void queryExecuted(String sql,
                          long begin,
                          long time)
Records a query that has executed, and the time it took to execute.

Parameters:
sql - The sql statement that was executed.
begin - When the query was initiated
time - The time it took to execute. This should be less than 0 if and only if the query execution failed.

reconnect

public void reconnect()
               throws SQLException
Shuts down all of the connections in the connection pool and restarts them. Connections which are in use when this method is invoked are given 10 seconds to be freed by the application using them before they are forcibly shut down.

SQLException

reconnect

public void reconnect(int pMaxWaitMilliseconds)
               throws SQLException
Shuts down all of the connections in the connection pool and restarts them.

Parameters:
pMaxWaitMilliseconds - The maximum time to wait for connections which are in use to be freed. After this amount of time, any connections still in use are forcibly shut down.
SQLException

removeListener

public void removeListener(IConnectionListener listener)
Removes a listener from this connection pool


run

public void run()
Specified by:
run in interface Runnable

setLoginTimeout

public void setLoginTimeout(int arg1)
                     throws SQLException
Sets the amount of time this connection pool will wait for when attempting to login to the database. This method is not supported.

Specified by:
setLoginTimeout in interface javax.sql.DataSource
SQLException

setLogWriter

public void setLogWriter(PrintWriter arg1)
                  throws SQLException
Sets the print writer used for logging. This method is not supported

Specified by:
setLogWriter in interface javax.sql.DataSource
SQLException

setReportDescriptor

public void setReportDescriptor(ConnectionPoolReportDescriptor descriptor)
Sets the report descriptor for this connection pool


setTimeoutSeconds

public void setTimeoutSeconds(int newTimeoutSeconds)
If no connections have been retrieved from this connection pool after this amount of time, then this connection pool will close itself. (The exact amount of inactive time that must pass before this pool is shutdown will vary, but it will be equal to or greater than this value.) A negative value indicates that this connection pool will not shut down due to inactivity.


statementExecuted

public void statementExecuted(String sql,
                              long begin,
                              long time)
Records a statement that has executed, and the time it took to execute.

Parameters:
sql - The sql statement that was executed.
begin - When the statement was executed
time - The time it took to execute. This should be less than 0 if and only if the query execution failed.

updateExecuted

public void updateExecuted(String sql,
                           long begin,
                           long time)
Records an update that has executed, and the time it took to execute.

Parameters:
sql - The sql statement that was executed.
begin - When the update was initiated
time - The time it took to execute. This should be less than 0 if and only if the query execution failed.