|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.caucho.sql.DBPool
Manages a pool of database connections. In addition, DBPool configures the database connection from a configuration file.
Like JDBC 2.0 pooling, DBPool returns a wrapped Connection.
Applications can use that connection just like an unpooled connection.
It is more important than ever to close()
the connection,
because the close returns the connection to the connection pool.
DBPool pool = DBPool.getPool("test");
Connection conn = pool.getConnection();
try {
... // normal connection stuff
} finally {
conn.close();
}
Connection conn = DriverManager.getConnection("jdbc:caucho:test");
try {
... // normal connection stuff
} finally {
conn.close();
}
<dbpool.sql id='test'
driver="postgresql.Driver"
url="jdbc:postgresql://localhost/test"
user="ferg"
password="foobar"/>
Connections will only stay in the pool for about 5 seconds. After that they will be removed and closed. This reduces the load on the DB and also protects against the database dropping old connections.
Field Summary | |
static java.lang.String |
PROPERTY_PASSWORD
The key used to look into the properties passed to the connect method to find the password. |
static java.lang.String |
PROPERTY_USER_NAME
The key used to look into the properties passed to the connect method to find the username. |
Constructor Summary | |
DBPool(java.lang.String poolName,
java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String driverName,
java.lang.ClassLoader loader,
int maxConnections)
|
Method Summary | |
boolean |
acceptsURL(java.lang.String url)
Returns true if the driver thinks that it can open a connection to the given URL. |
void |
close()
|
java.sql.Connection |
connect(java.lang.String url,
java.util.Properties info)
Attempts to make a database connection to the given URL. |
int |
getActiveConnections()
Get the total number of connections in use by the program. |
java.sql.Connection |
getConnection()
Returns a pooled connection. |
java.sql.Connection |
getConnection(java.lang.String user,
java.lang.String password)
Return a connection. |
java.sql.Driver |
getDriver()
Returns the JDBC driver for the pooled object. |
java.lang.String |
getDriverName()
Returns the JDBC driver class for the pooled object. |
int |
getLoginTimeout()
Gets the timeout for a database login. |
java.io.PrintWriter |
getLogWriter()
Sets the debugging log for the connection. |
int |
getMajorVersion()
Gets the driver's major version number. |
int |
getMaxConnections()
Get the maximum number of pooled connections. |
int |
getMinorVersion()
Gets the driver's minor version number. |
java.lang.String |
getPassword()
Returns the password for the connection. |
static DBPool |
getPool(java.lang.String name)
Returns the pool object with the given name. |
java.sql.DriverPropertyInfo[] |
getPropertyInfo(java.lang.String url,
java.util.Properties info)
Gets information about the possible properties for this driver. |
int |
getTotalConnections()
Get the total number of connections |
java.lang.String |
getURL()
Returns the JDBC url for the connection. |
java.lang.String |
getUser()
Returns the user for the connection. |
void |
handleAlarm(Alarm alarm)
At the alarm, close all connections which have been sitting in the pool for too long. |
boolean |
jdbcCompliant()
Reports whether this driver is a genuine JDBC COMPLIANTTM driver. |
void |
setLoginTimeout(int seconds)
Sets the timeout for a database login. |
void |
setLogWriter(java.io.PrintWriter out)
Sets the debugging log for the connection. |
void |
setMaxConnections(int maxConnections)
Sets the maximum number of pooled connections. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String PROPERTY_USER_NAME
public static final java.lang.String PROPERTY_PASSWORD
Constructor Detail |
public DBPool(java.lang.String poolName, java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String driverName, java.lang.ClassLoader loader, int maxConnections) throws java.sql.SQLException
Method Detail |
public java.sql.DriverPropertyInfo[] getPropertyInfo(java.lang.String url, java.util.Properties info) throws java.sql.SQLException
The getPropertyInfo method is intended to allow a generic GUI tool to discover what properties it should prompt a human for in order to get enough information to connect to a database. Note that depending on the values the human has supplied so far, additional values may become necessary, so it may be necessary to iterate though several calls to getPropertyInfo.
url
- the URL of the database to which to connectinfo
- a proposed list of tag/value pairs that will be sent
on connect openpublic boolean acceptsURL(java.lang.String url) throws java.sql.SQLException
url
- the URL of the databasepublic java.sql.Connection connect(java.lang.String url, java.util.Properties info) throws java.sql.SQLException
The driver should raise a SQLException if it is the right driver to connect to the given URL, but has trouble connecting to the database.
The java.util.Properties argument can be used to passed arbitrary string tag/value pairs as connection arguments. Normally at least "user" and "password" properties should be included in the Properties.
url
- the URL of the database to which to connectinfo
- a list of arbitrary string tag/value pairs as
connection arguments. Normally at least a "user" and
"password" property should be included.Connection
object that represents a
connection to the URLpublic static DBPool getPool(java.lang.String name) throws java.sql.SQLException
name
- name of a database configuration.public java.lang.String getDriverName()
public java.sql.Driver getDriver()
public java.lang.String getURL()
public java.lang.String getUser()
public java.lang.String getPassword()
public void setMaxConnections(int maxConnections)
public int getMaxConnections()
public int getTotalConnections()
public int getActiveConnections()
public int getMajorVersion()
public int getMinorVersion()
public boolean jdbcCompliant()
public java.sql.Connection getConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
user
- database userpassword
- database passwordpublic java.sql.Connection getConnection() throws java.sql.SQLException
public void setLoginTimeout(int seconds) throws java.sql.SQLException
public int getLoginTimeout() throws java.sql.SQLException
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
public void handleAlarm(Alarm alarm)
public void close()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |