org.apache.commons.dbcp.datasources
public abstract class InstanceKeyDataSource extends Object implements DataSource, Referenceable, Serializable
The base class for SharedPoolDataSource
and
PerUserPoolDataSource
. Many of the configuration properties
are shared and defined here. This class is declared public in order
to allow particular usage with commons-beanutils; do not make direct
use of it outside of commons-dbcp.
A J2EE container will normally provide some method of initializing the
DataSource
whose attributes are presented
as bean getters/setters and then deploying it via JNDI. It is then
available to an application as a source of pooled logical connections to
the database. The pool needs a source of physical connections. This
source is in the form of a ConnectionPoolDataSource
that
can be specified via the setDataSourceName used to
lookup the source via JNDI.
Although normally used within a JNDI environment, A DataSource
can be instantiated and initialized as any bean. In this case the
ConnectionPoolDataSource
will likely be instantiated in
a similar manner. This class allows the physical source of connections
to be attached directly to this pool using the
setConnectionPoolDataSource method.
The dbcp package contains an adapter,
DriverAdapterCPDS,
that can be used to allow the use of DataSource
's based on this
class with jdbc driver implementations that do not supply a
ConnectionPoolDataSource
, but still
provide a java.sql.Driver implementation.
The package documentation contains an example using catalina and JNDI and it also contains a non-JNDI example.
Version: $Revision: 500687 $ $Date: 2007-01-27 16:33:47 -0700 (Sat, 27 Jan 2007) $
Constructor Summary | |
---|---|
InstanceKeyDataSource()
Default no-arg constructor for Serialization |
Method Summary | |
---|---|
abstract void | close()
Close pool being maintained by this datasource. |
Connection | getConnection()
Attempt to establish a database connection. |
Connection | getConnection(String username, String password)
Attempt to establish a database connection. |
ConnectionPoolDataSource | getConnectionPoolDataSource()
Get the value of connectionPoolDataSource. |
String | getDataSourceName()
Get the name of the ConnectionPoolDataSource which backs this pool.
|
int | getDefaultTransactionIsolation()
Get the value of defaultTransactionIsolation, which defines the state of
connections handed out from this pool. |
String | getDescription()
Get the description. |
String | getJndiEnvironment(String key)
Get the value of jndiEnvironment which is used when instantiating
a jndi InitialContext. |
int | getLoginTimeout()
Get the value of loginTimeout. |
PrintWriter | getLogWriter()
Get the value of logWriter. |
int | getMinEvictableIdleTimeMillis()
Returns the minimum amount of time an object may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any).
|
int | getNumTestsPerEvictionRun()
Returns the number of objects to examine during each run of the
idle object evictor thread (if any).
|
Reference | getReference()
Retrieves the Reference of this object.
|
boolean | getTestOnBorrow()
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
before being returned by the {*link #borrowObject}
method. |
boolean | getTestOnReturn()
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
before being returned to the pool within the
{*link #returnObject}.
|
boolean | getTestWhileIdle()
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
by the idle object evictor (if any). |
int | getTimeBetweenEvictionRunsMillis()
Returns the number of milliseconds to sleep between runs of the
idle object evictor thread.
|
String | getValidationQuery()
The SQL query that will be used to validate connections from this pool
before returning them to the caller. |
boolean | isDefaultAutoCommit()
Get the value of defaultAutoCommit, which defines the state of
connections handed out from this pool. |
boolean | isDefaultReadOnly()
Get the value of defaultReadOnly, which defines the state of
connections handed out from this pool. |
boolean | isRollbackAfterValidation()
Whether a rollback will be issued after executing the SQL query
that will be used to validate connections from this pool
before returning them to the caller.
|
boolean | isTestOnBorrow() |
boolean | isTestOnReturn() |
boolean | isTestWhileIdle() |
void | setConnectionPoolDataSource(ConnectionPoolDataSource v)
Set the backend ConnectionPoolDataSource. |
void | setDataSourceName(String v)
Set the name of the ConnectionPoolDataSource which backs this pool.
|
void | setDefaultAutoCommit(boolean v)
Set the value of defaultAutoCommit, which defines the state of
connections handed out from this pool. |
void | setDefaultReadOnly(boolean v)
Set the value of defaultReadOnly, which defines the state of
connections handed out from this pool. |
void | setDefaultTransactionIsolation(int v)
Set the value of defaultTransactionIsolation, which defines the state of
connections handed out from this pool. |
void | setDescription(String v)
Set the description. |
void | setJndiEnvironment(String key, String value)
Sets the value of the given JNDI environment property to be used when
instantiating a JNDI InitialContext. |
void | setLoginTimeout(int v)
Set the value of loginTimeout. |
void | setLogWriter(PrintWriter v)
Set the value of logWriter. |
void | setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
Sets the minimum amount of time an object may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any).
|
void | setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the number of objects to examine during each run of the
idle object evictor thread (if any).
|
void | setRollbackAfterValidation(boolean rollbackAfterValidation)
Whether a rollback will be issued after executing the SQL query
that will be used to validate connections from this pool
before returning them to the caller. |
void | setTestOnBorrow(boolean testOnBorrow)
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
before being returned by the {*link #borrowObject}
method. |
void | setTestOnReturn(boolean testOnReturn)
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
before being returned to the pool within the
{*link #returnObject}. |
void | setTestWhileIdle(boolean testWhileIdle)
When true, objects will be
{*link PoolableObjectFactory#validateObject validated}
by the idle object evictor (if any). |
void | setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
Sets the number of milliseconds to sleep between runs of the
idle object evictor thread.
|
void | setValidationQuery(String validationQuery)
The SQL query that will be used to validate connections from this pool
before returning them to the caller. |
Returns: value of connectionPoolDataSource.
Returns: value of dataSourceName.
Returns: value of defaultTransactionIsolation.
Returns: value of description.
Returns: value of jndiEnvironment.
Returns: value of loginTimeout.
Returns: value of logWriter.
See Also: InstanceKeyDataSource InstanceKeyDataSource
See Also: InstanceKeyDataSource InstanceKeyDataSource
InstanceKeyDataSource
subclasses
should override this method. The implementaion included below
is not robust and will be removed at the next major version DBCP
release.
Returns: The non-null Reference of this object.
Throws: NamingException If a naming exception was encountered while retrieving the reference.
See Also: InstanceKeyDataSource
See Also: InstanceKeyDataSource
See Also: InstanceKeyDataSource InstanceKeyDataSource
See Also: InstanceKeyDataSource
Returns: value of defaultAutoCommit.
Returns: value of defaultReadOnly.
Returns: true if a rollback will be issued after executing the validation query
Since: 1.2.2
See Also: InstanceKeyDataSource
See Also: InstanceKeyDataSource
See Also: InstanceKeyDataSource
Parameters: v Value to assign to connectionPoolDataSource.
Parameters: v Value to assign to dataSourceName.
Parameters: v Value to assign to defaultAutoCommit.
Parameters: v Value to assign to defaultReadOnly.
Parameters: v Value to assign to defaultTransactionIsolation
Parameters: v Value to assign to description.
Parameters: key the JNDI environment property to set. value the value assigned to specified JNDI environment property.
Parameters: v Value to assign to loginTimeout.
Parameters: v Value to assign to logWriter.
See Also: InstanceKeyDataSource InstanceKeyDataSource
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.
See Also: InstanceKeyDataSource InstanceKeyDataSource
Parameters: rollbackAfterValidation new property value
Since: 1.2.2
true
value to have any effect,
the validationQuery
property must be set to a non-null
string.
See Also: InstanceKeyDataSource
true
value to have any effect,
the validationQuery
property must be set to a non-null
string.
See Also: InstanceKeyDataSource
true
value to have any effect,
the validationQuery
property must be set to a non-null
string.
See Also: InstanceKeyDataSource InstanceKeyDataSource
See Also: InstanceKeyDataSource