Class DriverAdapterCPDS
- java.lang.Object
- 
- org.apache.tomcat.dbcp.dbcp2.cpdsadapter.DriverAdapterCPDS
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- javax.naming.Referenceable,- javax.naming.spi.ObjectFactory,- javax.sql.CommonDataSource,- javax.sql.ConnectionPoolDataSource
 
 public class DriverAdapterCPDS extends java.lang.Object implements javax.sql.ConnectionPoolDataSource, javax.naming.Referenceable, java.io.Serializable, javax.naming.spi.ObjectFactoryAn adapter for JDBC drivers that do not include an implementation of ConnectionPoolDataSource, but still include aDriverManagerimplementation.ConnectionPoolDataSources are not used within general applications. They are used byDataSourceimplementations that poolConnections, such asSharedPoolDataSource. A J2EE container will normally provide some method of initializing theConnectionPoolDataSourcewhose 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 poolingDataSourceneeds 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.Jdbc2PoolDataSourcecan use theConnectionPoolDataSourcewith or without the use of JNDI.The DriverAdapterCPDS also provides PreparedStatementpooling which is not generally available in jdbc2ConnectionPoolDataSourceimplementation, but is addressed within the jdbc3 specification. ThePreparedStatementpool 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 DriverAdapterCPDSas a source forJdbc2PoolDataSourcewithout the use of JNDI.- Since:
- 2.0
- See Also:
- Serialized Form
 
- 
- 
Constructor SummaryConstructors Constructor Description DriverAdapterCPDS()Default no-arg constructor for Serialization
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.PropertiesgetConnectionProperties()Gets the connection properties passed to the JDBC driver.java.lang.StringgetDescription()Gets the value of description.java.lang.StringgetDriver()Gets the driver class name.intgetLoginTimeout()Gets the maximum time in seconds that this data source can wait while attempting to connect to a database.java.io.PrintWritergetLogWriter()Gets the log writer for this data source.intgetMaxIdle()Gets the maximum number of statements that can remain idle in the pool, without extra ones being released, or negative for no limit.intgetMaxPreparedStatements()Gets the maximum number of prepared statements.intgetMinEvictableIdleTimeMillis()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).intgetNumTestsPerEvictionRun()Gets the number of statements to examine during each run of the idle object evictor thread (if any.)java.lang.ObjectgetObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context context, java.util.Hashtable<?,?> env)ImplementsObjectFactoryto create an instance of this classjava.util.logging.LoggergetParentLogger()java.lang.StringgetPassword()Gets the value of password for the default user.char[]getPasswordCharArray()Gets the value of password for the default user.javax.sql.PooledConnectiongetPooledConnection()Attempts to establish a database connection using the default user and password.javax.sql.PooledConnectiongetPooledConnection(java.lang.String pooledUserName, java.lang.String pooledUserPassword)Attempts to establish a database connection.javax.naming.ReferencegetReference()ImplementsReferenceable.longgetTimeBetweenEvictionRunsMillis()Gets the number of milliseconds to sleep between runs of the idle object evictor thread.java.lang.StringgetUrl()Gets the value of url used to locate the database for this datasource.java.lang.StringgetUser()Gets the value of default user (login or user name).booleanisAccessToUnderlyingConnectionAllowed()Returns the value of the accessToUnderlyingConnectionAllowed property.booleanisPoolPreparedStatements()Whether to toggle the pooling ofPreparedStatementsvoidsetAccessToUnderlyingConnectionAllowed(boolean allow)Sets the value of the accessToUnderlyingConnectionAllowed property.voidsetConnectionProperties(java.util.Properties props)Sets the connection properties passed to the JDBC driver.voidsetDescription(java.lang.String description)Sets the value of description.voidsetDriver(java.lang.String driver)Sets the driver class name.voidsetLoginTimeout(int seconds)Sets the maximum time in seconds that this data source will wait while attempting to connect to a database.voidsetLogWriter(java.io.PrintWriter logWriter)Sets the log writer for this data source.voidsetMaxIdle(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.voidsetMaxPreparedStatements(int maxPreparedStatements)Sets the maximum number of prepared statements.voidsetMinEvictableIdleTimeMillis(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).voidsetNumTestsPerEvictionRun(int numTestsPerEvictionRun)Sets the number of statements to examine during each run of the idle object evictor thread (if any).voidsetPassword(char[] userPassword)Sets the value of password for the default user.voidsetPassword(java.lang.String userPassword)Sets the value of password for the default user.voidsetPoolPreparedStatements(boolean poolPreparedStatements)Whether to toggle the pooling ofPreparedStatementsvoidsetTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)Sets the number of milliseconds to sleep between runs of the idle object evictor thread.voidsetUrl(java.lang.String url)Sets the value of URL string used to locate the database for this datasource.voidsetUser(java.lang.String userName)Sets the value of default user (login or user name).java.lang.StringtoString()Does not print the userName and userPassword field nor the 'user' or 'password' in the connectionProperties.
 
