public class DriverAdapterCPDS extends Object implements ConnectionPoolDataSource, Referenceable, Serializable, 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 |
---|---|
Properties |
getConnectionProperties()
Gets the connection properties passed to the JDBC driver.
|
String |
getDescription()
Gets the value of description.
|
String |
getDriver()
Gets the driver classname.
|
int |
getLoginTimeout()
Gets the maximum time in seconds that this data source can wait
while attempting to connect to a database.
|
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).
|
Object |
getObjectInstance(Object refObj,
Name name,
Context context,
Hashtable<?,?> env)
implements ObjectFactory to create an instance of this class
|
Logger |
getParentLogger() |
String |
getPassword()
Gets the value of password for the default user.
|
PooledConnection |
getPooledConnection()
Attempt to establish a database connection using the default
user and password.
|
PooledConnection |
getPooledConnection(String username,
String pass)
Attempt to establish a database connection.
|
Reference |
getReference()
Referenceable implementation. |
long |
getTimeBetweenEvictionRunsMillis()
Gets the number of milliseconds to sleep between runs of the
idle object evictor thread.
|
String |
getUrl()
Gets the value of url used to locate the database for this datasource.
|
String |
getUser()
Gets the value of default user (login or username).
|
boolean |
isAccessToUnderlyingConnectionAllowed()
Returns the value of the accessToUnderlyingConnectionAllowed property.
|
boolean |
isPoolPreparedStatements()
Flag to toggle the pooling of
PreparedStatement s |
void |
setAccessToUnderlyingConnectionAllowed(boolean allow)
Sets the value of the accessToUnderlyingConnectionAllowed property.
|
void |
setConnectionProperties(Properties props)
Sets the connection properties passed to the JDBC driver.
|
void |
setDescription(String v)
Sets the value of description.
|
void |
setDriver(String v)
Sets the driver classname.
|
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(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(String v)
Sets the value of password for the default user.
|
void |
setPoolPreparedStatements(boolean v)
Flag 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(String v)
Sets the value of URL string used to locate the database for this datasource.
|
void |
setUser(String v)
Sets the value of default user (login or username).
|
public DriverAdapterCPDS()
public PooledConnection getPooledConnection() throws SQLException
getPooledConnection
in interface ConnectionPoolDataSource
SQLException
public PooledConnection getPooledConnection(String username, String pass) throws SQLException
getPooledConnection
in interface ConnectionPoolDataSource
username
- name to be used for the connectionpass
- password to be used fur the connectionSQLException
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface CommonDataSource
SQLFeatureNotSupportedException
public Reference getReference() throws NamingException
Referenceable
implementation.getReference
in interface Referenceable
NamingException
public Object getObjectInstance(Object refObj, Name name, Context context, Hashtable<?,?> env) throws Exception
getObjectInstance
in interface ObjectFactory
Exception
public Properties getConnectionProperties()
public void setConnectionProperties(Properties props)
Sets the connection properties passed to the JDBC driver.
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.IllegalStateException
- if getPooledConnection()
has been calledpublic String getDescription()
setDescription(String)
public void setDescription(String v)
v
- Value to assign to description.public String getPassword()
public void setPassword(String v)
v
- Value to assign to password.IllegalStateException
- if getPooledConnection()
has been calledpublic String getUrl()
public void setUrl(String v)
v
- Value to assign to url.IllegalStateException
- if getPooledConnection()
has been calledpublic String getUser()
public void setUser(String v)
v
- Value to assign to user.IllegalStateException
- if getPooledConnection()
has been calledpublic void setDriver(String v) throws ClassNotFoundException
v
- Value to assign to driver.IllegalStateException
- if getPooledConnection()
has been calledClassNotFoundException
public int getLoginTimeout()
getLoginTimeout
in interface CommonDataSource
public PrintWriter getLogWriter()
getLogWriter
in interface CommonDataSource
public void setLoginTimeout(int seconds)
setLoginTimeout
in interface CommonDataSource
public void setLogWriter(PrintWriter out)
setLogWriter
in interface CommonDataSource
public boolean isPoolPreparedStatements()
PreparedStatement
spublic void setPoolPreparedStatements(boolean v)
PreparedStatement
sv
- true to pool statements.IllegalStateException
- if getPooledConnection()
has been calledpublic int getMaxIdle()
public void setMaxIdle(int maxIdle)
maxIdle
- The maximum number of statements that can remain idleIllegalStateException
- if getPooledConnection()
has been calledpublic long getTimeBetweenEvictionRunsMillis()
setTimeBetweenEvictionRunsMillis(long)
public void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
timeBetweenEvictionRunsMillis
- IllegalStateException
- if getPooledConnection()
has been calledgetTimeBetweenEvictionRunsMillis()
public int getNumTestsPerEvictionRun()
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 runIllegalStateException
- if getPooledConnection()
has been calledgetNumTestsPerEvictionRun()
,
setTimeBetweenEvictionRunsMillis(long)
public int getMinEvictableIdleTimeMillis()
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
minEvictableIdleTimeMillis
- minimum time to set (in ms)IllegalStateException
- if getPooledConnection()
has been calledgetMinEvictableIdleTimeMillis()
,
setTimeBetweenEvictionRunsMillis(long)
public boolean isAccessToUnderlyingConnectionAllowed()
public void setAccessToUnderlyingConnectionAllowed(boolean allow)
allow
- Access to the underlying connection is granted when true.public int getMaxPreparedStatements()
public void setMaxPreparedStatements(int maxPreparedStatements)
maxPreparedStatements
- the new maximum number of prepared
statementsCopyright © 2001–2017 The Apache Software Foundation. All rights reserved.