|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.osesb.utilities.jdbc.DriverConnectionManager
public class DriverConnectionManager
DriverConnectionManager is an implementation of IConnectionManager that starts and maintains a plain old JDBC connection using java.sql.DriverManagerDriver and properties in a JDBCConfiguration.
The purpose of a IConnectionManager is to hide how database connections are managed. Components that use a IConnectionManager call getConnection() and releaseConnection() and do not need to determine whether the connection is returned by a java.sqlDriverManager or a javax.sql DataDource. A DriverConnectionManager can be constructed directly using a JDBCConfiguration or the createConnectionManager() method in JDBCConfiguration can be invoked to return a DriverConnectionManager. Optionally, this class will periodically test the managed connection. If jdbcConfiguration.getdbPingIntervalSeconds() > 0, this object starts a Thread that periodically tests the JDBC connection. If the test fails, then the connection is re-established. Use reset() to close the managed connection. Use stop() to end the DriverConnectionManager thread and close the connection. Note: Each JDBC connection creates a separate backend agent that serves as the context for a Connection. The Java connection and statement objects are thread safe, and access to the connection is serialized.
| Field Summary | |
|---|---|
protected java.sql.Connection |
dbConn
the DB connection. |
protected long |
dbPingIntervalSeconds
If dbPingIntervalSeconds > 0, dbPingThread periodically tests dbConn and the connection is re-established, if needed. |
protected java.lang.String |
dbPingSQLStatement
If dbPingIntervalSeconds > 0, then DriverConnectionManager starts a Thread that periodically tests dbConn and the connection is re-established, if needed. |
protected java.lang.Thread |
dbPingThread
If dbPingIntervalSeconds > 0, then when DriverConnectionManager creates a connection, it starts a Thread that periodically tests dbConn and the connection is re-established, if needed. |
protected JDBCConfiguration |
jdbcConfiguration
The JDBCConfiguration properties. |
protected java.lang.String |
thisClassName
The full name of this class. |
protected java.util.Date |
timeDBPingThreadStarted
The time dbPingThread started. |
| Constructor Summary | |
|---|---|
DriverConnectionManager(JDBCConfiguration jdbcConfiguration)
Creates a new DriverConnectionManager with the given JDBC Configuration. |
|
| Method Summary | |
|---|---|
protected void |
closeConnection()
Close the configured database connection. |
protected void |
createConnection()
Creates a new database connection for this DriverConnectionManager according to the connection properties in jdbcConfiguration and starts a dbPingThread if dbPingIntervalSeconds > 0. |
protected void |
dbPing()
Test the configured database connection. |
void |
finalize()
just maybe... |
java.sql.Connection |
getConnection()
Returns the database connection, according to the properties in jdbcConfiguration, creating a new connection, if necessary. |
long |
getDbPingIntervalSeconds()
Return dbPingIntervalSeconds, which is the interval between tests of database connection. |
protected java.lang.String |
getDbPingSQLStatement()
Return dbPingSQLStatement, which is the SQL statement used to test the database connection. |
static void |
main(java.lang.String[] args)
Main method for testing. |
void |
releaseConnection(java.sql.Connection dbConn)
Releases the database connection. |
void |
reset()
Resets the connection manager. |
void |
run()
Test the configured database connection at intervals specifiec by dbPingIntervalSeconds. |
void |
setDbPingIntervalSeconds(long dbPingIntervalSeconds)
Set dbPingIntervalSeconds, which is the interval between tests of database connection. |
protected void |
setDbPingSQLStatement(java.lang.String dbPingSQLStatement)
Set dbPingSQLStatement, which is the SQL statement used to test the database connection. |
void |
stop()
End DriverConnectionManager#run() and closeConnection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.lang.String thisClassName
protected JDBCConfiguration jdbcConfiguration
protected java.sql.Connection dbConn
protected long dbPingIntervalSeconds
protected java.lang.String dbPingSQLStatement
protected java.lang.Thread dbPingThread
createConnection()protected java.util.Date timeDBPingThreadStarted
| Constructor Detail |
|---|
public DriverConnectionManager(JDBCConfiguration jdbcConfiguration)
throws java.lang.Exception
jdbcConfiguration - The JDBCConfiguration to use for this
DriverConnectionManager.
java.lang.Exception - if constructed with a null jdbcConfiguration.| Method Detail |
|---|
public java.sql.Connection getConnection()
throws java.lang.Exception
getConnection in interface IConnectionManagerjava.lang.Exception - if an error occurs while loading the JDBC driver
or obtaining a connection.
protected void createConnection()
throws java.lang.Exception
java.lang.Exception - if an error occurs while loading the JDBC driver
or obtaining a connection.public void releaseConnection(java.sql.Connection dbConn)
releaseConnection in interface IConnectionManagerdbConn - A Connection obtained using a previous call
to getConnection().public void reset()
reset in interface IConnectionManagerpublic void run()
run in interface java.lang.Runnableprotected void dbPing()
public void stop()
stop in interface IConnectionManagerprotected void closeConnection()
public long getDbPingIntervalSeconds()
public void setDbPingIntervalSeconds(long dbPingIntervalSeconds)
dbPingIntervalSeconds - the interval, in seconds,
between tests of the database connection.protected java.lang.String getDbPingSQLStatement()
protected void setDbPingSQLStatement(java.lang.String dbPingSQLStatement)
dbPingSQLStatement - The SQL statement that is used to test the
database connection.public void finalize()
finalize in class java.lang.Objectpublic static void main(java.lang.String[] args)
args - The test data directory.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||