- 
- 
- 
Method Detail- 
getConnectionPropertiespublic java.util.Properties getConnectionProperties() Gets the connection properties passed to the JDBC driver.- Returns:
- the JDBC connection properties used when creating connections.
 
 - 
getDescriptionpublic java.lang.String getDescription() Gets the value of description. This property is here for use by the code which will deploy this datasource. It is not used internally.- Returns:
- value of description, may be null.
- See Also:
- setDescription(String)
 
 - 
getDriverpublic java.lang.String getDriver() Gets the driver class name.- Returns:
- value of driver.
 
 - 
getLoginTimeoutpublic int getLoginTimeout() Gets the maximum time in seconds that this data source can wait while attempting to connect to a database. NOT USED.- Specified by:
- getLoginTimeoutin interface- javax.sql.CommonDataSource
- Specified by:
- getLoginTimeoutin interface- javax.sql.ConnectionPoolDataSource
 
 - 
getLogWriterpublic java.io.PrintWriter getLogWriter() Gets the log writer for this data source. NOT USED.- Specified by:
- getLogWriterin interface- javax.sql.CommonDataSource
- Specified by:
- getLogWriterin interface- javax.sql.ConnectionPoolDataSource
 
 - 
getMaxIdlepublic 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.- Returns:
- the value of maxIdle
 
 - 
getMaxPreparedStatementspublic int getMaxPreparedStatements() Gets the maximum number of prepared statements.- Returns:
- maxPrepartedStatements value
 
 - 
getMinEvictableIdleTimeMillispublic 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).- Returns:
- the minimum amount of time a statement may sit idle in the pool.
- See Also:
- setMinEvictableIdleTimeMillis(int),- setTimeBetweenEvictionRunsMillis(long)
 
 - 
getNumTestsPerEvictionRunpublic int getNumTestsPerEvictionRun() Gets the number of statements to examine during each run of the idle object evictor thread (if any.)- Returns:
- the number of statements to examine during each run of the idle object evictor thread (if any.)
- See Also:
- setNumTestsPerEvictionRun(int),- setTimeBetweenEvictionRunsMillis(long)
 
 - 
getObjectInstancepublic java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context context, java.util.Hashtable<?,?> env) throws java.lang.ExceptionImplementsObjectFactoryto create an instance of this class- Specified by:
- getObjectInstancein interface- javax.naming.spi.ObjectFactory
- Throws:
- java.lang.Exception
 
 - 
getParentLoggerpublic java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException- Specified by:
- getParentLoggerin interface- javax.sql.CommonDataSource
- Throws:
- java.sql.SQLFeatureNotSupportedException
 
 - 
getPasswordpublic java.lang.String getPassword() Gets the value of password for the default user.- Returns:
- value of password.
 
 - 
getPasswordCharArraypublic char[] getPasswordCharArray() Gets the value of password for the default user.- Returns:
- value of password.
- Since:
- 2.4.0
 
 - 
getPooledConnectionpublic javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLExceptionAttempts to establish a database connection using the default user and password.- Specified by:
- getPooledConnectionin interface- javax.sql.ConnectionPoolDataSource
- Throws:
- java.sql.SQLException
 
 - 
getPooledConnectionpublic javax.sql.PooledConnection getPooledConnection(java.lang.String pooledUserName, java.lang.String pooledUserPassword) throws java.sql.SQLExceptionAttempts to establish a database connection.- Specified by:
- getPooledConnectionin interface- javax.sql.ConnectionPoolDataSource
- Parameters:
- pooledUserName- name to be used for the connection
- pooledUserPassword- password to be used fur the connection
- Throws:
- java.sql.SQLException
 
 - 
getReferencepublic javax.naming.Reference getReference() throws javax.naming.NamingExceptionImplementsReferenceable.- Specified by:
- getReferencein interface- javax.naming.Referenceable
- Throws:
- javax.naming.NamingException
 
 - 
getTimeBetweenEvictionRunsMillispublic long getTimeBetweenEvictionRunsMillis() Gets 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.- Returns:
- the value of the evictor thread timer
- See Also:
- setTimeBetweenEvictionRunsMillis(long)
 
 - 
getUrlpublic java.lang.String getUrl() Gets the value of url used to locate the database for this datasource.- Returns:
- value of url.
 
 - 
getUserpublic java.lang.String getUser() Gets the value of default user (login or user name).- Returns:
- value of user.
 
 - 
isAccessToUnderlyingConnectionAllowedpublic boolean isAccessToUnderlyingConnectionAllowed() Returns the value of the accessToUnderlyingConnectionAllowed property.- Returns:
- true if access to the underlying is allowed, false otherwise.
 
 - 
