|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.jwarp.service.connectionpool.ConnectionPool
The connection pool pools connections to a database. When initializing an initial number of connections where opened. Each pool is generateed out of the configuration date (typically read in through a configuration file). The format for defining a database pool is:
| Name of value | Description |
| name | Name of the connection pool |
| DBPOOL.UPDATETIME | The update time in ms (for releasing too many free connections) |
| DBPOOL.name.URL | JDBC url to connect to the database |
| DBPOOL.name.USER | User id for the database connection |
| DBPOOL.name.PASSWORD | Password for connecting to the database |
| DBPOOL.name.MAXCONNS | Max number of connection this pool will create |
| DBPOOL.name.INITCONNS | Initial number of connections made to database when pool is initialised |
| DBPool.name.MAXFREECONNS | The maximal number of free connection so some connections will be removed from the pool. |
| DBPOOL.name.RELEASECONNS | Determines how many connections will be released if too many free connections are available (see MAXFREECONNS setting) |
| DBPOOL.name.TIMEOUT | Timeout in seconds for login to database |
| DBPOOL.name.INITSTATEMENT | Initial SQL statement. This statement can be used to initialise the connection with some cutomized code, e.g. setting the default date format used within the application. |
| DBPOOL.name.LOGTARGET | The target log writer. |
The connections given back by the pool methods are additionally wrapped within the ConnectionWrapper class. A call to the method connection.close() finally gives the connection back to the pool instead of closing it physically.
ConnectionWrapper| Constructor Summary | |
ConnectionPool(org.jdom.Element config)
Creates a new pool named poolName. |
|
ConnectionPool(java.lang.String name,
java.lang.String URL,
java.lang.String user,
java.lang.String password,
int maxConns,
int initConns,
int timeOut,
java.lang.String logTarget)
This creates a ConnectionPool. |
|
ConnectionPool(java.lang.String name,
java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxConns,
int initConns,
int timeOut,
java.lang.String initStatement,
java.lang.String logTarget)
This creates a ConnectionPool. |
|
| Method Summary | |
void |
checkFreeConnections()
Checkes for too many free connections. |
int |
getBusyConnectionCount()
Returns the current active connections count. |
java.sql.Connection |
getConnection()
Returns a connection from the pool. |
java.sql.Connection |
getConnection(java.lang.String username,
java.lang.String password)
Attempt to establish a database connection. |
int |
getFreeConnectionCount()
Returns the number of free connections |
int |
getLoginTimeout()
Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. |
java.io.PrintWriter |
getLogWriter()
Get the log writer for this data source. |
int |
getMaxFreeConnections()
Returns the number of free connections so some connections may be released. |
java.lang.String |
getName()
Returns the name of the pool. |
int |
getReleaseSize()
Returns the number of connections released in a update count when there are too many free connections. |
java.lang.String |
getUid()
Returns the user id for connecting to the database. |
java.lang.String |
getUrl()
Returns the connection url. |
void |
loadPool(org.jdom.Element config)
This method actually loads the pool from the properties. |
void |
release()
This method will physically close all free connections. |
void |
setAccess(java.lang.String newUid,
java.lang.String newPwd)
Changed the uid and password for connecting to the database. |
void |
setInitStatement(java.lang.String statement)
Set init-Statement executed for each new connection within this pool. |
void |
setLoginTimeout(int seconds)
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. |
void |
setLogWriter(java.io.PrintWriter out)
Set the log writer for this data source. |
void |
setMaxFreeConnections(int val)
Sets the maximal number of free connections so an release is triggered. |
void |
setReleaseSize(int val)
Sets the number of connections released when there are too many connections. |
void |
setUrl(java.lang.String newUrl)
Changed the database url. |
(package private) void |
wrapperClosed(java.sql.Connection conn)
This is called from a connection wrapper object when the ConnectionWrapper.close() method was called. |
| Constructor Detail |
public ConnectionPool(java.lang.String name,
java.lang.String URL,
java.lang.String user,
java.lang.String password,
int maxConns,
int initConns,
int timeOut,
java.lang.String logTarget)
Name - of the pool.Connection - url for connecting to the databaseUser - used to connect to the databasePassword - used to connect to the databaseMaximal - number of connections this pool will create.Initial - number of connection this pool will create upon initialisation.Login - timeout in seconds
public ConnectionPool(java.lang.String name,
java.lang.String url,
java.lang.String user,
java.lang.String password,
int maxConns,
int initConns,
int timeOut,
java.lang.String initStatement,
java.lang.String logTarget)
Name - of the pool.Connection - url for connecting to the databaseUser - used to connect to the databasePassword - used to connect to the databaseMaximal - number of connections this pool will create.Initial - number of connection this pool will create upon initialisation.Login - timeout in secondsString - which is send as an init statement for each newly created connection.
public ConnectionPool(org.jdom.Element config)
throws PoolInitException
| Name of value | Description |
| DBPOOL.name.URL | JDBC url to connect to the database |
| DBPOOL.name.USER | User id for the database connection |
| DBPOOL.name.PASSWORD | Password for connecting to the database |
| DBPOOL.name.MAXCONNS | Max number of connection this pool will create |
| DBPOOL.name.INITCONNSonns | Initial number of connections made to database when pool is initialised |
| DBPOOL.name.TIMEOUT | Timeout in seconds for login to database |
| DBPOOL.name.INITSTAEMENT | Initial SQL statement. This statement can be used to initialise the connection with some cutomized code, e.g. setting the default date format used within the application. |
PoolManager| Method Detail |
public void loadPool(org.jdom.Element config)
throws PoolInitException
the - propertiesPoolInitException - If the pool can not be instantiated.public void setInitStatement(java.lang.String statement)
The - initial SQL statement.
public java.sql.Connection getConnection()
throws java.sql.SQLException
java.sql.SQLException - MaxConnectException - if no more connections can be created and all connections are currently checked outConnectionWrappervoid wrapperClosed(java.sql.Connection conn)
conn - The connection wrapperConnectionWrapperpublic int getFreeConnectionCount()
public int getBusyConnectionCount()
public void checkFreeConnections()
ConnectionPoolUpdateThreadpublic int getMaxFreeConnections()
public int getReleaseSize()
public void setMaxFreeConnections(int val)
val - The maximum connection countpublic void setReleaseSize(int val)
val - The valuepublic void release()
public java.lang.String getUid()
public java.lang.String getUrl()
public java.lang.String getName()
public void setUrl(java.lang.String newUrl)
The - new database connection url.
public void setAccess(java.lang.String newUid,
java.lang.String newPwd)
The - new uid.The - new password.
public java.sql.Connection getConnection(java.lang.String username,
java.lang.String password)
throws java.sql.SQLException
Attempt to establish a database connection.
user - the database user on whose behalf the Connection is
being madepassword - the user's passwordjava.sql.SQLException - if a database-access error occurs.
public java.io.PrintWriter getLogWriter()
throws java.sql.SQLException
Get the log writer for this data source.
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.
java.sql.SQLException - if a database-access error occurs.
public void setLogWriter(java.io.PrintWriter out)
throws java.sql.SQLException
Set the log writer for this data source.
The log writer is a character output stream to which all logging and tracing messages for this data source object instance will be printed. This includes messages printed by the methods of this object, messages printed by methods of other objects manufactured by this object, and so on. Messages printed to a data source specific log writer are not printed to the log writer associated with the java.sql.Drivermanager class. When a DataSource object is created the log writer is initially null, in other words, logging is disabled.
out - the new log writer; to disable, set to nulljava.sql.SQLException - if a database-access error occurs.
public void setLoginTimeout(int seconds)
throws java.sql.SQLException
Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. A value of zero specifies that the timeout is the default system timeout if there is one; otherwise it specifies that there is no timeout. When a DataSource object is created the login timeout is initially zero.
seconds - the data source login time limitjava.sql.SQLException - if a database access error occurs.
public int getLoginTimeout()
throws java.sql.SQLException
java.sql.SQLException - if a database access error occurs.
|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||