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(String)
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(ConnectionPoolDataSource)
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 Driver
implementation.
The package documentation contains an example using Apache Tomcat and JNDI and it also contains a non-JNDI example.
Modifier and Type | Field and Description |
---|---|
protected static int |
UNKNOWN_TRANSACTIONISOLATION
Internal constant to indicate the level is not set.
|
Constructor and Description |
---|
InstanceKeyDataSource()
Default no-arg constructor for Serialization
|
Modifier and Type | Method and Description |
---|---|
protected void |
assertInitializationAllowed()
Throws an IllegalStateException, if a PooledConnection has already
been requested.
|
abstract void |
close()
Close the connection pool being maintained by this datasource.
|
Connection |
getConnection()
Attempt to establish a database connection.
|
Connection |
getConnection(String username,
String password)
Attempt to retrieve a database connection using
getPooledConnectionAndInfo(String, String)
with the provided username and password. |
protected abstract org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionManager |
getConnectionManager(org.apache.tomcat.dbcp.dbcp2.datasources.UserPassKey upkey) |
ConnectionPoolDataSource |
getConnectionPoolDataSource()
Get the value of connectionPoolDataSource.
|
String |
getDataSourceName()
Get the name of the ConnectionPoolDataSource which backs this pool.
|
boolean |
getDefaultBlockWhenExhausted()
Gets the default value for
BaseObjectPoolConfig.getBlockWhenExhausted() for each per
user pool. |
String |
getDefaultEvictionPolicyClassName()
Gets the default value for
BaseObjectPoolConfig.getEvictionPolicyClassName() for
each per user pool. |
boolean |
getDefaultLifo()
Gets the default value for
BaseObjectPoolConfig.getLifo() for each per user pool. |
int |
getDefaultMaxIdle()
Gets the default value for
GenericKeyedObjectPoolConfig.getMaxIdlePerKey() for each per user
pool. |
int |
getDefaultMaxTotal()
Gets the default value for
GenericKeyedObjectPoolConfig.getMaxTotalPerKey() for each per
user pool. |
long |
getDefaultMaxWaitMillis()
Gets the default value for
BaseObjectPoolConfig.getMaxWaitMillis() for each per user
pool. |
long |
getDefaultMinEvictableIdleTimeMillis()
Gets the default value for
BaseObjectPoolConfig.getMinEvictableIdleTimeMillis() for
each per user pool. |
int |
getDefaultMinIdle()
Gets the default value for
GenericKeyedObjectPoolConfig.getMinIdlePerKey() for each per user
pool. |
int |
getDefaultNumTestsPerEvictionRun()
Gets the default value for
BaseObjectPoolConfig.getNumTestsPerEvictionRun() for each
per user pool. |
long |
getDefaultSoftMinEvictableIdleTimeMillis()
Gets the default value for
GenericObjectPool#getSoftMinEvictableIdleTimeMillis() for each
per user pool. |
boolean |
getDefaultTestOnBorrow()
Gets the default value for
GenericObjectPool#getTestOnBorrow() for each per user pool. |
boolean |
getDefaultTestOnCreate()
Gets the default value for
GenericObjectPool#getTestOnCreate() for each per user pool. |
boolean |
getDefaultTestOnReturn()
Gets the default value for
GenericObjectPool#getTestOnReturn() for each per user pool. |
boolean |
getDefaultTestWhileIdle()
Gets the default value for
GenericObjectPool#getTestWhileIdle() for each per user pool. |
long |
getDefaultTimeBetweenEvictionRunsMillis()
Gets the default value for
GenericObjectPool#getTimeBetweenEvictionRunsMillis () for each
per user pool. |
int |
getDefaultTransactionIsolation()
Get the value of defaultTransactionIsolation, which defines the state of
connections handed out from this pool.
|
String |
getDescription()
Get the description.
|
protected String |
getInstanceKey() |
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.
|
long |
getMaxConnLifetimeMillis()
Returns the maximum permitted lifetime of a connection in milliseconds.
|
Logger |
getParentLogger() |
protected abstract org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionAndInfo |
getPooledConnectionAndInfo(String username,
String password) |
String |
getValidationQuery()
The SQL query that will be used to validate connections from this pool
before returning them to the caller.
|
int |
getValidationQueryTimeout()
Returns the timeout in seconds before the validation query fails.
|
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 |
isWrapperFor(Class<?> iface) |
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 |
setDefaultBlockWhenExhausted(boolean blockWhenExhausted)
Sets the default value for
BaseObjectPoolConfig.getBlockWhenExhausted() for each per
user pool. |
void |
setDefaultEvictionPolicyClassName(String evictionPolicyClassName)
Sets the default value for
BaseObjectPoolConfig.getEvictionPolicyClassName() for
each per user pool. |
void |
setDefaultLifo(boolean lifo)
Sets the default value for
BaseObjectPoolConfig.getLifo() for each per user pool. |
void |
setDefaultMaxIdle(int maxIdle)
Sets the default value for
GenericKeyedObjectPoolConfig.getMaxIdlePerKey() for each per user
pool. |
void |
setDefaultMaxTotal(int maxTotal)
Sets the default value for
GenericKeyedObjectPoolConfig.getMaxTotalPerKey() for each per
user pool. |
void |
setDefaultMaxWaitMillis(long maxWaitMillis)
Sets the default value for
BaseObjectPoolConfig.getMaxWaitMillis() for each per user
pool. |
void |
setDefaultMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the default value for
BaseObjectPoolConfig.getMinEvictableIdleTimeMillis() for
each per user pool. |
void |
setDefaultMinIdle(int minIdle)
Sets the default value for
GenericKeyedObjectPoolConfig.getMinIdlePerKey() for each per user
pool. |
void |
setDefaultNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the default value for
BaseObjectPoolConfig.getNumTestsPerEvictionRun() for each
per user pool. |
void |
setDefaultReadOnly(Boolean v)
Set the value of defaultReadOnly, which defines the state of
connections handed out from this pool.
|
void |
setDefaultSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
Sets the default value for
GenericObjectPool#getSoftMinEvictableIdleTimeMillis() for each per user pool. |
void |
setDefaultTestOnBorrow(boolean testOnBorrow)
Sets the default value for
GenericObjectPool#getTestOnBorrow() for each per user pool. |
void |
setDefaultTestOnCreate(boolean testOnCreate)
Sets the default value for
GenericObjectPool#getTestOnCreate() for each per user pool. |
void |
setDefaultTestOnReturn(boolean testOnReturn)
Sets the default value for
GenericObjectPool#getTestOnReturn() for each per user pool. |
void |
setDefaultTestWhileIdle(boolean testWhileIdle)
Sets the default value for
GenericObjectPool#getTestWhileIdle() for each per user pool. |
void |
setDefaultTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the default value for
GenericObjectPool#getTimeBetweenEvictionRunsMillis () for each
per user 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 |
setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
Sets the maximum permitted lifetime of a connection in
milliseconds.
|
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.
|
protected abstract void |
setupDefaults(Connection con,
String username) |
void |
setValidationQuery(String validationQuery)
The SQL query that will be used to validate connections from this pool
before returning them to the caller.
|
void |
setValidationQueryTimeout(int validationQueryTimeout)
Sets the timeout in seconds before the validation query fails.
|
protected ConnectionPoolDataSource |
testCPDS(String username,
String password) |
<T> T |
unwrap(Class<T> iface) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getReference
protected static final int UNKNOWN_TRANSACTIONISOLATION
public InstanceKeyDataSource()
protected void assertInitializationAllowed() throws IllegalStateException
IllegalStateException
public abstract void close() throws Exception
Exception
protected abstract org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionManager getConnectionManager(org.apache.tomcat.dbcp.dbcp2.datasources.UserPassKey upkey)
public boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor
in interface Wrapper
SQLException
public <T> T unwrap(Class<T> iface) throws SQLException
unwrap
in interface Wrapper
SQLException
public Logger getParentLogger() throws SQLFeatureNotSupportedException
getParentLogger
in interface CommonDataSource
SQLFeatureNotSupportedException
public boolean getDefaultBlockWhenExhausted()
BaseObjectPoolConfig.getBlockWhenExhausted()
for each per
user pool.public void setDefaultBlockWhenExhausted(boolean blockWhenExhausted)
BaseObjectPoolConfig.getBlockWhenExhausted()
for each per
user pool.public String getDefaultEvictionPolicyClassName()
BaseObjectPoolConfig.getEvictionPolicyClassName()
for
each per user pool.public void setDefaultEvictionPolicyClassName(String evictionPolicyClassName)
BaseObjectPoolConfig.getEvictionPolicyClassName()
for
each per user pool.public boolean getDefaultLifo()
BaseObjectPoolConfig.getLifo()
for each per user pool.public void setDefaultLifo(boolean lifo)
BaseObjectPoolConfig.getLifo()
for each per user pool.public int getDefaultMaxIdle()
GenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user
pool.public void setDefaultMaxIdle(int maxIdle)
GenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user
pool.public int getDefaultMaxTotal()
GenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per
user pool.public void setDefaultMaxTotal(int maxTotal)
GenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per
user pool.public long getDefaultMaxWaitMillis()
BaseObjectPoolConfig.getMaxWaitMillis()
for each per user
pool.public void setDefaultMaxWaitMillis(long maxWaitMillis)
BaseObjectPoolConfig.getMaxWaitMillis()
for each per user
pool.public long getDefaultMinEvictableIdleTimeMillis()
BaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for
each per user pool.public void setDefaultMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
BaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for
each per user pool.public int getDefaultMinIdle()
GenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user
pool.public void setDefaultMinIdle(int minIdle)
GenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user
pool.public int getDefaultNumTestsPerEvictionRun()
BaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each
per user pool.public void setDefaultNumTestsPerEvictionRun(int numTestsPerEvictionRun)
BaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each
per user pool.public long getDefaultSoftMinEvictableIdleTimeMillis()
GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each
per user pool.public void setDefaultSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.public boolean getDefaultTestOnCreate()
GenericObjectPool#getTestOnCreate()
for each per user pool.public void setDefaultTestOnCreate(boolean testOnCreate)
GenericObjectPool#getTestOnCreate()
for each per user pool.public boolean getDefaultTestOnBorrow()
GenericObjectPool#getTestOnBorrow()
for each per user pool.public void setDefaultTestOnBorrow(boolean testOnBorrow)
GenericObjectPool#getTestOnBorrow()
for each per user pool.public boolean getDefaultTestOnReturn()
GenericObjectPool#getTestOnReturn()
for each per user pool.public void setDefaultTestOnReturn(boolean testOnReturn)
GenericObjectPool#getTestOnReturn()
for each per user pool.public boolean getDefaultTestWhileIdle()
GenericObjectPool#getTestWhileIdle()
for each per user pool.public void setDefaultTestWhileIdle(boolean testWhileIdle)
GenericObjectPool#getTestWhileIdle()
for each per user pool.public long getDefaultTimeBetweenEvictionRunsMillis()
GenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each
per user pool.public void setDefaultTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
GenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each
per user pool.public ConnectionPoolDataSource getConnectionPoolDataSource()
public void setConnectionPoolDataSource(ConnectionPoolDataSource v)
v
- Value to assign to connectionPoolDataSource.public String getDataSourceName()
public void setDataSourceName(String v)
v
- Value to assign to dataSourceName.public Boolean isDefaultAutoCommit()
null
which will use the default value for the
drive.public void setDefaultAutoCommit(Boolean v)
null
which will use the default value for the
drive.v
- Value to assign to defaultAutoCommit.public Boolean isDefaultReadOnly()
null
which will use the default value for the
drive.public void setDefaultReadOnly(Boolean v)
null
which will use the default value for the
drive.v
- Value to assign to defaultReadOnly.public int getDefaultTransactionIsolation()
public void setDefaultTransactionIsolation(int v)
v
- Value to assign to defaultTransactionIsolationpublic String getDescription()
public void setDescription(String v)
v
- Value to assign to description.protected String getInstanceKey()
public String getJndiEnvironment(String key)
public void setJndiEnvironment(String key, String value)
key
- the JNDI environment property to set.value
- the value assigned to specified JNDI environment property.public int getLoginTimeout()
getLoginTimeout
in interface CommonDataSource
public void setLoginTimeout(int v)
setLoginTimeout
in interface CommonDataSource
v
- Value to assign to loginTimeout.public PrintWriter getLogWriter()
getLogWriter
in interface CommonDataSource
public void setLogWriter(PrintWriter v)
setLogWriter
in interface CommonDataSource
v
- Value to assign to logWriter.public String getValidationQuery()
Connection.isValid(int)
will be used
to validate connections.public void setValidationQuery(String validationQuery)
Connection.isValid(int)
.public int getValidationQueryTimeout()
public void setValidationQueryTimeout(int validationQueryTimeout)
validationQueryTimeout
- The new timeout in secondspublic boolean isRollbackAfterValidation()
public void setRollbackAfterValidation(boolean rollbackAfterValidation)
rollbackAfterValidation
- new property valuepublic long getMaxConnLifetimeMillis()
public void setMaxConnLifetimeMillis(long maxConnLifetimeMillis)
Sets the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.
Note: this method currently has no effect once the pool has been
initialized. The pool is initialized the first time one of the
following methods is invoked: getConnection, setLogwriter,
setLoginTimeout, getLoginTimeout, getLogWriter.
public Connection getConnection() throws SQLException
getConnection
in interface DataSource
SQLException
public Connection getConnection(String username, String password) throws SQLException
getPooledConnectionAndInfo(String, String)
with the provided username and password. The password on the PooledConnectionAndInfo
instance returned by getPooledConnectionAndInfo
is compared to the password
parameter. If the comparison fails, a database connection using the supplied username and password
is attempted. If the connection attempt fails, an SQLException is thrown, indicating that the given password
did not match the password used to create the pooled connection. If the connection attempt succeeds, this
means that the database password has been changed. In this case, the PooledConnectionAndInfo
instance retrieved with the old password is destroyed and the getPooledConnectionAndInfo
is
repeatedly invoked until a PooledConnectionAndInfo
instance with the new password is returned.getConnection
in interface DataSource
SQLException
protected abstract org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionAndInfo getPooledConnectionAndInfo(String username, String password) throws SQLException
SQLException
protected abstract void setupDefaults(Connection con, String username) throws SQLException
SQLException
protected ConnectionPoolDataSource testCPDS(String username, String password) throws NamingException, SQLException
NamingException
SQLException
Copyright © 2000-2014 Apache Software Foundation. All Rights Reserved.