isPoolPreparedStatementspublic boolean isPoolPreparedStatements() Whether to toggle the pooling ofPreparedStatements- Returns:
- value of poolPreparedStatements.
 
 - 
setAccessToUnderlyingConnectionAllowedpublic void setAccessToUnderlyingConnectionAllowed(boolean allow) Sets the value of the accessToUnderlyingConnectionAllowed property. It controls if the PoolGuard allows access to the underlying connection. (Default: false)- Parameters:
- allow- Access to the underlying connection is granted when true.
 
 - 
setConnectionPropertiespublic void setConnectionProperties(java.util.Properties props) Sets the connection properties passed to the JDBC driver.If propscontains "user" and/or "password" properties, the corresponding instance properties are set. If these properties are not present, they are filled in usinggetUser(),getPassword()whengetPooledConnection()is called, or using the actual parameters to the method call whengetPooledConnection(String, String)is called. Calls tosetUser(String)orsetPassword(String)overwrite the values of these properties ifconnectionPropertiesis not null.- Parameters:
- props- Connection properties to use when creating new connections.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setDescriptionpublic void setDescription(java.lang.String description) Sets the value of description. This property is here for use by the code which will deploy this datasource. It is not used internally.- Parameters:
- description- Value to assign to description.
 
 - 
setDriverpublic void setDriver(java.lang.String driver) throws java.lang.ClassNotFoundExceptionSets the driver class name. Setting the driver class name cause the driver to be registered with the DriverManager.- Parameters:
- driver- Value to assign to driver.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
- java.lang.ClassNotFoundException- if the class cannot be located
 
 - 
setLoginTimeoutpublic void setLoginTimeout(int seconds) Sets the maximum time in seconds that this data source will wait while attempting to connect to a database. NOT USED.- Specified by:
- setLoginTimeoutin interface- javax.sql.CommonDataSource
- Specified by:
- setLoginTimeoutin interface- javax.sql.ConnectionPoolDataSource
 
 - 
setLogWriterpublic void setLogWriter(java.io.PrintWriter logWriter) Sets the log writer for this data source. NOT USED.- Specified by:
- setLogWriterin interface- javax.sql.CommonDataSource
- Specified by:
- setLogWriterin interface- javax.sql.ConnectionPoolDataSource
 
 - 
setMaxIdlepublic 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.- Parameters:
- maxIdle- The maximum number of statements that can remain idle
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setMaxPreparedStatementspublic void setMaxPreparedStatements(int maxPreparedStatements) Sets the maximum number of prepared statements.- Parameters:
- maxPreparedStatements- the new maximum number of prepared statements
 
 - 
setMinEvictableIdleTimeMillispublic 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). When non-positive, no objects will be evicted from the pool due to idle time alone.- Parameters:
- minEvictableIdleTimeMillis- minimum time to set (in ms)
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
- See Also:
- getMinEvictableIdleTimeMillis(),- setTimeBetweenEvictionRunsMillis(long)
 
 - 
setNumTestsPerEvictionRunpublic void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) Sets the number of statements to examine during each run of the idle object evictor thread (if any).When a negative value is supplied, ceil(tests will be run. I.e., when the value is -n, roughly one nth of the idle objects will be tested per run.BasicDataSource.getNumIdle())/abs(getNumTestsPerEvictionRun())- Parameters:
- numTestsPerEvictionRun- number of statements to examine per run
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
- See Also:
- getNumTestsPerEvictionRun(),- setTimeBetweenEvictionRunsMillis(long)
 
 - 
setPasswordpublic void setPassword(char[] userPassword) Sets the value of password for the default user.- Parameters:
- userPassword- Value to assign to password.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setPasswordpublic void setPassword(java.lang.String userPassword) Sets the value of password for the default user.- Parameters:
- userPassword- Value to assign to password.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setPoolPreparedStatementspublic void setPoolPreparedStatements(boolean poolPreparedStatements) Whether to toggle the pooling ofPreparedStatements- Parameters:
- poolPreparedStatements- true to pool statements.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setTimeBetweenEvictionRunsMillispublic void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) Sets 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.- Parameters:
- 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.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
- See Also:
- getTimeBetweenEvictionRunsMillis()
 
 - 
setUrlpublic void setUrl(java.lang.String url) Sets the value of URL string used to locate the database for this datasource.- Parameters:
- url- Value to assign to url.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
setUserpublic void setUser(java.lang.String userName) Sets the value of default user (login or user name).- Parameters:
- userName- Value to assign to user.
- Throws:
- java.lang.IllegalStateException- if- getPooledConnection()has been called
 
 - 
toStringpublic java.lang.String toString() Does not print the userName and userPassword field nor the 'user' or 'password' in the connectionProperties.- Overrides:
- toStringin class- java.lang.Object
- Since:
- 2.6.0
 
 
- 
 
-