|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--planetj.database.DatabaseManager
Manages the Connections to one or more databases. Creating a new database connection is costly, so
this class maintains a connection pool for each database. Applications use the
getConnection(String)
method to get a Connection object for a
database, and the freeConnection()
method to return a Connection
to the connection pool when they are through with it. The close()
method of a Connection can also be invoked to return that Connection to the connection pool.
It is important for applications to return any Connections they get from the pool. Any section of code
that gets and uses a Connection should be enclosed in a try{} statement, and the Connection returned
to the pool in a finally{} statement; that way the Connection will always be returned,
even if an exception occurs.
Field Summary | |
static byte |
ACTION_RESTART_CONNECTION_POOL
Constant for restarting a connection pool |
static byte |
ACTION_START_CONNECTION_POOL
Constant for starting a connection pool |
static byte |
ACTION_STOP_CONNECTION_POOL
Constant for stopping a connection pool |
Constructor Summary | |
DatabaseManager()
|
Method Summary | |
static void |
addConnectionListener(String alias,
IConnectionListener listener)
Adds a IConnectionListener to a connection pool |
static ConnectionPoolReportDescriptor |
beginReportMonitoring(ConnectionPoolReportDescriptor pReportDescriptor)
Attaches a report descriptor to a connection pool. |
static void |
closeConnectionPool(String systemAlias)
Closes a ConnectionPool, releasing all of its connections. |
static void |
closeConnectionPool(String systemAlias,
int seconds)
Waits the specified amount of time, and then closes a ConnectionPool, releasing all of its connections. |
static int |
connectionId(String systemURL,
Connection conn)
Deprecated. |
static void |
createConnectionPool(ConnectionRow pConnectionRow)
|
static void |
createConnectionPool(String driver,
DBSystem system,
String user,
String password,
int minConnections,
int maxConnections,
int maxConnSeconds,
int orphanTimeout)
Creates and returns a new DataEngineConnectionPool using the given properties. |
static void |
createConnectionPool(String driver,
DBSystem system,
String user,
String password,
int minConnections,
int maxConnections,
int maxConnSeconds,
int orphanTimeout,
String connectionAlias)
Creates and returns a new DataEngineConnectionPool using the given properties. |
static void |
createConnectionPool(String pSystemAlias,
String pSystemAliasForLookUp)
Creates a ConnectionPool with the specifed system alias. |
static void |
createConnectionPool(String driver,
String systemURL,
String urlAlias,
String user,
String password,
int minConnections,
int maxConnections,
int maxConnSeconds,
int orphanTimeout)
Creates and returns a new DataEngineConnectionPool using the given properties. |
static void |
createDataSource(String JNDIName)
Creates a datasource based on a given JNDI name. |
static void |
createDataSource(String JNDIName,
Class systemClass)
Creates a datasource based on a given JNDI name. |
static void |
createDataSource(String JNDIName,
Class systemClass,
String userID,
String password)
Creates a datasource based on a given JNDI name. |
static boolean |
doesConnectionPoolExist(String systemAlias)
Returns whether or not a connection pool already exists for the specified system alias |
static String |
dump()
|
static String |
dump(String alias)
|
static void |
freeConnection(Connection conn)
Frees up the given connection in the connection pool identified by the given key. |
static void |
freeConnection(String pSystemAlias,
Connection pConnection)
Deprecated. Use the single argument method instead |
static ConnectionPoolReport |
generateReport(String alias)
Generates a report about a connection pool. |
static Map |
getAllConnectionPools()
Gets all of the connection pools. |
static Connection |
getConnection(String pAlias)
Returns a connection associated with the given alias |
static int |
getRetryAttempts()
If the first attempt to get a connection fails, this many retry attempts will be made before giving up and throwing an exception. |
static int |
getRetryMillis()
If the first attempt to get a connection fails, this many milliseconds will elapse between retries. |
static boolean |
isConnectionPoolAvailable(String pAlias)
Deprecated. use isDataSourceAvailable instead |
static boolean |
isDataSourceAvailable(String pAlias)
Tests if a datasource with the given name exists and is available. |
static boolean |
isUseBackgoundThreads()
Tests if the DatabaseManager should use background threads to retrieve Library and Table objects before they are requested. |
static boolean |
performConnectionPoolAction(String alias,
byte action)
Performs an action on a connection pool |
static void |
reconnect(String pAlias)
Shuts down all of the connections in the specified connection pool and restarts them. |
static void |
reconnect(String pAlias,
int pMaxWaitMilliseconds)
Shuts down all of the connections in the specified connection pool and restarts them. |
static void |
removeConnectionListener(String alias,
IConnectionListener listener)
Removes a IConnectionListener from a connection pool |
static void |
restartConnectionPool(String alias)
If the specified connection pool is started it is shut down and restarted. |
static void |
setRetryAttempts(int newRetryAttempts)
If the first attempt to get a connection fails, this many retry attempts will be made before giving up and throwing an exception. |
static void |
setRetryMillis(int newRetryMillis)
If the first attempt to get a connection fails, this many milliseconds will elapse between retries. |
static void |
setTimeoutSeconds(String alias,
int seconds)
If no connections have been retrieved from the connection pool after this amount of time, then the connection pool will close itself. |
static void |
setUseBackgoundThreads(boolean newUseBackgoundThreads)
Tests if the DatabaseManager should use background threads to retrieve Library and Table objects before they are requested. |
static void |
shutDownConnectionPool(String systemURL)
Deprecated. Use closeConnectionPool(String) instead |
static void |
toggleStatus(ConnectionRow crow)
Starts up the specified connection pool if it is not already started. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final byte ACTION_START_CONNECTION_POOL
public static final byte ACTION_STOP_CONNECTION_POOL
public static final byte ACTION_RESTART_CONNECTION_POOL
Constructor Detail |
public DatabaseManager()
Method Detail |
public static void addConnectionListener(String alias, IConnectionListener listener)
public static ConnectionPoolReportDescriptor beginReportMonitoring(ConnectionPoolReportDescriptor pReportDescriptor) throws CMException
CMException
public static void closeConnectionPool(String systemAlias)
public static void closeConnectionPool(String systemAlias, int seconds)
public static int connectionId(String systemURL, Connection conn) throws DataEngineException
systemURL
- Stringconn
- Connection
DataEngineException
public static void createConnectionPool(String pSystemAlias, String pSystemAliasForLookUp) throws CMException
pSystemAlias
- The alias to use for reading the Connection tablepSystemAliasForLookUp
- The alias for the ConnectionPools that will be created
CMException
public static void createConnectionPool(String driver, String systemURL, String urlAlias, String user, String password, int minConnections, int maxConnections, int maxConnSeconds, int orphanTimeout) throws CMException
driver
- StringsystemURL
- StringurlAlias
- Stringuser
- Stringpassword
- StringminConnections
- intmaxConnections
- int
CMException
public static void createConnectionPool(String driver, DBSystem system, String user, String password, int minConnections, int maxConnections, int maxConnSeconds, int orphanTimeout) throws CMException
driver
- Stringsystem
- DBSystemuser
- Stringpassword
- StringminConnections
- intmaxConnections
- int
CMException
public static void createConnectionPool(String driver, DBSystem system, String user, String password, int minConnections, int maxConnections, int maxConnSeconds, int orphanTimeout, String connectionAlias) throws CMException
driver
- Stringsystem
- DBSystemuser
- Stringpassword
- StringminConnections
- intmaxConnections
- int
CMException
public static void createConnectionPool(ConnectionRow pConnectionRow) throws CMException
CMException
public static void createDataSource(String JNDIName) throws DataEngineException
DataEngineException
public static void createDataSource(String JNDIName, Class systemClass) throws DataEngineException
DataEngineException
public static void createDataSource(String JNDIName, Class systemClass, String userID, String password) throws DataEngineException
DataEngineException
public static boolean doesConnectionPoolExist(String systemAlias)
systemAlias
- The alias for which a connection pool may or may not existpublic static String dump()
public static String dump(String alias)
public static void freeConnection(String pSystemAlias, Connection pConnection)
public static void freeConnection(Connection conn)
conn
- Connectionpublic static ConnectionPoolReport generateReport(String alias) throws CMException
CMException
public static Map getAllConnectionPools()
public static Connection getConnection(String pAlias) throws DataEngineException
pAlias
- The alias for the system to connect to
DataEngineException
public static int getRetryAttempts()
public static int getRetryMillis()
public static boolean isConnectionPoolAvailable(String pAlias)
public static boolean isDataSourceAvailable(String pAlias)
public static boolean isUseBackgoundThreads()
public static boolean performConnectionPoolAction(String alias, byte action) throws CMException
alias
- The alias of the connection pool on which the action should be performedaction
- The action that should be taken
CMException
- Thrown if an error occurs while performing the actionpublic static void reconnect(String pAlias) throws CMException
pAlias
- The alias of the connection pool to reconnect to
CMException
public static void reconnect(String pAlias, int pMaxWaitMilliseconds) throws CMException
pAlias
- The alias of the connection pool to reconnect topMaxWaitMilliseconds
- 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.
CMException
public static void removeConnectionListener(String alias, IConnectionListener listener)
public static void restartConnectionPool(String alias) throws CMException
CMException
public static void setRetryAttempts(int newRetryAttempts)
public static void setRetryMillis(int newRetryMillis)
public static void setTimeoutSeconds(String alias, int seconds)
public static void setUseBackgoundThreads(boolean newUseBackgoundThreads)
public static void shutDownConnectionPool(String systemURL) throws DataEngineException
systemURL
- String
DataEngineException
public static void toggleStatus(ConnectionRow crow) throws CMException
CMException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |