|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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
The key used to look into the properties passed to the connect method to find the username. |
Constructor Summary | |
DBPool()
Null constructor for the Driver interface; called by the JNDI configuration. |
|
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)
Creates a new DBPool. |
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()
Close the pool, closing the connections. |
java.sql.Connection |
connect(java.lang.String url,
java.util.Properties info)
Attempts to make a database connection to the given URL. |
void |
forceClose()
Close all the connections in the pool. |
int |
getActiveConnections()
Get the total number of connections in use by the program. |
java.sql.Connection |
getConnection()
Returns a new or 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. |
boolean |
getEnableTransaction()
Are transactions allowed on this pool? |
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 |
getMaxIdleTime()
Get the time in seconds a connection will remain in the pool before being closed. |
int |
getMinorVersion()
Gets the driver's minor version number. |
java.lang.String |
getPassword()
Returns the connection's password |
boolean |
getPingOnFree()
If true, the pool will ping when attempting to free a connection. |
boolean |
getPingOnIdle()
If true, the pool will ping in the idle pool. |
boolean |
getPingOnReuse()
If true, the pool will ping when attempting to reuse a connection. |
java.lang.String |
getPingTable()
Get the table to 'ping' to see if the connection is still live. |
static DBPool |
getPool(java.lang.String name)
Returns the pool object with the given name. |
java.lang.String |
getProperty(java.lang.String name)
Gets a property from the underlying driver. |
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 connection's JDBC url. |
java.lang.String |
getUser()
Returns the connection's user. |
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 |
setDriverName(java.lang.String name)
Sets the JDBC driver class underlying the pooled object. |
void |
setEnableTransaction(boolean allowTransaction)
Enable transactions on this pool. |
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. |
void |
setMaxIdleTime(int maxIdleTime)
Set the time in seconds a connection will remain in the pool before being closed. |
void |
setPassword(java.lang.String password)
Sets the connection's password |
void |
setPingOnFree(boolean pingOnFree)
Set the table to 'ping' to see if the connection is still live. |
void |
setPingOnIdle(boolean pingOnIdle)
Set the table to 'ping' to see if the connection is still live. |
void |
setPingOnReuse(boolean pingOnReuse)
Set the table to 'ping' to see if the connection is still live. |
void |
setPingTable(java.lang.String pingTable)
Set the table to 'ping' to see if the connection is still live. |
void |
setProperty(java.lang.String name,
java.lang.String value)
Sets a property from the underlying driver. |
void |
setURL(java.lang.String url)
Sets the connection's JDBC url. |
void |
setUser(java.lang.String user)
Sets the connection's user. |
Field Detail |
public static final java.lang.String PROPERTY_USER
public static final java.lang.String PROPERTY_PASSWORD
Constructor Detail |
public DBPool()
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
poolName
- the name of the poolurl
- the JDBC urluser
- the JDBC userpassword
- the JDBC passworddriverName
- the JDBC driverloader
- the classloader used to load the drivermaxConnections
- the maximum connections allowed by the driverMethod Detail |
public java.lang.String getDriverName()
public void setDriverName(java.lang.String name)
public java.lang.String getURL()
public void setURL(java.lang.String url)
public java.lang.String getUser()
public void setUser(java.lang.String user)
public java.lang.String getPassword()
public void setPassword(java.lang.String password)
public int getMaxConnections()
public void setMaxConnections(int maxConnections)
public int getTotalConnections()
public int getActiveConnections()
public int getMaxIdleTime()
public void setMaxIdleTime(int maxIdleTime)
public java.lang.String getPingTable()
public void setPingTable(java.lang.String pingTable)
pingTable
- name of the SQL table to ping.public boolean getPingOnReuse()
public void setPingOnReuse(boolean pingOnReuse)
public boolean getPingOnFree()
public void setPingOnFree(boolean pingOnFree)
public boolean getPingOnIdle()
public void setPingOnIdle(boolean pingOnIdle)
public void setEnableTransaction(boolean allowTransaction)
public boolean getEnableTransaction()
public int getMajorVersion()
getMajorVersion
in interface java.sql.Driver
public int getMinorVersion()
getMinorVersion
in interface java.sql.Driver
public java.lang.String getProperty(java.lang.String name)
name
- property name for the driverpublic void setProperty(java.lang.String name, java.lang.String value)
name
- property name for the drivervalue
- the driver's value of the property namepublic java.sql.Driver getDriver() throws java.sql.SQLException
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.
getPropertyInfo
in interface java.sql.Driver
url
- the URL of the database to which to connectinfo
- a proposed list of tag/value pairs that will be sent
on connect openjava.sql.SQLException
- if a database access error occurspublic boolean acceptsURL(java.lang.String url) throws java.sql.SQLException
acceptsURL
in interface java.sql.Driver
url
- the URL of the databasejava.sql.SQLException
- if a database access error occurspublic 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.
connect
in interface java.sql.Driver
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 URLjava.sql.SQLException
- if a database access error occurspublic static DBPool getPool(java.lang.String name) throws java.sql.SQLException
name
- name of a database configuration.public boolean jdbcCompliant()
jdbcCompliant
in interface java.sql.Driver
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 java.sql.Connection getConnection() throws java.sql.SQLException
public java.sql.Connection getConnection(java.lang.String user, java.lang.String password) throws java.sql.SQLException
user
- database userpassword
- database passwordpublic void handleAlarm(Alarm alarm)
handleAlarm
in interface AlarmListener
alarm
- the alarm event.public void close()
public void forceClose()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |