|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsnaq.db.DBPoolDataSource
public class DBPoolDataSource
A DataSource implementation which produces Connection
instances. This implementation internally references a ConnectionPool
which it uses to provide transparent connection pooling to the client.
| Field Summary | |
|---|---|
protected Driver |
driver
Driver to use for database access. |
protected static org.apache.commons.logging.Log |
logger
Apache Commons Logging shared instance for writing log entries. |
protected PrintWriter |
logWriter
PrintWriter instance used for logging. |
protected ConnectionPool |
pool
ConnectionPool instance used to source connections. |
protected static String |
POOL_NAME_PREFIX
Name prefix to use for ConnectionPool instance (JNDI name is appended). |
| Constructor Summary | |
|---|---|
DBPoolDataSource()
Creates a new DBPoolDataSource instance. |
|
| Method Summary | ||
|---|---|---|
protected void |
createConnectionPool()
Creates a new DBPoolDataSource instance. |
|
Connection |
getConnection()
Attempts to establish a connection with the database. |
|
Connection |
getConnection(String username,
String password)
Attempts to establish a connection with the database. |
|
String |
getDescription()
Returns the description of this DataSource. |
|
String |
getDriverClassName()
Returns the fully-qualified class name for the JDBC driver to use. |
|
int |
getExpiryTime()
Deprecated. Use getIdleTimeout() instead. |
|
int |
getIdleTimeout()
Returns the idle timeout (seconds) for connections in the underlying ConnectionPool. |
|
int |
getLoginTimeout()
|
|
PrintWriter |
getLogWriter()
Retrieves the log writer for this DataSource. |
|
int |
getMaxPool()
Returns the maximum number of pooled connections in the underlying ConnectionPool. |
|
int |
getMaxSize()
Returns the maximum number of connections in the underlying ConnectionPool. |
|
int |
getMinPool()
Returns the minimum number of pooled connections in the underlying ConnectionPool. |
|
String |
getName()
Returns the JNDI name of the DBPoolDataSource instance. |
|
String |
getPassword()
Returns the password to use with this DataSource. |
|
String |
getPasswordDecoderClassName()
Returns the class name of the PasswordDecoder to use with this DataSource. |
|
String |
getUrl()
Returns the JDBC URL to use with this DataSource. |
|
String |
getUser()
Returns the username to use with this DataSource. |
|
String |
getUsername()
Deprecated. Use getUser() method instead. |
|
String |
getValidationQuery()
Returns the SQL query string to issue for connection validation. |
|
String |
getValidatorClassName()
Returns the class name of the ConnectionValidator to use with this DataSource. |
|
boolean |
isWrapperFor(Class<?> iface)
|
|
protected void |
log(String message)
Writes a message to the log. |
|
protected void |
log(String message,
Throwable throwable)
Writes a message with a Throwable to the log file. |
|
void |
maxPoolLimitExceeded(ConnectionPoolEvent evt)
Called when a check-out request causes the maxPool limit to be exceeded. |
|
void |
maxPoolLimitReached(ConnectionPoolEvent evt)
Called when a check-out request causes the maxPool limit to be reached. |
|
void |
maxSizeLimitError(ConnectionPoolEvent evt)
Called when a check-out request attempts to exceed the maxSize limit. |
|
void |
maxSizeLimitReached(ConnectionPoolEvent evt)
Called when a check-out request causes the maxSize limit to be reached. |
|
void |
poolCheckIn(ConnectionPoolEvent evt)
Called when a connection is checked back in to the pool. |
|
void |
poolCheckOut(ConnectionPoolEvent evt)
Called when a connection is checked out of the pool. |
|
void |
poolFlushed(ConnectionPoolEvent evt)
Called when the pool is flushed of free/unused connections. |
|
void |
poolInitCompleted(ConnectionPoolEvent evt)
Called when the pool's ObjectPool.init(int) method has completed. |
|
void |
poolParametersChanged(ConnectionPoolEvent evt)
Called when the pool's parameters are changed. |
|
void |
poolReleased(ConnectionPoolEvent evt)
Called when the pool is released (no more events are fired by the pool after this event). |
|
void |
registerShutdownHook()
Registers a shutdown hook for this ConnectionPoolManager instance to ensure it is released if the JVM exits |
|
void |
release()
Releases the delegate ConnectionPool instance. |
|
void |
releaseAsync()
Asynchronously releases the delegate ConnectionPool instance. |
|
void |
releaseConnectionPool()
Releases (cleans up resources of) the internal ConnectionPool
instance. |
|
void |
releaseForcibly()
Forcibly releases the delegate ConnectionPool instance. |
|
void |
removeShutdownHook()
Deregisters a registered shutdown hook for this ConnectionPoolManager instance. |
|
void |
setDescription(String description)
Sets the description of this DataSource. |
|
void |
setDriverClassName(String driverClassName)
Sets the fully-qualified class name for the JDBC driver to use. |
|
void |
setExpiryTime(int idleTimeout)
Deprecated. Use setIdleTimeout(int) instead. |
|
void |
setIdleTimeout(int idleTimeout)
Sets the idle timeout (seconds) for connections in the underlying ConnectionPool. |
|
void |
setLoginTimeout(int seconds)
Sets the maximum time in seconds that this DataSource will wait while attempting to connect to a database. |
|
void |
setLogWriter(PrintWriter out)
Sets the log writer for this DataSource to the given PrintWriter. |
|
void |
setMaxPool(int maxPool)
Sets the maximum number of pooled connections in the underlying ConnectionPool. |
|
void |
setMaxSize(int maxSize)
Sets the maximum number of connections in the underlying ConnectionPool. |
|
void |
setMinPool(int minPool)
Sets the minimum number of pooled connections in the underlying ConnectionPool. |
|
void |
setName(String name)
Sets the JNDI name of the DBPoolDataSource instance. |
|
void |
setPassword(String password)
Sets the password to use with this DataSource. |
|
void |
setPasswordDecoderClassName(String decoderClassName)
Sets the class name of the PasswordDecoder to use with this
DataSource. |
|
void |
setUrl(String url)
Sets the JDBC URL to use with this DataSource. |
|
void |
setUser(String user)
Sets the username to use with this DataSource. |
|
void |
setUsername(String username)
Deprecated. Use setUser(String) method instead. |
|
void |
setValidationQuery(String validationQuery)
Sets the SQL query string to issue for connection validation. |
|
void |
setValidatorClassName(String validatorClassName)
Sets the class name of the ConnectionValidator to use with this
DataSource. |
|
String |
toString()
|
|
|
unwrap(Class<T> iface)
|
|
void |
validationError(ConnectionPoolEvent evt)
Called when a connection is found to be invalid. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final String POOL_NAME_PREFIX
ConnectionPool instance (JNDI name is appended).
protected static final org.apache.commons.logging.Log logger
protected transient Driver driver
Driver to use for database access.
protected transient ConnectionPool pool
ConnectionPool instance used to source connections.
protected transient PrintWriter logWriter
PrintWriter instance used for logging.
| Constructor Detail |
|---|
public DBPoolDataSource()
DBPoolDataSource instance.
| Method Detail |
|---|
public void registerShutdownHook()
public void removeShutdownHook()
protected void log(String message)
protected void log(String message,
Throwable throwable)
Throwable to the log file.
protected void createConnectionPool()
throws SQLException
DBPoolDataSource instance.
SQLException - if required resources cannot be located/established
public Connection getConnection()
throws SQLException
getConnection in interface DataSourceConnection instance, or null if unable to connect
SQLException - if a database access error occurs
public Connection getConnection(String username,
String password)
throws SQLException
getConnection in interface DataSourceusername - the database user on whose behalf the connection is being madepassword - the user's password
Connection instance, or null if unable to connect
SQLException - if a database access error occurspublic void releaseConnectionPool()
ConnectionPool
instance. This method should be called to close all the pooled connections.
public String getDescription()
public void setDescription(String description)
public String getUser()
@Deprecated public String getUsername()
getUser() method instead.
getUser().
public void setUser(String user)
@Deprecated public void setUsername(String username)
setUser(String) method instead.
setUser(String).
public String getPassword()
public void setPassword(String password)
public String getName()
DBPoolDataSource instance.
public void setName(String name)
DBPoolDataSource instance.
public String getDriverClassName()
public void setDriverClassName(String driverClassName)
public String getPasswordDecoderClassName()
PasswordDecoder to use with this DataSource.
public void setPasswordDecoderClassName(String decoderClassName)
PasswordDecoder to use with this
DataSource. The specified class should implement the
PasswordDecoder interface, and have a no-argument constructor
which can be used to instantiate it for use.
public String getValidatorClassName()
ConnectionValidator to use with this DataSource.
public void setValidatorClassName(String validatorClassName)
ConnectionValidator to use with this
DataSource. The specified class should implement the
ConnectionValidator interface, and have a no-argument constructor
which can be used to instantiate it for use.
public String getValidationQuery()
validationClassName has not
been explicitly set, in which case this query string is used with an
instance of SimpleQueryValidator.
public void setValidationQuery(String validationQuery)
validationClassName has not
been explicitly set, in which case this query string is used with an
instance of SimpleQueryValidator.
public String getUrl()
public void setUrl(String url)
public int getMinPool()
ConnectionPool.
public void setMinPool(int minPool)
ConnectionPool.
public int getMaxPool()
ConnectionPool.
public void setMaxPool(int maxPool)
ConnectionPool.
public int getMaxSize()
ConnectionPool.
public void setMaxSize(int maxSize)
ConnectionPool.
public int getIdleTimeout()
ConnectionPool.
public void setIdleTimeout(int idleTimeout)
ConnectionPool.
@Deprecated public int getExpiryTime()
getIdleTimeout() instead.
ConnectionPool.
@Deprecated public void setExpiryTime(int idleTimeout)
setIdleTimeout(int) instead.
ConnectionPool.
public PrintWriter getLogWriter()
getLogWriter in interface CommonDataSourcepublic void setLogWriter(PrintWriter out)
PrintWriter.
setLogWriter in interface CommonDataSourceout - the new log writer; to disable logging, set to nullpublic void setLoginTimeout(int seconds)
DataSource object is created, the login timeout is
initially zero.
setLoginTimeout in interface CommonDataSourceseconds - the DataSource login time limitpublic int getLoginTimeout()
getLoginTimeout in interface CommonDataSourcepublic void release()
ConnectionPool instance.
public void releaseAsync()
ConnectionPool instance.
public void releaseForcibly()
ConnectionPool instance.
public String toString()
toString in class Object
public boolean isWrapperFor(Class<?> iface)
throws SQLException
isWrapperFor in interface WrapperSQLException
public <T> T unwrap(Class<T> iface)
throws SQLException
unwrap in interface WrapperSQLExceptionpublic void poolInitCompleted(ConnectionPoolEvent evt)
ConnectionPoolListenerObjectPool.init(int) method has completed.
poolInitCompleted in interface ConnectionPoolListenerpublic void poolCheckOut(ConnectionPoolEvent evt)
ConnectionPoolListener
poolCheckOut in interface ConnectionPoolListenerpublic void poolCheckIn(ConnectionPoolEvent evt)
ConnectionPoolListener
poolCheckIn in interface ConnectionPoolListenerpublic void validationError(ConnectionPoolEvent evt)
ConnectionPoolListener
validationError in interface ConnectionPoolListenerpublic void maxPoolLimitReached(ConnectionPoolEvent evt)
ConnectionPoolListener
maxPoolLimitReached in interface ConnectionPoolListenerpublic void maxPoolLimitExceeded(ConnectionPoolEvent evt)
ConnectionPoolListener
maxPoolLimitExceeded in interface ConnectionPoolListenerpublic void maxSizeLimitReached(ConnectionPoolEvent evt)
ConnectionPoolListener
maxSizeLimitReached in interface ConnectionPoolListenerpublic void maxSizeLimitError(ConnectionPoolEvent evt)
ConnectionPoolListener
maxSizeLimitError in interface ConnectionPoolListenerpublic void poolFlushed(ConnectionPoolEvent evt)
ConnectionPoolListener
poolFlushed in interface ConnectionPoolListenerpublic void poolParametersChanged(ConnectionPoolEvent evt)
ConnectionPoolListener
poolParametersChanged in interface ConnectionPoolListenerpublic void poolReleased(ConnectionPoolEvent evt)
ConnectionPoolListener
poolReleased in interface ConnectionPoolListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||