Package org.apache.tomcat.jdbc.pool
Class DataSourceProxy
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.DataSourceProxy
-
- All Implemented Interfaces:
PoolConfiguration
- Direct Known Subclasses:
DataSource
public class DataSourceProxy extends java.lang.Object implements PoolConfiguration
The DataSource proxy lets us implements methods that don't exist in the current compiler JDK but might be methods that are part of a future JDK DataSource interface.
It's a trick to work around compiler issues when implementing interfaces. For example, I could put in Java 6 methods of javax.sql.DataSource here, and compile it with JDK 1.5 and still be able to run under Java 6 without getting NoSuchMethodException.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description protected ConnectionPool
pool
protected PoolConfiguration
poolProperties
-
Fields inherited from interface org.apache.tomcat.jdbc.pool.PoolConfiguration
PKG_PREFIX
-
-
Constructor Summary
Constructors Constructor Description DataSourceProxy()
DataSourceProxy(PoolConfiguration poolProperties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAbandoned()
Forces an abandon check on the connection pool.void
checkIdle()
Forces a check for resizing of the idle connectionsvoid
close()
void
close(boolean all)
ConnectionPool
createPool()
Sets up the connection pool, by creating a pooling driver.int
getAbandonWhenPercentageFull()
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.int
getActive()
long
getBorrowedCount()
The total number of connections borrowed from this pool.boolean
getCommitOnReturn()
java.sql.Connection
getConnection()
Get a database connection.java.sql.Connection
getConnection(java.lang.String username, java.lang.String password)
Get a database connection.java.util.concurrent.Future<java.sql.Connection>
getConnectionAsync()
Invokes an sync operation to retrieve the connection.java.lang.String
getConnectionProperties()
The connection properties that will be sent to the JDBC driver when establishing new connections.long
getCreatedCount()
The total number of connections created by this pool.java.lang.Object
getDataSource()
Returns a datasource, if one exists that is being used to create connections.java.lang.String
getDataSourceJNDI()
Returns the JNDI string configured for data source usage.java.util.Properties
getDbProperties()
Returns the database properties that are passed into theDriver.connect(String, Properties)
method.java.lang.Boolean
getDefaultAutoCommit()
The default auto-commit state of connections created by this pool.java.lang.String
getDefaultCatalog()
If non null, during connection creation the methodConnection.setCatalog(String)
will be called with the set value.java.lang.Boolean
getDefaultReadOnly()
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.int
getDefaultTransactionIsolation()
Returns the default transaction isolation level.java.lang.String
getDriverClassName()
The fully qualified Java class name of the JDBC driver to be used.int
getIdle()
If the pool has not been created, it will be created during this call.int
getInitialSize()
Returns the number of connections that will be established when the connection pool is started.java.lang.String
getInitSQL()
A custom query to be run when a connection is first created.java.lang.String
getJdbcInterceptors()
A semicolon separated list of classnames extendingJdbcInterceptor
class.PoolProperties.InterceptorDefinition[]
getJdbcInterceptorsAsArray()
Returns thePoolConfiguration.getJdbcInterceptors()
as an array of objects with properties and the classes.int
getLoginTimeout()
no-opDataSource.getLoginTimeout()
boolean
getLogValidationErrors()
Returns true if errors that happen during validation will be loggedjava.io.PrintWriter
getLogWriter()
no-opDataSource.getLogWriter()
int
getMaxActive()
The maximum number of active connections that can be allocated from this pool at the same time.long
getMaxAge()
Time in milliseconds to keep this connection before reconnecting.int
getMaxIdle()
The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()
returns false.int
getMaxWait()
The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()
has been reached) for a connection to be returned before throwing an exception.int
getMinEvictableIdleTimeMillis()
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.int
getMinIdle()
The minimum number of established connections that should be kept in the pool at all times.java.lang.String
getName()
Returns the name of the connection pool.int
getNumActive()
int
getNumIdle()
int
getNumTestsPerEvictionRun()
Property not usedjava.util.logging.Logger
getParentLogger()
no-opCommonDataSource.getParentLogger()
java.lang.String
getPassword()
Returns the password used when establishing connections to the database.ConnectionPool
getPool()
javax.sql.PooledConnection
getPooledConnection()
Get a database connection.javax.sql.PooledConnection
getPooledConnection(java.lang.String username, java.lang.String password)
Get a database connection.java.lang.String
getPoolName()
PoolConfiguration
getPoolProperties()
int
getPoolSize()
boolean
getPropagateInterruptState()
Returns true if the pool is configured to propagate interrupt state of a thread.long
getReconnectedCount()
The total number of connections reconnected by this pool.long
getReleasedCount()
The total number of connections released from this pool.long
getReleasedIdleCount()
The total number of connections released by eviction.long
getRemoveAbandonedCount()
The total number of connections released by remove abandoned.int
getRemoveAbandonedTimeout()
The time in seconds before a connection can be considered abandoned.long
getReturnedCount()
The total number of connections returned to this pool.boolean
getRollbackOnReturn()
int
getSize()
int
getSuspectTimeout()
Returns the time in seconds to pass before a connection is marked an abandoned suspect.int
getTimeBetweenEvictionRunsMillis()
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.java.lang.String
getUrl()
The URL used to connect to the databaseboolean
getUseDisposableConnectionFacade()
Returnstrue
if this connection pool is configured to use a connection facade to prevent re-use of connection afterConnection.close()
has been invokedboolean
getUseLock()
Return true if a lock should be used when operations are performed on the connection object.java.lang.String
getUsername()
Returns the username used to establish the connection withboolean
getUseStatementFacade()
Returnstrue
if this connection pool is configured to wrap statements in order to enable equals() and hashCode() methods to be called on the closed statements if any statement proxy is set.long
getValidationInterval()
avoid excess validation, only run validation at most at this frequency - time in milliseconds.java.lang.String
getValidationQuery()
The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.int
getValidationQueryTimeout()
The timeout in seconds before a connection validation queries fail.Validator
getValidator()
java.lang.String
getValidatorClassName()
Return the name of the optional validator class - may be null.int
getWaitCount()
javax.sql.XAConnection
getXAConnection()
Get a database connection.javax.sql.XAConnection
getXAConnection(java.lang.String username, java.lang.String password)
Get a database connection.boolean
isAccessToUnderlyingConnectionAllowed()
Property not used.boolean
isAlternateUsernameAllowed()
Returns true if the callgetConnection(username,password)
is allowed.java.lang.Boolean
isDefaultAutoCommit()
The default auto-commit state of connections created by this pool.java.lang.Boolean
isDefaultReadOnly()
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.boolean
isFairQueue()
Returnstrue
if a fair queue is being used by the connection poolboolean
isIgnoreExceptionOnPreLoad()
boolean
isJmxEnabled()
If set to true, the connection pool creates aConnectionPoolMBean
object that can be registered with JMX to receive notifications and state about the pool.boolean
isLogAbandoned()
boolean flag to set if stack traces should be logged for application code which abandoned a Connection.boolean
isPoolSweeperEnabled()
Returns true if the pool sweeper is enabled for the connection pool.boolean
isRemoveAbandoned()
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.boolean
isTestOnBorrow()
The indication of whether objects will be validated before being borrowed from the pool.boolean
isTestOnConnect()
Returns true if we should run the validation query when connecting to the database for the first time on a connection.boolean
isTestOnReturn()
The indication of whether objects will be validated after being returned to the pool.boolean
isTestWhileIdle()
Set to true if query validation should take place while the connection is idle.boolean
isUseEquals()
Set to true if you wish theProxyConnection
class to useString.equals
instead of==
when comparing method names.boolean
isWrapperFor(java.lang.Class<?> iface)
void
purge()
void
purgeOnReturn()
void
resetStats()
reset the statistics of this pool.void
setAbandonWhenPercentageFull(int percentage)
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull.void
setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed)
No-opvoid
setAlternateUsernameAllowed(boolean alternateUsernameAllowed)
Set to true if the callgetConnection(username,password)
is allowed and honored..void
setCommitOnReturn(boolean commitOnReturn)
Set to true if you want the connection pool to commit any pending transaction when a connection is returned.void
setConnectionProperties(java.lang.String properties)
The properties that will be passed intoDriver.connect(String, Properties)
method.void
setDataSource(java.lang.Object ds)
Injects a datasource that will be used to retrieve/create connections.void
setDataSourceJNDI(java.lang.String jndiDS)
Configure the connection pool to use a DataSource according toPoolConfiguration.setDataSource(Object)
But instead of injecting the object, specify the JNDI location.void
setDbProperties(java.util.Properties dbProperties)
Overrides the database properties passed into theDriver.connect(String, Properties)
method.void
setDefaultAutoCommit(java.lang.Boolean autocommit)
The default auto-commit state of connections created by this pool.void
setDefaultCatalog(java.lang.String catalog)
If non null, during connection creation the methodConnection.setCatalog(String)
will be called with the set value.void
setDefaultReadOnly(java.lang.Boolean defaultReadOnly)
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.void
setDefaultTransactionIsolation(int defaultTransactionIsolation)
If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATION
the methodConnection.setTransactionIsolation(int)
will not be called during connection creation.void
setDriverClassName(java.lang.String driverClassName)
The fully qualified Java class name of the JDBC driver to be used.void
setFairQueue(boolean fairQueue)
Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion.void
setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad)
Set to true if you want to ignore error of connection creation while initializing the pool.void
setInitialSize(int initialSize)
Set the number of connections that will be established when the connection pool is started.void
setInitSQL(java.lang.String initSQL)
A custom query to be run when a connection is first created.void
setJdbcInterceptors(java.lang.String interceptors)
A semicolon separated list of classnames extendingJdbcInterceptor
class.void
setJmxEnabled(boolean enabled)
If set to true, the connection pool creates aConnectionPoolMBean
object that can be registered with JMX to receive notifications and state about the pool.void
setLogAbandoned(boolean logAbandoned)
boolean flag to set if stack traces should be logged for application code which abandoned a Connection.void
setLoginTimeout(int i)
DataSource.setLoginTimeout(int)
void
setLogValidationErrors(boolean logValidationErrors)
Set to true if you wish that errors from validation should be logged as error messages.void
setLogWriter(java.io.PrintWriter out)
no-opDataSource.setLogWriter(PrintWriter)
void
setMaxActive(int maxActive)
The maximum number of active connections that can be allocated from this pool at the same time.void
setMaxAge(long maxAge)
Time in milliseconds to keep this connection before reconnecting.void
setMaxIdle(int maxIdle)
The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()
returns false.void
setMaxWait(int maxWait)
The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()
has been reached) for a connection to be returned before throwing an exception.void
setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction.void
setMinIdle(int minIdle)
The minimum number of established connections that should be kept in the pool at all times.void
setName(java.lang.String name)
Sets the name of the connection poolvoid
setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Property not usedvoid
setPassword(java.lang.String password)
Sets the password to establish the connection with.void
setPoolProperties(PoolConfiguration poolProperties)
void
setPropagateInterruptState(boolean propagateInterruptState)
Configure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aPoolExhaustedException
If set to true, this behavior will change, while thePoolExhaustedException
is still thrown, the threads interrupted state is still set.void
setRemoveAbandoned(boolean removeAbandoned)
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout.void
setRemoveAbandonedTimeout(int removeAbandonedTimeout)
The time in seconds before a connection can be considered abandoned.void
setRollbackOnReturn(boolean rollbackOnReturn)
Set to true if you want the connection pool to rollback any pending transaction when a connection is returned.void
setSuspectTimeout(int seconds)
Similar toPoolConfiguration.setRemoveAbandonedTimeout(int)
but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning ifPoolConfiguration.isLogAbandoned()
returns true.void
setTestOnBorrow(boolean testOnBorrow)
The indication of whether objects will be validated before being borrowed from the pool.void
setTestOnConnect(boolean testOnConnect)
Set to true if we should run the validation query when connecting to the database for the first time on a connection.void
setTestOnReturn(boolean testOnReturn)
The indication of whether objects will be validated after being returned to the pool.void
setTestWhileIdle(boolean testWhileIdle)
Set to true if query validation should take place while the connection is idle.void
setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing.void
setUrl(java.lang.String url)
Sets the URL used to connect to the databasevoid
setUseDisposableConnectionFacade(boolean useDisposableConnectionFacade)
If set totrue
, the connection will be wrapped with facade that will disallow the connection to be used afterConnection.close()
is called.void
setUseEquals(boolean useEquals)
Set to true if you wish theProxyConnection
class to useString.equals
instead of==
when comparing method names.void
setUseLock(boolean useLock)
Set to true if a lock should be used when operations are performed on the connection object.void
setUsername(java.lang.String username)
Sets the username used to establish the connection with It will also be a property called 'user' in the database properties.void
setUseStatementFacade(boolean useStatementFacade)
Set this to true if you wish to wrap statements in order to enable equals() and hashCode() methods to be called on the closed statements if any statement proxy is set.void
setValidationInterval(long validationInterval)
avoid excess validation, only run validation at most at this frequency - time in milliseconds.void
setValidationQuery(java.lang.String validationQuery)
The SQL query that will be used to validate connections from this pool before returning them to the caller or pool.void
setValidationQueryTimeout(int validationQueryTimeout)
The timeout in seconds before a connection validation queries fail.void
setValidator(Validator validator)
Sets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.void
setValidatorClassName(java.lang.String className)
Set the name for an optional validator class which will be used in place of test queries.void
testIdle()
Performs a validation on idle connectionsjava.lang.String
toString()
<T> T
unwrap(java.lang.Class<T> iface)
-
-
-
Field Detail
-
pool
protected volatile ConnectionPool pool
-
poolProperties
protected volatile PoolConfiguration poolProperties
-
-
Constructor Detail
-
DataSourceProxy
public DataSourceProxy()
-
DataSourceProxy
public DataSourceProxy(PoolConfiguration poolProperties)
-
-
Method Detail
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
getConnection
public java.sql.Connection getConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
Get a database connection.DataSource.getConnection()
- Parameters:
username
- The user namepassword
- The password- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getPoolProperties
public PoolConfiguration getPoolProperties()
-
createPool
public ConnectionPool createPool() throws java.sql.SQLException
Sets up the connection pool, by creating a pooling driver.- Returns:
- the connection pool
- Throws:
java.sql.SQLException
- Error creating pool
-
getConnection
public java.sql.Connection getConnection() throws java.sql.SQLException
Get a database connection.DataSource.getConnection()
- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getConnectionAsync
public java.util.concurrent.Future<java.sql.Connection> getConnectionAsync() throws java.sql.SQLException
Invokes an sync operation to retrieve the connection.- Returns:
- a Future containing a reference to the connection when it becomes available
- Throws:
java.sql.SQLException
- Connection error
-
getXAConnection
public javax.sql.XAConnection getXAConnection() throws java.sql.SQLException
Get a database connection.XADataSource.getXAConnection()
- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getXAConnection
public javax.sql.XAConnection getXAConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
Get a database connection.XADataSource.getXAConnection(String, String)
- Parameters:
username
- The user namepassword
- The password- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getPooledConnection
public javax.sql.PooledConnection getPooledConnection() throws java.sql.SQLException
Get a database connection.DataSource.getConnection()
- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getPooledConnection
public javax.sql.PooledConnection getPooledConnection(java.lang.String username, java.lang.String password) throws java.sql.SQLException
Get a database connection.DataSource.getConnection()
- Parameters:
username
- unusedpassword
- unused- Returns:
- the connection
- Throws:
java.sql.SQLException
- Connection error
-
getPool
public ConnectionPool getPool()
-
close
public void close()
-
close
public void close(boolean all)
-
getPoolSize
public int getPoolSize()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getPoolName
public java.lang.String getPoolName()
- Specified by:
getPoolName
in interfacePoolConfiguration
- Returns:
- the pool name
- See Also:
PoolConfiguration.getName()
-
setPoolProperties
public void setPoolProperties(PoolConfiguration poolProperties)
-
setDriverClassName
public void setDriverClassName(java.lang.String driverClassName)
The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar- Specified by:
setDriverClassName
in interfacePoolConfiguration
- Parameters:
driverClassName
- a fully qualified Java class name of aDriver
implementation.
-
setInitialSize
public void setInitialSize(int initialSize)
Set the number of connections that will be established when the connection pool is started. Default value is 10. If this value exceedsPoolConfiguration.setMaxActive(int)
it will automatically be lowered.- Specified by:
setInitialSize
in interfacePoolConfiguration
- Parameters:
initialSize
- the number of connections to be established.
-
setInitSQL
public void setInitSQL(java.lang.String initSQL)
A custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.- Specified by:
setInitSQL
in interfacePoolConfiguration
- Parameters:
initSQL
- the init SQL used to run against the DB or null if no query should be executed
-
setLogAbandoned
public void setLogAbandoned(boolean logAbandoned)
boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.- Specified by:
setLogAbandoned
in interfacePoolConfiguration
- Parameters:
logAbandoned
- set to true if stack traces should be recorded whengetConnection()
is called.
-
setMaxActive
public void setMaxActive(int maxActive)
The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100- Specified by:
setMaxActive
in interfacePoolConfiguration
- Parameters:
maxActive
- hard limit for number of managed connections by this pool
-
setMaxIdle
public void setMaxIdle(int maxIdle)
The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()
returns false. If the IfPoolConfiguration.isPoolSweeperEnabled()
returns true, then the idle pool can grow up toPoolConfiguration.getMaxActive()
and will be shrunk according toPoolConfiguration.getMinEvictableIdleTimeMillis()
setting. Default value is maxActive:100- Specified by:
setMaxIdle
in interfacePoolConfiguration
- Parameters:
maxIdle
- the maximum size of the idle pool
-
setMaxWait
public void setMaxWait(int maxWait)
The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()
has been reached) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)- Specified by:
setMaxWait
in interfacePoolConfiguration
- Parameters:
maxWait
- the maximum number of milliseconds to wait.
-
setMinEvictableIdleTimeMillis
public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis)
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).- Specified by:
setMinEvictableIdleTimeMillis
in interfacePoolConfiguration
- Parameters:
minEvictableIdleTimeMillis
- the number of milliseconds a connection must be idle to be eligible for eviction.
-
setMinIdle
public void setMinIdle(int minIdle)
The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. Default value is derived fromPoolConfiguration.getInitialSize()
(also seePoolConfiguration.setTestWhileIdle(boolean)
The idle pool will not shrink below this value during an eviction run, hence the number of actual connections can be betweenPoolConfiguration.getMinIdle()
and somewhere betweenPoolConfiguration.getMaxIdle()
andPoolConfiguration.getMaxActive()
- Specified by:
setMinIdle
in interfacePoolConfiguration
- Parameters:
minIdle
- the minimum number of idle or established connections
-
setNumTestsPerEvictionRun
public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun)
Property not used- Specified by:
setNumTestsPerEvictionRun
in interfacePoolConfiguration
- Parameters:
numTestsPerEvictionRun
- parameter ignored.
-
setPassword
public void setPassword(java.lang.String password)
Sets the password to establish the connection with. The password will be included as a database property with the name 'password'.- Specified by:
setPassword
in interfacePoolConfiguration
- Parameters:
password
- The password- See Also:
PoolConfiguration.getDbProperties()
-
setRemoveAbandoned
public void setRemoveAbandoned(boolean removeAbandoned)
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than thePoolConfiguration.getRemoveAbandonedTimeout()
and the condition forPoolConfiguration.getAbandonWhenPercentageFull()
is met. Setting this to true can recover db connections from applications that fail to close a connection. See alsoPoolConfiguration.isLogAbandoned()
The default value is false.- Specified by:
setRemoveAbandoned
in interfacePoolConfiguration
- Parameters:
removeAbandoned
- set to true if abandoned connections can be closed and expelled out of the pool
-
setRemoveAbandonedTimeout
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout)
The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.- Specified by:
setRemoveAbandonedTimeout
in interfacePoolConfiguration
- Parameters:
removeAbandonedTimeout
- the time in seconds before a used connection can be considered abandoned- See Also:
ResetAbandonedTimer
-
setTestOnBorrow
public void setTestOnBorrow(boolean testOnBorrow)
The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)
- Specified by:
setTestOnBorrow
in interfacePoolConfiguration
- Parameters:
testOnBorrow
- set to true if validation should take place before a connection is handed out to the application- See Also:
PoolConfiguration.getValidationInterval()
-
setTestOnConnect
public void setTestOnConnect(boolean testOnConnect)
Set to true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query. Setting anPoolConfiguration.setInitSQL(String)
will override this setting, as the init SQL will be used instead of the validation query- Specified by:
setTestOnConnect
in interfacePoolConfiguration
- Parameters:
testOnConnect
- set to true if we should run the validation query upon connect
-
setTestOnReturn
public void setTestOnReturn(boolean testOnReturn)
The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)
- Specified by:
setTestOnReturn
in interfacePoolConfiguration
- Parameters:
testOnReturn
- true if validation should take place after a connection is returned to the pool- See Also:
PoolConfiguration.getValidationInterval()
-
setTestWhileIdle
public void setTestWhileIdle(boolean testWhileIdle)
Set to true if query validation should take place while the connection is idle.- Specified by:
setTestWhileIdle
in interfacePoolConfiguration
- Parameters:
testWhileIdle
- true if validation should take place during idle checks- See Also:
PoolConfiguration.setTimeBetweenEvictionRunsMillis(int)
-
setTimeBetweenEvictionRunsMillis
public void setTimeBetweenEvictionRunsMillis(int timeBetweenEvictionRunsMillis)
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)- Specified by:
setTimeBetweenEvictionRunsMillis
in interfacePoolConfiguration
- Parameters:
timeBetweenEvictionRunsMillis
- the sleep time in between validations in milliseconds
-
setUrl
public void setUrl(java.lang.String url)
Sets the URL used to connect to the database- Specified by:
setUrl
in interfacePoolConfiguration
- Parameters:
url
- the configured URL for this connection pool- See Also:
Driver.connect(String, Properties)
-
setUsername
public void setUsername(java.lang.String username)
Sets the username used to establish the connection with It will also be a property called 'user' in the database properties.- Specified by:
setUsername
in interfacePoolConfiguration
- Parameters:
username
- The user name- See Also:
PoolConfiguration.getDbProperties()
-
setValidationInterval
public void setValidationInterval(long validationInterval)
avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).- Specified by:
setValidationInterval
in interfacePoolConfiguration
- Parameters:
validationInterval
- the validation interval in milliseconds
-
setValidationQuery
public void setValidationQuery(java.lang.String validationQuery)
The SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)- Specified by:
setValidationQuery
in interfacePoolConfiguration
- Parameters:
validationQuery
- the query used for validation or null if no validation is performed
-
setValidatorClassName
public void setValidatorClassName(java.lang.String className)
Set the name for an optional validator class which will be used in place of test queries. If set to null, standard validation will be used.- Specified by:
setValidatorClassName
in interfacePoolConfiguration
- Parameters:
className
- the name of the optional validator class
-
setValidationQueryTimeout
public void setValidationQueryTimeout(int validationQueryTimeout)
The timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.- Specified by:
setValidationQueryTimeout
in interfacePoolConfiguration
- Parameters:
validationQueryTimeout
- The timeout value
-
setJdbcInterceptors
public void setJdbcInterceptors(java.lang.String interceptors)
A semicolon separated list of classnames extendingJdbcInterceptor
class. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors areStatementFinalizer
to close all used statements during the session.ResetAbandonedTimer
resets the timer upon every operation on the connection or a statement.ConnectionState
caches the auto commit, read only and catalog settings to avoid round trips to the DB. The default value is null.- Specified by:
setJdbcInterceptors
in interfacePoolConfiguration
- Parameters:
interceptors
- the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'
-
setJmxEnabled
public void setJmxEnabled(boolean enabled)
If set to true, the connection pool creates aConnectionPoolMBean
object that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.- Specified by:
setJmxEnabled
in interfacePoolConfiguration
- Parameters:
enabled
- set to to if the mbean object should be created upon startup.
-
setFairQueue
public void setFairQueue(boolean fairQueue)
Set to true if you wish that calls to getConnection should be treated fairly in a true FIFO fashion. This uses theFairBlockingQueue
implementation for the list of the idle connections. The default value is true. This flag is required when you want to use asynchronous connection retrieval.- Specified by:
setFairQueue
in interfacePoolConfiguration
- Parameters:
fairQueue
-true
to use a fair queue
-
setUseLock
public void setUseLock(boolean useLock)
Set to true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.- Specified by:
setUseLock
in interfacePoolConfiguration
- Parameters:
useLock
- set to true if a lock should be used on connection operations
-
setDefaultCatalog
public void setDefaultCatalog(java.lang.String catalog)
If non null, during connection creation the methodConnection.setCatalog(String)
will be called with the set value.- Specified by:
setDefaultCatalog
in interfacePoolConfiguration
- Parameters:
catalog
- null if not set and accepting the driver default.
-
setDefaultAutoCommit
public void setDefaultAutoCommit(java.lang.Boolean autocommit)
The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)
method will not be called.)- Specified by:
setDefaultAutoCommit
in interfacePoolConfiguration
- Parameters:
autocommit
- default auto commit setting, null is Driver default.
-
setDefaultTransactionIsolation
public void setDefaultTransactionIsolation(int defaultTransactionIsolation)
If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATION
the methodConnection.setTransactionIsolation(int)
will not be called during connection creation. Otherwise the method will be called with the isolation level set by this property.- Specified by:
setDefaultTransactionIsolation
in interfacePoolConfiguration
- Parameters:
defaultTransactionIsolation
- a value ofConnection.TRANSACTION_NONE
,Connection.TRANSACTION_READ_COMMITTED
,Connection.TRANSACTION_READ_UNCOMMITTED
,Connection.TRANSACTION_REPEATABLE_READ
,Connection.TRANSACTION_SERIALIZABLE
orDataSourceFactory.UNKNOWN_TRANSACTIONISOLATION
The last value will not be set on the connection.
-
setConnectionProperties
public void setConnectionProperties(java.lang.String properties)
The properties that will be passed intoDriver.connect(String, Properties)
method. Username and password do not need to be stored here, they will be passed into the properties right before the connection is established.- Specified by:
setConnectionProperties
in interfacePoolConfiguration
- Parameters:
properties
- properties - Format of the string is [propertyName=property;]* Example: prop1=value1;prop2=value2
-
setUseEquals
public void setUseEquals(boolean useEquals)
Set to true if you wish theProxyConnection
class to useString.equals
instead of==
when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value isfalse
.- Specified by:
setUseEquals
in interfacePoolConfiguration
- Parameters:
useEquals
- set to true if the pool should useString.equals(Object)
instead of == when comparing method names onConnection
methods
-
getParentLogger
public java.util.logging.Logger getParentLogger() throws java.sql.SQLFeatureNotSupportedException
no-opCommonDataSource.getParentLogger()
- Returns:
- no return value
- Throws:
java.sql.SQLFeatureNotSupportedException
- Unsupported
-
getLogWriter
public java.io.PrintWriter getLogWriter() throws java.sql.SQLException
no-opDataSource.getLogWriter()
- Returns:
- null
- Throws:
java.sql.SQLException
- No exception
-
setLogWriter
public void setLogWriter(java.io.PrintWriter out) throws java.sql.SQLException
no-opDataSource.setLogWriter(PrintWriter)
- Parameters:
out
- Ignored- Throws:
java.sql.SQLException
- No exception
-
getLoginTimeout
public int getLoginTimeout()
no-opDataSource.getLoginTimeout()
- Returns:
- the timeout
-
setLoginTimeout
public void setLoginTimeout(int i)
DataSource.setLoginTimeout(int)
- Parameters:
i
- The timeout value
-
getSuspectTimeout
public int getSuspectTimeout()
Returns the time in seconds to pass before a connection is marked an abandoned suspect. Any value lesser than or equal to 0 means the check is disabled.- Specified by:
getSuspectTimeout
in interfacePoolConfiguration
- Returns:
- Returns the time in seconds to pass before a connection is marked an abandoned suspect.
-
setSuspectTimeout
public void setSuspectTimeout(int seconds)
Similar toPoolConfiguration.setRemoveAbandonedTimeout(int)
but instead of treating the connection as abandoned, and potentially closing the connection, this simply logs the warning ifPoolConfiguration.isLogAbandoned()
returns true. If this value is equal or less than 0, no suspect checking will be performed. Suspect checking only takes place if the timeout value is larger than 0 and the connection was not abandoned or if abandon check is disabled. If a connection is suspect a WARN message gets logged and a JMX notification gets sent once.- Specified by:
setSuspectTimeout
in interfacePoolConfiguration
- Parameters:
seconds
- - the amount of time in seconds that has to pass before a connection is marked suspect.
-
getIdle
public int getIdle()
If the pool has not been created, it will be created during this call.- Returns:
- the number of established but idle connections
-
getNumIdle
public int getNumIdle()
- Returns:
- the number of established but idle connections
-
checkAbandoned
public void checkAbandoned()
Forces an abandon check on the connection pool. If connections that have been abandoned exists, they will be closed during this run
-
checkIdle
public void checkIdle()
Forces a check for resizing of the idle connections
-
getActive
public int getActive()
- Returns:
- number of connections in use by the application
-
getNumActive
public int getNumActive()
- Returns:
- number of connections in use by the application
getActive()
-
getWaitCount
public int getWaitCount()
- Returns:
- number of threads waiting for a connection
-
getSize
public int getSize()
- Returns:
- the current size of the pool
-
testIdle
public void testIdle()
Performs a validation on idle connections
-
getBorrowedCount
public long getBorrowedCount()
The total number of connections borrowed from this pool.- Returns:
- the borrowed connection count
-
getReturnedCount
public long getReturnedCount()
The total number of connections returned to this pool.- Returns:
- the returned connection count
-
getCreatedCount
public long getCreatedCount()
The total number of connections created by this pool.- Returns:
- the created connection count
-
getReleasedCount
public long getReleasedCount()
The total number of connections released from this pool.- Returns:
- the released connection count
-
getReconnectedCount
public long getReconnectedCount()
The total number of connections reconnected by this pool.- Returns:
- the reconnected connection count
-
getRemoveAbandonedCount
public long getRemoveAbandonedCount()
The total number of connections released by remove abandoned.- Returns:
- the PoolCleaner removed abandoned connection count
-
getReleasedIdleCount
public long getReleasedIdleCount()
The total number of connections released by eviction.- Returns:
- the PoolCleaner evicted idle connection count
-
resetStats
public void resetStats()
reset the statistics of this pool.
-
getConnectionProperties
public java.lang.String getConnectionProperties()
The connection properties that will be sent to the JDBC driver when establishing new connections. Format of the string is [propertyName=property;]
NOTE - The "user" and "password" properties will be passed explicitly, so they do not need to be included here. The default value is null.- Specified by:
getConnectionProperties
in interfacePoolConfiguration
- Returns:
- the connection properties
-
getDbProperties
public java.util.Properties getDbProperties()
Returns the database properties that are passed into theDriver.connect(String, Properties)
method.- Specified by:
getDbProperties
in interfacePoolConfiguration
- Returns:
- database properties that are passed into the
Driver.connect(String, Properties)
method.
-
getDefaultCatalog
public java.lang.String getDefaultCatalog()
If non null, during connection creation the methodConnection.setCatalog(String)
will be called with the set value.- Specified by:
getDefaultCatalog
in interfacePoolConfiguration
- Returns:
- the default catalog, null if not set and accepting the driver default.
-
getDefaultTransactionIsolation
public int getDefaultTransactionIsolation()
Returns the default transaction isolation level. If set toDataSourceFactory.UNKNOWN_TRANSACTIONISOLATION
the methodConnection.setTransactionIsolation(int)
will not be called during connection creation.- Specified by:
getDefaultTransactionIsolation
in interfacePoolConfiguration
- Returns:
- driver transaction isolation level, or -1
DataSourceFactory.UNKNOWN_TRANSACTIONISOLATION
if not set.
-
getDriverClassName
public java.lang.String getDriverClassName()
The fully qualified Java class name of the JDBC driver to be used. The driver has to be accessible from the same classloader as tomcat-jdbc.jar- Specified by:
getDriverClassName
in interfacePoolConfiguration
- Returns:
- fully qualified JDBC driver name.
-
getInitialSize
public int getInitialSize()
Returns the number of connections that will be established when the connection pool is started. Default value is 10- Specified by:
getInitialSize
in interfacePoolConfiguration
- Returns:
- number of connections to be started when pool is started
-
getInitSQL
public java.lang.String getInitSQL()
A custom query to be run when a connection is first created. The default value is null. This query only runs once per connection, and that is when a new connection is established to the database. If this value is non null, it will replace the validation query during connection creation.- Specified by:
getInitSQL
in interfacePoolConfiguration
- Returns:
- the init SQL used to run against the DB or null if not set
-
getJdbcInterceptors
public java.lang.String getJdbcInterceptors()
A semicolon separated list of classnames extendingJdbcInterceptor
class. These interceptors will be inserted as an interceptor into the chain of operations on a java.sql.Connection object. Example interceptors areStatementFinalizer
to close all used statements during the session.ResetAbandonedTimer
resets the timer upon every operation on the connection or a statement.ConnectionState
caches the auto commit, read only and catalog settings to avoid round trips to the DB. The default value is null.- Specified by:
getJdbcInterceptors
in interfacePoolConfiguration
- Returns:
- the interceptors that are used for connections. Example format: 'ConnectionState(useEquals=true,fast=yes);ResetAbandonedTimer'
-
getMaxActive
public int getMaxActive()
The maximum number of active connections that can be allocated from this pool at the same time. The default value is 100- Specified by:
getMaxActive
in interfacePoolConfiguration
- Returns:
- the maximum number of connections used by this pool
-
getMaxIdle
public int getMaxIdle()
The maximum number of connections that should be kept in the idle pool ifPoolConfiguration.isPoolSweeperEnabled()
returns false. If the IfPoolConfiguration.isPoolSweeperEnabled()
returns true, then the idle pool can grow up toPoolConfiguration.getMaxActive()
and will be shrunk according toPoolConfiguration.getMinEvictableIdleTimeMillis()
setting. Default value is maxActive:100- Specified by:
getMaxIdle
in interfacePoolConfiguration
- Returns:
- the maximum number of idle connections.
-
getMaxWait
public int getMaxWait()
The maximum number of milliseconds that the pool will wait (when there are no available connections and thePoolConfiguration.getMaxActive()
has been reached) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)- Specified by:
getMaxWait
in interfacePoolConfiguration
- Returns:
- the number of milliseconds to wait for a connection to become available if the pool is maxed out.
-
getMinEvictableIdleTimeMillis
public int getMinEvictableIdleTimeMillis()
The minimum amount of time an object must sit idle in the pool before it is eligible for eviction. The default value is 60000 (60 seconds).- Specified by:
getMinEvictableIdleTimeMillis
in interfacePoolConfiguration
- Returns:
- the minimum amount of idle time in milliseconds before a connection is considered idle and eligible for eviction.
-
getMinIdle
public int getMinIdle()
The minimum number of established connections that should be kept in the pool at all times. The connection pool can shrink below this number if validation queries fail and connections get closed. Default value is derived fromPoolConfiguration.getInitialSize()
(also seePoolConfiguration.setTestWhileIdle(boolean)
The idle pool will not shrink below this value during an eviction run, hence the number of actual connections can be betweenPoolConfiguration.getMinIdle()
and somewhere betweenPoolConfiguration.getMaxIdle()
andPoolConfiguration.getMaxActive()
- Specified by:
getMinIdle
in interfacePoolConfiguration
- Returns:
- the minimum number of idle or established connections
-
getMaxAge
public long getMaxAge()
Time in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked ifPoolConfiguration.getTimeBetweenEvictionRunsMillis()
returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.- Specified by:
getMaxAge
in interfacePoolConfiguration
- Returns:
- the time in milliseconds a connection will be open for when used
-
getName
public java.lang.String getName()
Returns the name of the connection pool. By default a JVM unique random name is assigned.- Specified by:
getName
in interfacePoolConfiguration
- Returns:
- the name of the pool, should be unique in a JVM
-
getNumTestsPerEvictionRun
public int getNumTestsPerEvictionRun()
Property not used- Specified by:
getNumTestsPerEvictionRun
in interfacePoolConfiguration
- Returns:
- unknown value
-
getPassword
public java.lang.String getPassword()
Description copied from interface:PoolConfiguration
Returns the password used when establishing connections to the database.- Specified by:
getPassword
in interfacePoolConfiguration
- Returns:
- DOES NOT RETURN THE PASSWORD, IT WOULD SHOW UP IN JMX
-
getRemoveAbandonedTimeout
public int getRemoveAbandonedTimeout()
The time in seconds before a connection can be considered abandoned. The timer can be reset upon queries using an interceptor.- Specified by:
getRemoveAbandonedTimeout
in interfacePoolConfiguration
- Returns:
- the time in seconds before a used connection can be considered abandoned
- See Also:
ResetAbandonedTimer
-
getTimeBetweenEvictionRunsMillis
public int getTimeBetweenEvictionRunsMillis()
The number of milliseconds to sleep between runs of the idle connection validation, abandoned cleaner and idle pool resizing. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connection and resize the idle pool. The default value is 5000 (5 seconds)- Specified by:
getTimeBetweenEvictionRunsMillis
in interfacePoolConfiguration
- Returns:
- the sleep time in between validations in milliseconds
-
getUrl
public java.lang.String getUrl()
The URL used to connect to the database- Specified by:
getUrl
in interfacePoolConfiguration
- Returns:
- the configured URL for this connection pool
- See Also:
Driver.connect(String, Properties)
-
getUsername
public java.lang.String getUsername()
Returns the username used to establish the connection with- Specified by:
getUsername
in interfacePoolConfiguration
- Returns:
- the username used to establish the connection with
-
getValidationInterval
public long getValidationInterval()
avoid excess validation, only run validation at most at this frequency - time in milliseconds. If a connection is due for validation, but has been validated previously within this interval, it will not be validated again. The default value is 3000 (3 seconds).- Specified by:
getValidationInterval
in interfacePoolConfiguration
- Returns:
- the validation interval in milliseconds
-
getValidationQuery
public java.lang.String getValidationQuery()
The SQL query that will be used to validate connections from this pool before returning them to the caller or pool. If specified, this query does not have to return any data, it just can't throw an SQLException. The default value is null. Example values are SELECT 1(mysql), select 1 from dual(oracle), SELECT 1(MS Sql Server)- Specified by:
getValidationQuery
in interfacePoolConfiguration
- Returns:
- the query used for validation or null if no validation is performed
-
getValidationQueryTimeout
public int getValidationQueryTimeout()
The timeout in seconds before a connection validation queries fail. A value less than or equal to zero will disable this feature. Defaults to -1.- Specified by:
getValidationQueryTimeout
in interfacePoolConfiguration
- Returns:
- the timeout value in seconds
-
getValidatorClassName
public java.lang.String getValidatorClassName()
Return the name of the optional validator class - may be null.- Specified by:
getValidatorClassName
in interfacePoolConfiguration
- Returns:
- the name of the optional validator class - may be null
-
getValidator
public Validator getValidator()
- Specified by:
getValidator
in interfacePoolConfiguration
- Returns:
- the optional validator object - may be null
-
setValidator
public void setValidator(Validator validator)
Sets the validator object If this is a non null object, it will be used as a validator instead of the validationQuery If this is null, remove the usage of the validator.- Specified by:
setValidator
in interfacePoolConfiguration
- Parameters:
validator
- The validator object
-
isAccessToUnderlyingConnectionAllowed
public boolean isAccessToUnderlyingConnectionAllowed()
Property not used. Access is always allowed. Access can be achieved by calling unwrap on the pooled connection. seeDataSource
interface or call getConnection through reflection or cast the object asPooledConnection
- Specified by:
isAccessToUnderlyingConnectionAllowed
in interfacePoolConfiguration
- Returns:
true
-
isDefaultAutoCommit
public java.lang.Boolean isDefaultAutoCommit()
The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)
method will not be called.)- Specified by:
isDefaultAutoCommit
in interfacePoolConfiguration
- Returns:
- the default auto commit setting, null is Driver default.
-
isDefaultReadOnly
public java.lang.Boolean isDefaultReadOnly()
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.- Specified by:
isDefaultReadOnly
in interfacePoolConfiguration
- Returns:
- null if not set and accepting the driver default otherwise the read only value
-
isLogAbandoned
public boolean isLogAbandoned()
boolean flag to set if stack traces should be logged for application code which abandoned a Connection. Logging of abandoned Connections adds overhead for every Connection borrow because a stack trace has to be generated. The default value is false.- Specified by:
isLogAbandoned
in interfacePoolConfiguration
- Returns:
- true if the connection pool logs stack traces when connections are borrowed from the pool.
-
isPoolSweeperEnabled
public boolean isPoolSweeperEnabled()
Returns true if the pool sweeper is enabled for the connection pool. The pool sweeper is enabled if any settings that require async intervention in the pool are turned onboolean result = getTimeBetweenEvictionRunsMillis()>0; result = result && (isRemoveAbandoned() && getRemoveAbandonedTimeout()>0); result = result || (isTestWhileIdle() && getValidationQuery()!=null); return result;
- Specified by:
isPoolSweeperEnabled
in interfacePoolConfiguration
- Returns:
- true if a background thread is or will be enabled for this pool
-
isRemoveAbandoned
public boolean isRemoveAbandoned()
boolean flag to remove abandoned connections if they exceed the removeAbandonedTimeout. If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than thePoolConfiguration.getRemoveAbandonedTimeout()
and the condition forPoolConfiguration.getAbandonWhenPercentageFull()
is met. Setting this to true can recover db connections from applications that fail to close a connection. See alsoPoolConfiguration.isLogAbandoned()
The default value is false.- Specified by:
isRemoveAbandoned
in interfacePoolConfiguration
- Returns:
- true if abandoned connections can be closed and expelled out of the pool
-
getAbandonWhenPercentageFull
public int getAbandonWhenPercentageFull()
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.- Specified by:
getAbandonWhenPercentageFull
in interfacePoolConfiguration
- Returns:
- percentage - a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
-
isTestOnBorrow
public boolean isTestOnBorrow()
The indication of whether objects will be validated before being borrowed from the pool. If the object fails to validate, it will be dropped from the pool, and we will attempt to borrow another. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)
- Specified by:
isTestOnBorrow
in interfacePoolConfiguration
- Returns:
- true if the connection is to be validated upon borrowing a connection from the pool
- See Also:
PoolConfiguration.getValidationInterval()
-
isTestOnConnect
public boolean isTestOnConnect()
Returns true if we should run the validation query when connecting to the database for the first time on a connection. Normally this is always set to false, unless one wants to use the validationQuery as an init query.- Specified by:
isTestOnConnect
in interfacePoolConfiguration
- Returns:
- true if we should run the validation query upon connect
-
isTestOnReturn
public boolean isTestOnReturn()
The indication of whether objects will be validated after being returned to the pool. If the object fails to validate, it will be dropped from the pool. NOTE - for a true value to have any effect, the validationQuery parameter must be set to a non-null string. Default value is false In order to have a more efficient validation, seePoolConfiguration.setValidationInterval(long)
- Specified by:
isTestOnReturn
in interfacePoolConfiguration
- Returns:
- true if validation should take place after a connection is returned to the pool
- See Also:
PoolConfiguration.getValidationInterval()
-
isTestWhileIdle
public boolean isTestWhileIdle()
Set to true if query validation should take place while the connection is idle.- Specified by:
isTestWhileIdle
in interfacePoolConfiguration
- Returns:
- true if validation should take place during idle checks
- See Also:
PoolConfiguration.setTimeBetweenEvictionRunsMillis(int)
-
getDefaultAutoCommit
public java.lang.Boolean getDefaultAutoCommit()
The default auto-commit state of connections created by this pool. If not set (null), default is JDBC driver default (If set to null then theConnection.setAutoCommit(boolean)
method will not be called.)- Specified by:
getDefaultAutoCommit
in interfacePoolConfiguration
- Returns:
- the default auto commit setting, null is Driver default.
-
getDefaultReadOnly
public java.lang.Boolean getDefaultReadOnly()
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.- Specified by:
getDefaultReadOnly
in interfacePoolConfiguration
- Returns:
- null if not set and accepting the driver default otherwise the read only value
-
getJdbcInterceptorsAsArray
public PoolProperties.InterceptorDefinition[] getJdbcInterceptorsAsArray()
Returns thePoolConfiguration.getJdbcInterceptors()
as an array of objects with properties and the classes.- Specified by:
getJdbcInterceptorsAsArray
in interfacePoolConfiguration
- Returns:
- an array of interceptors that have been configured
-
getUseLock
public boolean getUseLock()
Return true if a lock should be used when operations are performed on the connection object. Should be set to false unless you plan to have a background thread of your own doing idle and abandon checking such as JMX clients. If the pool sweeper is enabled, then the lock will automatically be used regardless of this setting.- Specified by:
getUseLock
in interfacePoolConfiguration
- Returns:
- true if a lock is used.
-
isFairQueue
public boolean isFairQueue()
Returnstrue
if a fair queue is being used by the connection pool- Specified by:
isFairQueue
in interfacePoolConfiguration
- Returns:
true
if a fair waiting queue is being used
-
isJmxEnabled
public boolean isJmxEnabled()
If set to true, the connection pool creates aConnectionPoolMBean
object that can be registered with JMX to receive notifications and state about the pool. The ConnectionPool object doesn't register itself, as there is no way to keep a static non changing ObjectName across JVM restarts.- Specified by:
isJmxEnabled
in interfacePoolConfiguration
- Returns:
- true if the mbean object will be created upon startup.
-
isUseEquals
public boolean isUseEquals()
Set to true if you wish theProxyConnection
class to useString.equals
instead of==
when comparing method names. This property does not apply to added interceptors as those are configured individually. The default value isfalse
.- Specified by:
isUseEquals
in interfacePoolConfiguration
- Returns:
- true if pool uses
String.equals(Object)
instead of == when comparing method names onConnection
methods
-
setAbandonWhenPercentageFull
public void setAbandonWhenPercentageFull(int percentage)
Connections that have been abandoned (timed out) wont get closed and reported up unless the number of connections in use are above the percentage defined by abandonWhenPercentageFull. The value should be between 0-100. The default value is 0, which implies that connections are eligible for closure as soon as removeAbandonedTimeout has been reached.- Specified by:
setAbandonWhenPercentageFull
in interfacePoolConfiguration
- Parameters:
percentage
- a value between 0 and 100 to indicate when connections that have been abandoned/timed out are considered abandoned
-
setAccessToUnderlyingConnectionAllowed
public void setAccessToUnderlyingConnectionAllowed(boolean accessToUnderlyingConnectionAllowed)
No-op- Specified by:
setAccessToUnderlyingConnectionAllowed
in interfacePoolConfiguration
- Parameters:
accessToUnderlyingConnectionAllowed
- parameter ignored
-
setDbProperties
public void setDbProperties(java.util.Properties dbProperties)
Overrides the database properties passed into theDriver.connect(String, Properties)
method.- Specified by:
setDbProperties
in interfacePoolConfiguration
- Parameters:
dbProperties
- The database properties
-
setDefaultReadOnly
public void setDefaultReadOnly(java.lang.Boolean defaultReadOnly)
If non null, during connection creation the methodConnection.setReadOnly(boolean)
will be called with the set value.- Specified by:
setDefaultReadOnly
in interfacePoolConfiguration
- Parameters:
defaultReadOnly
- null if not set and accepting the driver default.
-
setMaxAge
public void setMaxAge(long maxAge)
Time in milliseconds to keep this connection before reconnecting. When a connection is idle, returned to the pool or borrowed from the pool, the pool will check to see if the ((now - time-when-connected) > maxAge) has been reached, and if so, it reconnects. Note that the age of idle connections will only be checked ifPoolConfiguration.getTimeBetweenEvictionRunsMillis()
returns a value greater than 0. The default value is 0, which implies that connections will be left open and no age checks will be done. This is a useful setting for database sessions that leak memory as it ensures that the session will have a finite life span.- Specified by:
setMaxAge
in interfacePoolConfiguration
- Parameters:
maxAge
- the time in milliseconds a connection will be open for when used
-
setName
public void setName(java.lang.String name)
Sets the name of the connection pool- Specified by:
setName
in interfacePoolConfiguration
- Parameters:
name
- the name of the pool, should be unique in a runtime JVM
-
setDataSource
public void setDataSource(java.lang.Object ds)
Injects a datasource that will be used to retrieve/create connections. If a data source is set, thePoolConfiguration.getUrl()
andPoolConfiguration.getDriverClassName()
methods are ignored and not used by the pool. If thePoolConfiguration.getUsername()
andPoolConfiguration.getPassword()
values are set, the methodDataSource.getConnection(String, String)
method will be called instead of theDataSource.getConnection()
method. If the data source implementsXADataSource
the methodsXADataSource.getXAConnection()
andXADataSource.getXAConnection(String,String)
will be invoked.- Specified by:
setDataSource
in interfacePoolConfiguration
- Parameters:
ds
- theDataSource
to be used for creating connections to be pooled.
-
getDataSource
public java.lang.Object getDataSource()
Returns a datasource, if one exists that is being used to create connections. This method will return null if the pool is using aDriver
- Specified by:
getDataSource
in interfacePoolConfiguration
- Returns:
- the
DataSource
to be used for creating connections to be pooled or null if a Driver is used.
-
setDataSourceJNDI
public void setDataSourceJNDI(java.lang.String jndiDS)
Configure the connection pool to use a DataSource according toPoolConfiguration.setDataSource(Object)
But instead of injecting the object, specify the JNDI location. After a successful JNDI look, thePoolConfiguration.getDataSource()
will not return null.- Specified by:
setDataSourceJNDI
in interfacePoolConfiguration
- Parameters:
jndiDS
- -the JNDI string @TODO specify the rules here.
-
getDataSourceJNDI
public java.lang.String getDataSourceJNDI()
Returns the JNDI string configured for data source usage.- Specified by:
getDataSourceJNDI
in interfacePoolConfiguration
- Returns:
- the JNDI string or null if not set
-
isAlternateUsernameAllowed
public boolean isAlternateUsernameAllowed()
Returns true if the callgetConnection(username,password)
is allowed. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on.- Specified by:
isAlternateUsernameAllowed
in interfacePoolConfiguration
- Returns:
- true if
getConnection(username,password)
is honored, false if it is ignored.
-
setAlternateUsernameAllowed
public void setAlternateUsernameAllowed(boolean alternateUsernameAllowed)
Set to true if the callgetConnection(username,password)
is allowed and honored.. This is used for when the pool is used by an application accessing multiple schemas. There is a performance impact turning this option on, even when not used due to username checks.- Specified by:
setAlternateUsernameAllowed
in interfacePoolConfiguration
- Parameters:
alternateUsernameAllowed
- - set true ifgetConnection(username,password)
is honored, false if it is to be ignored.
-
setCommitOnReturn
public void setCommitOnReturn(boolean commitOnReturn)
Set to true if you want the connection pool to commit any pending transaction when a connection is returned. The default value is false, as this could result in committing data. This parameter is only looked at if thePoolConfiguration.getDefaultAutoCommit()
returns false- Specified by:
setCommitOnReturn
in interfacePoolConfiguration
- Parameters:
commitOnReturn
- set to true if the pool should callConnection.commit()
when a connection is returned to the pool. Default is false
-
getCommitOnReturn
public boolean getCommitOnReturn()
- Specified by:
getCommitOnReturn
in interfacePoolConfiguration
- Returns:
true
if the pool should commit when a connection is returned to it- See Also:
PoolConfiguration.setCommitOnReturn(boolean)
-
setRollbackOnReturn
public void setRollbackOnReturn(boolean rollbackOnReturn)
Set to true if you want the connection pool to rollback any pending transaction when a connection is returned. The default value is false, as this could result in committing data. This parameter is only looked at if thePoolConfiguration.getDefaultAutoCommit()
returns false- Specified by:
setRollbackOnReturn
in interfacePoolConfiguration
- Parameters:
rollbackOnReturn
- set to true if the pool should callConnection.rollback()
when a connection is returned to the pool. Default is false
-
getRollbackOnReturn
public boolean getRollbackOnReturn()
- Specified by:
getRollbackOnReturn
in interfacePoolConfiguration
- Returns:
true
if the pool should rollback when a connection is returned to it- See Also:
PoolConfiguration.setRollbackOnReturn(boolean)
-
setUseDisposableConnectionFacade
public void setUseDisposableConnectionFacade(boolean useDisposableConnectionFacade)
If set totrue
, the connection will be wrapped with facade that will disallow the connection to be used afterConnection.close()
is called. If set totrue
, afterConnection.close()
all calls exceptConnection.close()
andConnection.isClosed()
will throw an exception.- Specified by:
setUseDisposableConnectionFacade
in interfacePoolConfiguration
- Parameters:
useDisposableConnectionFacade
-true
to use a facade
-
getUseDisposableConnectionFacade
public boolean getUseDisposableConnectionFacade()
Returnstrue
if this connection pool is configured to use a connection facade to prevent re-use of connection afterConnection.close()
has been invoked- Specified by:
getUseDisposableConnectionFacade
in interfacePoolConfiguration
- Returns:
true
ifConnection.close()
has been invoked.
-
setLogValidationErrors
public void setLogValidationErrors(boolean logValidationErrors)
Set to true if you wish that errors from validation should be logged as error messages.- Specified by:
setLogValidationErrors
in interfacePoolConfiguration
- Parameters:
logValidationErrors
- set to true to log validation errors
-
getLogValidationErrors
public boolean getLogValidationErrors()
Returns true if errors that happen during validation will be logged- Specified by:
getLogValidationErrors
in interfacePoolConfiguration
- Returns:
- true if errors that happen during validation will be logged
-
getPropagateInterruptState
public boolean getPropagateInterruptState()
Returns true if the pool is configured to propagate interrupt state of a thread. A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aPoolExhaustedException
- Specified by:
getPropagateInterruptState
in interfacePoolConfiguration
- Returns:
- true if the pool is configured to propagate and not clear the thread interrupt state
-
setPropagateInterruptState
public void setPropagateInterruptState(boolean propagateInterruptState)
Configure the pool to propagate interrupt state for interrupted threads waiting for a connection A thread waiting for a connection, can have its wait interrupted, and by default will clear the interrupt flag and throw aPoolExhaustedException
If set to true, this behavior will change, while thePoolExhaustedException
is still thrown, the threads interrupted state is still set.- Specified by:
setPropagateInterruptState
in interfacePoolConfiguration
- Parameters:
propagateInterruptState
- - set to true to not clear, but propagate, a threads interrupted state.
-
isIgnoreExceptionOnPreLoad
public boolean isIgnoreExceptionOnPreLoad()
- Specified by:
isIgnoreExceptionOnPreLoad
in interfacePoolConfiguration
- Returns:
true
to ignore exceptions- See Also:
PoolConfiguration.setIgnoreExceptionOnPreLoad(boolean)
-
setIgnoreExceptionOnPreLoad
public void setIgnoreExceptionOnPreLoad(boolean ignoreExceptionOnPreLoad)
Set to true if you want to ignore error of connection creation while initializing the pool. Set to false if you want to fail the initialization of the pool by throwing exception.- Specified by:
setIgnoreExceptionOnPreLoad
in interfacePoolConfiguration
- Parameters:
ignoreExceptionOnPreLoad
- set to true if you want to ignore error of connection creation while initializing the pool.
-
getUseStatementFacade
public boolean getUseStatementFacade()
Returnstrue
if this connection pool is configured to wrap statements in order to enable equals() and hashCode() methods to be called on the closed statements if any statement proxy is set.- Specified by:
getUseStatementFacade
in interfacePoolConfiguration
- Returns:
true
if the statements are wrapped
-
setUseStatementFacade
public void setUseStatementFacade(boolean useStatementFacade)
Set this to true if you wish to wrap statements in order to enable equals() and hashCode() methods to be called on the closed statements if any statement proxy is set.- Specified by:
setUseStatementFacade
in interfacePoolConfiguration
- Parameters:
useStatementFacade
- set totrue
to wrap statements
-
purge
public void purge()
-
purgeOnReturn
public void purgeOnReturn()
-
-