|
|||||||||
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.
Context env = (Context) new InitialContext().lookup("java:comp/env");
DataSource pool = (DataSource) env.lookup("jdbc/test");
Connection conn = pool.getConnection();
try {
... // normal connection stuff
} finally {
conn.close();
}
<resource-ref
res-ref-name='jdbc/test'
res-ref-type='javax.sql.DataSource'
driver="postgresql.Driver"
url="jdbc:postgresql://localhost/test"
user="ferg"
password="foobar"/>
getMaxConnection
connections are already active,
getPooledConnection
will block waiting for an available
connection. The wait is timed. If connection-wait-time passes
and there is still no connection, getPooledConnection
create a new connection anyway.
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)
Deprecated. |
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. |
static void |
closeGlobalPools()
Closes the global pools. |
static void |
closeLoaderPools()
Closes the pools in this classloader. |
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. |
long |
getConnectionWaitTime()
Gets the time to wait for a connection when all are used. |
java.lang.String |
getDataSource()
Returns the underlying pooled or xa datasource |
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. |
long |
getMaxActiveTime()
Get the time in milliseconds a connection can remain active. |
int |
getMaxConnections()
Get the maximum number of pooled connections. |
long |
getMaxIdleTime()
Get the time in seconds a connection will remain in the pool before being closed. |
int |
getMaxOverflowConnections()
The number of connections to overflow if the connection pool fills and there's a timeout. |
long |
getMaxPoolTime()
Get the time in milliseconds a connection will remain in the pool before being closed. |
int |
getMinorVersion()
Gets the driver's minor version number. |
java.lang.String |
getName()
Returns the Pool's name |
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. |
RegistryNode |
getRegistry()
Return registry. |
int |
getTotalConnections()
Get the total number of connections |
TransactionManagerImpl |
getTransactionManager()
Are transactions allowed on this pool? |
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. |
void |
handleUnload(DynamicClassLoader loader)
Callback when the class loader dies. |
boolean |
jdbcCompliant()
Reports whether this driver is a genuine JDBC COMPLIANTTM driver. |
void |
setConnectionWaitTime(long waitTime)
Sets the time to wait for a connection when all are used. |
void |
setDataSource(java.lang.String name)
Returns the underlying pooled or xa datasource |
void |
setDriver(java.lang.String name)
DriverName alias for backward compatibility. |
void |
setDriverName(java.lang.String name)
Sets the JDBC driver class underlying the pooled object. |
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 |
setMaxActiveTime(long maxActiveTime)
Set the time in milliseconds a connection can remain active. |
void |
setMaxConnections(int maxConnections)
Sets the maximum number of pooled connections. |
void |
setMaxIdleTime(long idleTime)
Set the time in seconds a connection will remain in the pool before being closed. |
void |
setMaxOverflowConnections(int maxOverflowConnections)
The number of connections to overflow if the connection pool fills and there's a timeout. |
void |
setMaxPoolTime(long maxPoolTime)
Set the time in milliseconds a connection will remain in the pool before being closed. |
void |
setName(java.lang.String name)
Sets the Pool's name. |
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 |
setRegistry(RegistryNode registry)
Set registry. |
void |
setTransactionManager(TransactionManagerImpl tm)
Enable transactions on this pool. |
void |
setURL(java.lang.String url)
Sets the connection's JDBC url. |
void |
setUser(java.lang.String user)
Sets the connection's user. |
java.lang.String |
toString()
Returns a string description of the pool. |
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 getName()
public void setName(java.lang.String name)
public java.lang.String getDataSource()
public void setDataSource(java.lang.String name)
public java.lang.String getDriverName()
public void setDriverName(java.lang.String name)
public void setDriver(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 void setConnectionWaitTime(long waitTime)
public long getConnectionWaitTime()
public void setMaxOverflowConnections(int maxOverflowConnections)
public int getMaxOverflowConnections()
public int getActiveConnections()
public long getMaxIdleTime()
public void setMaxIdleTime(long idleTime)
public long getMaxPoolTime()
public void setMaxPoolTime(long maxPoolTime)
public long getMaxActiveTime()
public void setMaxActiveTime(long maxActiveTime)
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 setTransactionManager(TransactionManagerImpl tm)
public TransactionManagerImpl getTransactionManager()
public RegistryNode getRegistry()
public void setRegistry(RegistryNode registry)
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 static void closeLoaderPools()
public static void closeGlobalPools()
public void handleUnload(DynamicClassLoader loader)
handleUnload
in interface ClassLoaderListener
public void close()
public void forceClose()
public java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |