public class DriverAdapterCPDS
extends java.lang.Object
implements javax.sql.ConnectionPoolDataSource, javax.naming.Referenceable, java.io.Serializable, javax.naming.spi.ObjectFactory
An adapter for JDBC drivers that do not include an implementation of ConnectionPoolDataSource
, but
still include a DriverManager
implementation. ConnectionPoolDataSource
s are not used
within general applications. They are used by DataSource
implementations that pool
Connection
s, such as SharedPoolDataSource
. A J2EE container
will normally provide some method of initializing the ConnectionPoolDataSource
whose attributes are
presented as bean getters/setters and then deploying it via JNDI. It is then available as a source of physical
connections to the database, when the pooling DataSource
needs to create a new physical connection.
Although normally used within a JNDI environment, the DriverAdapterCPDS can be instantiated and initialized as any
bean and then attached directly to a pooling DataSource
. Jdbc2PoolDataSource
can use the
ConnectionPoolDataSource
with or without the use of JNDI.
The DriverAdapterCPDS also provides PreparedStatement
pooling which is not generally available in jdbc2
ConnectionPoolDataSource
implementation, but is addressed within the jdbc3 specification. The
PreparedStatement
pool in DriverAdapterCPDS has been in the dbcp package for some time, but it has not
undergone extensive testing in the configuration used here. It should be considered experimental and can be toggled
with the poolPreparedStatements attribute.
The package documentation contains an example using catalina and JNDI. The
datasources package documentation shows how to use
DriverAdapterCPDS
as a source for Jdbc2PoolDataSource
without the use of JNDI.
Constructor and Description |
---|
DriverAdapterCPDS()
Default no-arg constructor for Serialization
|
Modifier and Type | Method and Description |
---|---|
java.util.Properties |
getConnectionProperties()
Gets the connection properties passed to the JDBC driver.
|
java.lang.String |
getDescription()
Gets the value of description.
|
java.lang.String |
getDriver()
Gets the driver class name.
|
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()
Gets the log writer for this data source.
|
int |
getMaxIdle()
Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or
negative for no limit.
|
int |
getMaxPreparedStatements()
Gets the maximum number of prepared statements.
|
int |
getMinEvictableIdleTimeMillis()
Gets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the
idle object evictor (if any).
|
int |
getNumTestsPerEvictionRun()
Gets the number of statements to examine during each run of the idle object evictor thread (if any.)
|
java.lang.Object |
getObjectInstance(java.lang.Object refObj,
javax.naming.Name name,
javax.naming.Context context,
java.util.Hashtable<?,?> env)
Implements
ObjectFactory to create an instance of this class |
java.util.logging.Logger |
getParentLogger() |
java.lang.String |
getPassword()
Gets the value of password for the default user.
|
char[] |
getPasswordCharArray()
Gets the value of password for the default user.
|
javax.sql.PooledConnection |
getPooledConnection()
Attempts to establish a database connection using the default user and password.
|
javax.sql.PooledConnection |
getPooledConnection(java.lang.String pooledUserName,
java.lang.String pooledUserPassword)
Attempts to establish a database connection.
|
javax.naming.Reference |
getReference()
Implements
Referenceable . |
long |
getTimeBetweenEvictionRunsMillis()
Gets the number of milliseconds to sleep between runs of the idle object evictor thread.
|
java.lang.String |
getUrl()
Gets the value of url used to locate the database for this datasource.
|
java.lang.String |
getUser()
Gets the value of default user (login or user name).
|
boolean |
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.
|
boolean |
isPoolPreparedStatements()
Whether to toggle the pooling of
PreparedStatement s |
void |
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.
|
void |
setConnectionProperties(java.util.Properties props)
Sets the connection properties passed to the JDBC driver.
|
void |
setDescription(java.lang.String v)
Sets the value of description.
|
void |
setDriver(java.lang.String v)
Sets the driver class name.
|
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)
Sets the log writer for this data source.
|
void |
setMaxIdle(int maxIdle)
Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or
negative for no limit.
|
void |
setMaxPreparedStatements(int maxPreparedStatements)
Sets the maximum number of prepared statements.
|
void |
setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
Sets the minimum amount of time a statement may sit idle in the pool before it is eligible for eviction by the
idle object evictor (if any).
|
void |
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the number of statements to examine during each run of the idle object evictor thread (if any).
|
void |
setPassword(char[] userPassword)
Sets the value of password for the default user.
|
void |
setPassword(java.lang.String userPassword)
Sets the value of password for the default user.
|
void |
setPoolPreparedStatements(boolean poolPreparedStatements)
Whether to toggle the pooling of
PreparedStatement s |
void |
setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the number of milliseconds to sleep between runs of the idle object evictor thread.
|
void |
setUrl(java.lang.String v)
Sets the value of URL string used to locate the database for this datasource.
|
void |
setUser(java.lang.String v)
Sets the value of default user (login or user name).
|
java.lang.String |
toString()
Does not print the userName and userPassword field nor the 'user' or 'password' in the connectionProperties.
|
public DriverAdapterCPDS()
public java.util.Properties getConnectionProperties()
public java.lang.String getDescription()
setDescription(String)
public java.lang.String getDriver()
public int getLoginTimeout()
getLoginTimeout
in interface javax.sql.CommonDataSource
public java.io.PrintWriter getLogWriter()
getLogWriter
in interface javax.sql.CommonDataSource
public int getMaxIdle()
public int getMaxPreparedStatements()
public int getMinEvictableIdleTimeMillis()
setMinEvictableIdleTimeMillis(int)
,
setTimeBetweenEvictionRunsMillis(long)
public int getNumTestsPerEvictionRun()
setNumTestsPerEvictionRun(int)
,
setTimeBetweenEvictionRunsMillis(long)
public java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context context, java.util.Hashtable<?,?> env) throws java.lang.Exception
ObjectFactory
to create an instance of this classgetObjectInstance
in interface javax.naming.spi.ObjectFactory
java.lang.Exception
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
getParentLogger
in interface javax.sql.CommonDataSource
java.sql.SQLFeatureNotSupportedException
public java.lang.String getPassword()
public char[] getPasswordCharArray()
public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
java.sql.SQLException
public javax.sql.PooledConnection getPooledConnection(java.lang.String pooledUserName, java.lang.String pooledUserPassword) throws java.sql.SQLException
getPooledConnection
in interface javax.sql.ConnectionPoolDataSource
pooledUserName
- name to be used for the connectionpooledUserPassword
- password to be used fur the connectionjava.sql.SQLException
public javax.naming.Reference getReference() throws javax.naming.NamingException
Referenceable
.getReference
in interface javax.naming.Referenceable
javax.naming.NamingException
public long getTimeBetweenEvictionRunsMillis()
setTimeBetweenEvictionRunsMillis(long)
public java.lang.String getUrl()
public java.lang.String getUser()
public boolean isAccessToUnderlyingConnectionAllowed()
public boolean isPoolPreparedStatements()
PreparedStatement
spublic void setAccessToUnderlyingConnectionAllowed(boolean allow)
allow
- Access to the underlying connection is granted when true.public void setConnectionProperties(java.util.Properties props)
If props
contains "user" and/or "password" properties, the corresponding instance properties are
set. If these properties are not present, they are filled in using getUser()
, getPassword()
when getPooledConnection()
is called, or using the actual parameters to the method call when
getPooledConnection(String, String)
is called. Calls to setUser(String)
or
setPassword(String)
overwrite the values of these properties if connectionProperties
is not
null.
props
- Connection properties to use when creating new connections.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setDescription(java.lang.String v)
v
- Value to assign to description.public void setDriver(java.lang.String v) throws java.lang.ClassNotFoundException
v
- Value to assign to driver.java.lang.IllegalStateException
- if getPooledConnection()
has been calledjava.lang.ClassNotFoundException
- if the class cannot be locatedpublic void setLoginTimeout(int seconds)
setLoginTimeout
in interface javax.sql.CommonDataSource
public void setLogWriter(java.io.PrintWriter out)
setLogWriter
in interface javax.sql.CommonDataSource
public void setMaxIdle(int maxIdle)
maxIdle
- The maximum number of statements that can remain idlejava.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setMaxPreparedStatements(int maxPreparedStatements)
maxPreparedStatements
- the new maximum number of prepared statementspublic void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
minEvictableIdleTimeMillis
- minimum time to set (in ms)java.lang.IllegalStateException
- if getPooledConnection()
has been calledgetMinEvictableIdleTimeMillis()
,
setTimeBetweenEvictionRunsMillis(long)
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
When a negative value is supplied, ceil({*link #numIdle})/abs({*link #getNumTestsPerEvictionRun})
tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested
per run.
numTestsPerEvictionRun
- number of statements to examine per runjava.lang.IllegalStateException
- if getPooledConnection()
has been calledgetNumTestsPerEvictionRun()
,
setTimeBetweenEvictionRunsMillis(long)
public void setPassword(char[] userPassword)
userPassword
- Value to assign to password.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setPassword(java.lang.String userPassword)
userPassword
- Value to assign to password.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setPoolPreparedStatements(boolean poolPreparedStatements)
PreparedStatement
spoolPreparedStatements
- true to pool statements.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
timeBetweenEvictionRunsMillis
- The number of milliseconds to sleep between runs of the idle object evictor thread. When non-positive,
no idle object evictor thread will be run.java.lang.IllegalStateException
- if getPooledConnection()
has been calledgetTimeBetweenEvictionRunsMillis()
public void setUrl(java.lang.String v)
v
- Value to assign to url.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic void setUser(java.lang.String v)
v
- Value to assign to user.java.lang.IllegalStateException
- if getPooledConnection()
has been calledpublic java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2000-2023 Apache Software Foundation. All Rights Reserved.