Class InstanceKeyDataSource
- java.lang.Object
-
- org.datanucleus.store.rdbms.datasource.dbcp2.datasources.InstanceKeyDataSource
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.AutoCloseable
,java.sql.Wrapper
,javax.naming.Referenceable
,javax.sql.CommonDataSource
,javax.sql.DataSource
- Direct Known Subclasses:
PerUserPoolDataSource
,SharedPoolDataSource
public abstract class InstanceKeyDataSource extends java.lang.Object implements javax.sql.DataSource, javax.naming.Referenceable, java.io.Serializable, java.lang.AutoCloseable
The base class for
SharedPoolDataSource
andPerUserPoolDataSource
. 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-dbcp2.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 aConnectionPoolDataSource
that can be specified via thesetDataSourceName(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 thesetConnectionPoolDataSource(ConnectionPoolDataSource)
method.The dbcp package contains an adapter,
DriverAdapterCPDS
, that can be used to allow the use ofDataSource
's based on this class with JDBC driver implementations that do not supply aConnectionPoolDataSource
, but still provide aDriver
implementation.The package documentation contains an example using Apache Tomcat and JNDI and it also contains a non-JNDI example.
- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
BAD_TRANSACTION_ISOLATION
private javax.sql.ConnectionPoolDataSource
dataSource
Underlying source of PooledConnectionsprivate java.lang.String
dataSourceName
DataSource Name used to find the ConnectionPoolDataSourceprivate java.lang.Boolean
defaultAutoCommit
private boolean
defaultBlockWhenExhausted
private java.lang.String
defaultEvictionPolicyClassName
private boolean
defaultLifo
private int
defaultMaxIdle
private int
defaultMaxTotal
private long
defaultMaxWaitMillis
private long
defaultMinEvictableIdleTimeMillis
private int
defaultMinIdle
private int
defaultNumTestsPerEvictionRun
private java.lang.Boolean
defaultReadOnly
private long
defaultSoftMinEvictableIdleTimeMillis
private boolean
defaultTestOnBorrow
private boolean
defaultTestOnCreate
private boolean
defaultTestOnReturn
private boolean
defaultTestWhileIdle
private long
defaultTimeBetweenEvictionRunsMillis
private int
defaultTransactionIsolation
private java.lang.String
description
Descriptionprivate static java.lang.String
GET_CONNECTION_CALLED
private boolean
getConnectionCalled
Guards property setters - once true, setters throw IllegalStateExceptionprivate java.lang.String
instanceKey
Instance keyprivate java.util.Properties
jndiEnvironment
Environment that may be used to set up a JNDI initial context.private int
loginTimeout
Login TimeOut in secondsprivate java.io.PrintWriter
logWriter
Log streamprivate long
maxConnLifetimeMillis
private boolean
rollbackAfterValidation
private static long
serialVersionUID
protected static int
UNKNOWN_TRANSACTIONISOLATION
Internal constant to indicate the level is not set.private java.lang.String
validationQuery
private int
validationQueryTimeoutSeconds
-
Constructor Summary
Constructors Constructor Description InstanceKeyDataSource()
Default no-arg constructor for Serialization
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
assertInitializationAllowed()
Throws an IllegalStateException, if a PooledConnection has already been requested.abstract void
close()
Closes the connection pool being maintained by this datasource.private void
closeDueToException(PooledConnectionAndInfo info)
java.sql.Connection
getConnection()
Attempts to establish a database connection.java.sql.Connection
getConnection(java.lang.String userName, java.lang.String userPassword)
Attempts to retrieve a database connection usinggetPooledConnectionAndInfo(String, String)
with the provided user name and password.protected abstract PooledConnectionManager
getConnectionManager(UserPassKey upkey)
javax.sql.ConnectionPoolDataSource
getConnectionPoolDataSource()
Gets the value of connectionPoolDataSource.java.lang.String
getDataSourceName()
Gets the name of the ConnectionPoolDataSource which backs this pool.boolean
getDefaultBlockWhenExhausted()
Gets the default value forBaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.java.lang.String
getDefaultEvictionPolicyClassName()
Gets the default value forBaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.boolean
getDefaultLifo()
Gets the default value forBaseObjectPoolConfig.getLifo()
for each per user pool.int
getDefaultMaxIdle()
Gets the default value forGenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.int
getDefaultMaxTotal()
Gets the default value forGenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.long
getDefaultMaxWaitMillis()
Gets the default value forBaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.long
getDefaultMinEvictableIdleTimeMillis()
Gets the default value forBaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.int
getDefaultMinIdle()
Gets the default value forGenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.int
getDefaultNumTestsPerEvictionRun()
Gets the default value forBaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.long
getDefaultSoftMinEvictableIdleTimeMillis()
Gets the default value forGenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.boolean
getDefaultTestOnBorrow()
Gets the default value forGenericObjectPool#getTestOnBorrow()
for each per user pool.boolean
getDefaultTestOnCreate()
Gets the default value forGenericObjectPool#getTestOnCreate()
for each per user pool.boolean
getDefaultTestOnReturn()
Gets the default value forGenericObjectPool#getTestOnReturn()
for each per user pool.boolean
getDefaultTestWhileIdle()
Gets the default value forGenericObjectPool#getTestWhileIdle()
for each per user pool.long
getDefaultTimeBetweenEvictionRunsMillis()
Gets the default value forGenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.int
getDefaultTransactionIsolation()
Gets the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool.java.lang.String
getDescription()
Gets the description.protected java.lang.String
getInstanceKey()
java.lang.String
getJndiEnvironment(java.lang.String key)
Gets the value of jndiEnvironment which is used when instantiating a JNDI InitialContext.int
getLoginTimeout()
Gets the value of loginTimeout.java.io.PrintWriter
getLogWriter()
Gets the value of logWriter.long
getMaxConnLifetimeMillis()
Returns the maximum permitted lifetime of a connection in milliseconds.java.util.logging.Logger
getParentLogger()
protected abstract PooledConnectionAndInfo
getPooledConnectionAndInfo(java.lang.String userName, java.lang.String userPassword)
java.lang.String
getValidationQuery()
Gets 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.java.lang.Boolean
isDefaultAutoCommit()
Gets the value of defaultAutoCommit, which defines the state of connections handed out from this pool.java.lang.Boolean
isDefaultReadOnly()
Gets 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(java.lang.Class<?> iface)
void
setConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource v)
Sets the backend ConnectionPoolDataSource.void
setDataSourceName(java.lang.String v)
Sets the name of the ConnectionPoolDataSource which backs this pool.void
setDefaultAutoCommit(java.lang.Boolean v)
Sets the value of defaultAutoCommit, which defines the state of connections handed out from this pool.void
setDefaultBlockWhenExhausted(boolean blockWhenExhausted)
Sets the default value forBaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.void
setDefaultEvictionPolicyClassName(java.lang.String evictionPolicyClassName)
Sets the default value forBaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.void
setDefaultLifo(boolean lifo)
Sets the default value forBaseObjectPoolConfig.getLifo()
for each per user pool.void
setDefaultMaxIdle(int maxIdle)
Sets the default value forGenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.void
setDefaultMaxTotal(int maxTotal)
Sets the default value forGenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.void
setDefaultMaxWaitMillis(long maxWaitMillis)
Sets the default value forBaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.void
setDefaultMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the default value forBaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.void
setDefaultMinIdle(int minIdle)
Sets the default value forGenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.void
setDefaultNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the default value forBaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.void
setDefaultReadOnly(java.lang.Boolean v)
Sets the value of defaultReadOnly, which defines the state of connections handed out from this pool.void
setDefaultSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
Sets the default value forGenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.void
setDefaultTestOnBorrow(boolean testOnBorrow)
Sets the default value forGenericObjectPool#getTestOnBorrow()
for each per user pool.void
setDefaultTestOnCreate(boolean testOnCreate)
Sets the default value forGenericObjectPool#getTestOnCreate()
for each per user pool.void
setDefaultTestOnReturn(boolean testOnReturn)
Sets the default value forGenericObjectPool#getTestOnReturn()
for each per user pool.void
setDefaultTestWhileIdle(boolean testWhileIdle)
Sets the default value forGenericObjectPool#getTestWhileIdle()
for each per user pool.void
setDefaultTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the default value forGenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.void
setDefaultTransactionIsolation(int v)
Sets the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool.void
setDescription(java.lang.String v)
Sets the description.void
setJndiEnvironment(java.lang.String key, java.lang.String value)
Sets the value of the given JNDI environment property to be used when instantiating a JNDI InitialContext.(package private) void
setJndiEnvironment(java.util.Properties properties)
Sets the JNDI environment to be used when instantiating a JNDI InitialContext.void
setLoginTimeout(int v)
Sets the value of loginTimeout.void
setLogWriter(java.io.PrintWriter v)
Sets 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(java.sql.Connection connection, java.lang.String userName)
void
setValidationQuery(java.lang.String validationQuery)
Sets the SQL query that will be used to validate connections from this pool before returning them to the caller.void
setValidationQueryTimeout(int validationQueryTimeoutSeconds)
Sets the timeout in seconds before the validation query fails.protected javax.sql.ConnectionPoolDataSource
testCPDS(java.lang.String userName, java.lang.String userPassword)
java.lang.String
toString()
protected void
toStringFields(java.lang.StringBuilder builder)
<T> T
unwrap(java.lang.Class<T> iface)
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
GET_CONNECTION_CALLED
private static final java.lang.String GET_CONNECTION_CALLED
- See Also:
- Constant Field Values
-
BAD_TRANSACTION_ISOLATION
private static final java.lang.String BAD_TRANSACTION_ISOLATION
- See Also:
- Constant Field Values
-
UNKNOWN_TRANSACTIONISOLATION
protected static final int UNKNOWN_TRANSACTIONISOLATION
Internal constant to indicate the level is not set.- See Also:
- Constant Field Values
-
getConnectionCalled
private volatile boolean getConnectionCalled
Guards property setters - once true, setters throw IllegalStateException
-
dataSource
private javax.sql.ConnectionPoolDataSource dataSource
Underlying source of PooledConnections
-
dataSourceName
private java.lang.String dataSourceName
DataSource Name used to find the ConnectionPoolDataSource
-
description
private java.lang.String description
Description
-
jndiEnvironment
private java.util.Properties jndiEnvironment
Environment that may be used to set up a JNDI initial context.
-
loginTimeout
private int loginTimeout
Login TimeOut in seconds
-
logWriter
private java.io.PrintWriter logWriter
Log stream
-
instanceKey
private java.lang.String instanceKey
Instance key
-
defaultBlockWhenExhausted
private boolean defaultBlockWhenExhausted
-
defaultEvictionPolicyClassName
private java.lang.String defaultEvictionPolicyClassName
-
defaultLifo
private boolean defaultLifo
-
defaultMaxIdle
private int defaultMaxIdle
-
defaultMaxTotal
private int defaultMaxTotal
-
defaultMaxWaitMillis
private long defaultMaxWaitMillis
-
defaultMinEvictableIdleTimeMillis
private long defaultMinEvictableIdleTimeMillis
-
defaultMinIdle
private int defaultMinIdle
-
defaultNumTestsPerEvictionRun
private int defaultNumTestsPerEvictionRun
-
defaultSoftMinEvictableIdleTimeMillis
private long defaultSoftMinEvictableIdleTimeMillis
-
defaultTestOnCreate
private boolean defaultTestOnCreate
-
defaultTestOnBorrow
private boolean defaultTestOnBorrow
-
defaultTestOnReturn
private boolean defaultTestOnReturn
-
defaultTestWhileIdle
private boolean defaultTestWhileIdle
-
defaultTimeBetweenEvictionRunsMillis
private long defaultTimeBetweenEvictionRunsMillis
-
validationQuery
private java.lang.String validationQuery
-
validationQueryTimeoutSeconds
private int validationQueryTimeoutSeconds
-
rollbackAfterValidation
private boolean rollbackAfterValidation
-
maxConnLifetimeMillis
private long maxConnLifetimeMillis
-
defaultAutoCommit
private java.lang.Boolean defaultAutoCommit
-
defaultTransactionIsolation
private int defaultTransactionIsolation
-
defaultReadOnly
private java.lang.Boolean defaultReadOnly
-
-
Method Detail
-
assertInitializationAllowed
protected void assertInitializationAllowed() throws java.lang.IllegalStateException
Throws an IllegalStateException, if a PooledConnection has already been requested.- Throws:
java.lang.IllegalStateException
- Thrown if a PooledConnection has already been requested.
-
close
public abstract void close() throws java.lang.Exception
Closes the connection pool being maintained by this datasource.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
getConnectionManager
protected abstract PooledConnectionManager getConnectionManager(UserPassKey upkey)
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
- Specified by:
isWrapperFor
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Throws:
java.sql.SQLException
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
- Specified by:
getParentLogger
in interfacejavax.sql.CommonDataSource
- Throws:
java.sql.SQLFeatureNotSupportedException
-
getDefaultBlockWhenExhausted
public boolean getDefaultBlockWhenExhausted()
Gets the default value forBaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.
-
setDefaultBlockWhenExhausted
public void setDefaultBlockWhenExhausted(boolean blockWhenExhausted)
Sets the default value forBaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.- Parameters:
blockWhenExhausted
- The default value forBaseObjectPoolConfig.getBlockWhenExhausted()
for each per user pool.
-
getDefaultEvictionPolicyClassName
public java.lang.String getDefaultEvictionPolicyClassName()
Gets the default value forBaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.
-
setDefaultEvictionPolicyClassName
public void setDefaultEvictionPolicyClassName(java.lang.String evictionPolicyClassName)
Sets the default value forBaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.- Parameters:
evictionPolicyClassName
- The default value forBaseObjectPoolConfig.getEvictionPolicyClassName()
for each per user pool.
-
getDefaultLifo
public boolean getDefaultLifo()
Gets the default value forBaseObjectPoolConfig.getLifo()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getLifo()
for each per user pool.
-
setDefaultLifo
public void setDefaultLifo(boolean lifo)
Sets the default value forBaseObjectPoolConfig.getLifo()
for each per user pool.- Parameters:
lifo
- The default value forBaseObjectPoolConfig.getLifo()
for each per user pool.
-
getDefaultMaxIdle
public int getDefaultMaxIdle()
Gets the default value forGenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.- Returns:
- The default value for
GenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.
-
setDefaultMaxIdle
public void setDefaultMaxIdle(int maxIdle)
Sets the default value forGenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.- Parameters:
maxIdle
- The default value forGenericKeyedObjectPoolConfig.getMaxIdlePerKey()
for each per user pool.
-
getDefaultMaxTotal
public int getDefaultMaxTotal()
Gets the default value forGenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.- Returns:
- The default value for
GenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.
-
setDefaultMaxTotal
public void setDefaultMaxTotal(int maxTotal)
Sets the default value forGenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.- Parameters:
maxTotal
- The default value forGenericKeyedObjectPoolConfig.getMaxTotalPerKey()
for each per user pool.
-
getDefaultMaxWaitMillis
public long getDefaultMaxWaitMillis()
Gets the default value forBaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.
-
setDefaultMaxWaitMillis
public void setDefaultMaxWaitMillis(long maxWaitMillis)
Sets the default value forBaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.- Parameters:
maxWaitMillis
- The default value forBaseObjectPoolConfig.getMaxWaitMillis()
for each per user pool.
-
getDefaultMinEvictableIdleTimeMillis
public long getDefaultMinEvictableIdleTimeMillis()
Gets the default value forBaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.
-
setDefaultMinEvictableIdleTimeMillis
public void setDefaultMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis)
Sets the default value forBaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.- Parameters:
minEvictableIdleTimeMillis
- The default value forBaseObjectPoolConfig.getMinEvictableIdleTimeMillis()
for each per user pool.
-
getDefaultMinIdle
public int getDefaultMinIdle()
Gets the default value forGenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.- Returns:
- The default value for
GenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.
-
setDefaultMinIdle
public void setDefaultMinIdle(int minIdle)
Sets the default value forGenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.- Parameters:
minIdle
- The default value forGenericKeyedObjectPoolConfig.getMinIdlePerKey()
for each per user pool.
-
getDefaultNumTestsPerEvictionRun
public int getDefaultNumTestsPerEvictionRun()
Gets the default value forBaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.- Returns:
- The default value for
BaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.
-
setDefaultNumTestsPerEvictionRun
public void setDefaultNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Sets the default value forBaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.- Parameters:
numTestsPerEvictionRun
- The default value forBaseObjectPoolConfig.getNumTestsPerEvictionRun()
for each per user pool.
-
getDefaultSoftMinEvictableIdleTimeMillis
public long getDefaultSoftMinEvictableIdleTimeMillis()
Gets the default value forGenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.
-
setDefaultSoftMinEvictableIdleTimeMillis
public void setDefaultSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis)
Sets the default value forGenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.- Parameters:
softMinEvictableIdleTimeMillis
- The default value forGenericObjectPool#getSoftMinEvictableIdleTimeMillis()
for each per user pool.
-
getDefaultTestOnCreate
public boolean getDefaultTestOnCreate()
Gets the default value forGenericObjectPool#getTestOnCreate()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getTestOnCreate()
for each per user pool.
-
setDefaultTestOnCreate
public void setDefaultTestOnCreate(boolean testOnCreate)
Sets the default value forGenericObjectPool#getTestOnCreate()
for each per user pool.- Parameters:
testOnCreate
- The default value forGenericObjectPool#getTestOnCreate()
for each per user pool.
-
getDefaultTestOnBorrow
public boolean getDefaultTestOnBorrow()
Gets the default value forGenericObjectPool#getTestOnBorrow()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getTestOnBorrow()
for each per user pool.
-
setDefaultTestOnBorrow
public void setDefaultTestOnBorrow(boolean testOnBorrow)
Sets the default value forGenericObjectPool#getTestOnBorrow()
for each per user pool.- Parameters:
testOnBorrow
- The default value forGenericObjectPool#getTestOnBorrow()
for each per user pool.
-
getDefaultTestOnReturn
public boolean getDefaultTestOnReturn()
Gets the default value forGenericObjectPool#getTestOnReturn()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getTestOnReturn()
for each per user pool.
-
setDefaultTestOnReturn
public void setDefaultTestOnReturn(boolean testOnReturn)
Sets the default value forGenericObjectPool#getTestOnReturn()
for each per user pool.- Parameters:
testOnReturn
- The default value forGenericObjectPool#getTestOnReturn()
for each per user pool.
-
getDefaultTestWhileIdle
public boolean getDefaultTestWhileIdle()
Gets the default value forGenericObjectPool#getTestWhileIdle()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getTestWhileIdle()
for each per user pool.
-
setDefaultTestWhileIdle
public void setDefaultTestWhileIdle(boolean testWhileIdle)
Sets the default value forGenericObjectPool#getTestWhileIdle()
for each per user pool.- Parameters:
testWhileIdle
- The default value forGenericObjectPool#getTestWhileIdle()
for each per user pool.
-
getDefaultTimeBetweenEvictionRunsMillis
public long getDefaultTimeBetweenEvictionRunsMillis()
Gets the default value forGenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.- Returns:
- The default value for
GenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.
-
setDefaultTimeBetweenEvictionRunsMillis
public void setDefaultTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis)
Sets the default value forGenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.- Parameters:
timeBetweenEvictionRunsMillis
- The default value forGenericObjectPool#getTimeBetweenEvictionRunsMillis ()
for each per user pool.
-
getConnectionPoolDataSource
public javax.sql.ConnectionPoolDataSource getConnectionPoolDataSource()
Gets the value of connectionPoolDataSource. This method will return null, if the backing data source is being accessed via JNDI.- Returns:
- value of connectionPoolDataSource.
-
setConnectionPoolDataSource
public void setConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource v)
Sets the backend ConnectionPoolDataSource. This property should not be set if using JNDI to access the data source.- Parameters:
v
- Value to assign to connectionPoolDataSource.
-
getDataSourceName
public java.lang.String getDataSourceName()
Gets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the data source from a JNDI service provider.- Returns:
- value of dataSourceName.
-
setDataSourceName
public void setDataSourceName(java.lang.String v)
Sets the name of the ConnectionPoolDataSource which backs this pool. This name is used to look up the data source from a JNDI service provider.- Parameters:
v
- Value to assign to dataSourceName.
-
isDefaultAutoCommit
public java.lang.Boolean isDefaultAutoCommit()
Gets the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default isnull
which will use the default value for the drive.- Returns:
- value of defaultAutoCommit.
-
setDefaultAutoCommit
public void setDefaultAutoCommit(java.lang.Boolean v)
Sets the value of defaultAutoCommit, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setAutoCommit(boolean). The default isnull
which will use the default value for the drive.- Parameters:
v
- Value to assign to defaultAutoCommit.
-
isDefaultReadOnly
public java.lang.Boolean isDefaultReadOnly()
Gets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default isnull
which will use the default value for the drive.- Returns:
- value of defaultReadOnly.
-
setDefaultReadOnly
public void setDefaultReadOnly(java.lang.Boolean v)
Sets the value of defaultReadOnly, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setReadOnly(boolean). The default isnull
which will use the default value for the drive.- Parameters:
v
- Value to assign to defaultReadOnly.
-
getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()
Gets the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). If this method returns -1, the default is JDBC driver dependent.- Returns:
- value of defaultTransactionIsolation.
-
setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int v)
Sets the value of defaultTransactionIsolation, which defines the state of connections handed out from this pool. The value can be changed on the Connection using Connection.setTransactionIsolation(int). The default is JDBC driver dependent.- Parameters:
v
- Value to assign to defaultTransactionIsolation
-
getDescription
public java.lang.String getDescription()
Gets the description. This property is defined by JDBC as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.- Returns:
- value of description.
-
setDescription
public void setDescription(java.lang.String v)
Sets the description. This property is defined by JDBC as for use with GUI (or other) tools that might deploy the datasource. It serves no internal purpose.- Parameters:
v
- Value to assign to description.
-
getInstanceKey
protected java.lang.String getInstanceKey()
-
getJndiEnvironment
public java.lang.String getJndiEnvironment(java.lang.String key)
Gets the value of jndiEnvironment which is used when instantiating a JNDI InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.- Parameters:
key
- JNDI environment key.- Returns:
- value of jndiEnvironment.
-
setJndiEnvironment
public void setJndiEnvironment(java.lang.String key, java.lang.String value)
Sets the value of the given JNDI environment property to be used when instantiating a JNDI InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.- Parameters:
key
- the JNDI environment property to set.value
- the value assigned to specified JNDI environment property.
-
setJndiEnvironment
void setJndiEnvironment(java.util.Properties properties)
Sets the JNDI environment to be used when instantiating a JNDI InitialContext. This InitialContext is used to locate the backend ConnectionPoolDataSource.- Parameters:
properties
- the JNDI environment property to set which will overwrite any current settings
-
getLoginTimeout
public int getLoginTimeout()
Gets the value of loginTimeout.- Specified by:
getLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
getLoginTimeout
in interfacejavax.sql.DataSource
- Returns:
- value of loginTimeout.
-
setLoginTimeout
public void setLoginTimeout(int v)
Sets the value of loginTimeout.- Specified by:
setLoginTimeout
in interfacejavax.sql.CommonDataSource
- Specified by:
setLoginTimeout
in interfacejavax.sql.DataSource
- Parameters:
v
- Value to assign to loginTimeout.
-
getLogWriter
public java.io.PrintWriter getLogWriter()
Gets the value of logWriter.- Specified by:
getLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
getLogWriter
in interfacejavax.sql.DataSource
- Returns:
- value of logWriter.
-
setLogWriter
public void setLogWriter(java.io.PrintWriter v)
Sets the value of logWriter.- Specified by:
setLogWriter
in interfacejavax.sql.CommonDataSource
- Specified by:
setLogWriter
in interfacejavax.sql.DataSource
- Parameters:
v
- Value to assign to logWriter.
-
getValidationQuery
public java.lang.String getValidationQuery()
Gets the SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. If not specified,Connection.isValid(int)
will be used to validate connections.- Returns:
- The SQL query that will be used to validate connections from this pool before returning them to the caller.
-
setValidationQuery
public void setValidationQuery(java.lang.String validationQuery)
Sets the SQL query that will be used to validate connections from this pool before returning them to the caller. If specified, this query MUST be an SQL SELECT statement that returns at least one row. If not specified, connections will be validated usingConnection.isValid(int)
.- Parameters:
validationQuery
- The SQL query that will be used to validate connections from this pool before returning them to the caller.
-
getValidationQueryTimeout
public int getValidationQueryTimeout()
Returns the timeout in seconds before the validation query fails.- Returns:
- The timeout in seconds before the validation query fails.
-
setValidationQueryTimeout
public void setValidationQueryTimeout(int validationQueryTimeoutSeconds)
Sets the timeout in seconds before the validation query fails.- Parameters:
validationQueryTimeoutSeconds
- The new timeout in seconds
-
isRollbackAfterValidation
public 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.- Returns:
- true if a rollback will be issued after executing the validation query
-
setRollbackAfterValidation
public 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. Default behavior is NOT to issue a rollback. The setting will only have an effect if a validation query is set- Parameters:
rollbackAfterValidation
- new property value
-
getMaxConnLifetimeMillis
public long getMaxConnLifetimeMillis()
Returns the maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.- Returns:
- The maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.
-
setMaxConnLifetimeMillis
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.
- Parameters:
maxConnLifetimeMillis
- The maximum permitted lifetime of a connection in milliseconds. A value of zero or less indicates an infinite lifetime.
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Attempts to establish a database connection.- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String userName, java.lang.String userPassword) throws java.sql.SQLException
Attempts to retrieve a database connection usinggetPooledConnectionAndInfo(String, String)
with the provided user name and password. The password on thePooledConnectionAndInfo
instance returned bygetPooledConnectionAndInfo
is compared to thepassword
parameter. If the comparison fails, a database connection using the supplied user name 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, thePooledConnectionAndInfo
instance retrieved with the old password is destroyed and thegetPooledConnectionAndInfo
is repeatedly invoked until aPooledConnectionAndInfo
instance with the new password is returned.- Specified by:
getConnection
in interfacejavax.sql.DataSource
- Throws:
java.sql.SQLException
-
getPooledConnectionAndInfo
protected abstract PooledConnectionAndInfo getPooledConnectionAndInfo(java.lang.String userName, java.lang.String userPassword) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setupDefaults
protected abstract void setupDefaults(java.sql.Connection connection, java.lang.String userName) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
closeDueToException
private void closeDueToException(PooledConnectionAndInfo info)
-
testCPDS
protected javax.sql.ConnectionPoolDataSource testCPDS(java.lang.String userName, java.lang.String userPassword) throws javax.naming.NamingException, java.sql.SQLException
- Throws:
javax.naming.NamingException
java.sql.SQLException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Since:
- 2.6.0
-
toStringFields
protected void toStringFields(java.lang.StringBuilder builder)
-
-