Class PerUserPoolDataSource
- All Implemented Interfaces:
Serializable
,AutoCloseable
,Wrapper
,Referenceable
,CommonDataSource
,DataSource
A pooling DataSource
appropriate for deployment within J2EE environment. There are many configuration
options, most of which are defined in the parent class. This datasource uses individual pools per user, and some
properties can be set specifically for a given user, if the deployment environment can support initialization of
mapped properties. So for example, a pool of admin or write-access Connections can be guaranteed a certain number of
connections, separate from a maximum set for users with read-only connections.
User passwords can be changed without re-initializing the datasource. When a
getConnection(userName, password)
request is processed with a password that is different from those used
to create connections in the pool associated with userName
, an attempt is made to create a new
connection using the supplied password and if this succeeds, the existing pool is cleared and a new pool is created
for connections using the new password.
- Since:
- 2.0
- See Also:
-
Field Summary
Fields inherited from class org.apache.tomcat.dbcp.dbcp2.datasources.InstanceKeyDataSource
UNKNOWN_TRANSACTIONISOLATION
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears pool(s) maintained by this data source.void
close()
Closes pool(s) maintained by this data source.protected org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionManager
getConnectionManager
(org.apache.tomcat.dbcp.dbcp2.datasources.UserPassKey upKey) int
Gets the number of active connections in the default pool.int
getNumActive
(String userName) Gets the number of active connections in the pool for a given user.int
Gets the number of idle connections in the default pool.int
getNumIdle
(String userName) Gets the number of idle connections in the pool for a given user.boolean
getPerUserBlockWhenExhausted
(String userName) Gets the user specific value forBaseGenericObjectPool.getBlockWhenExhausted()
for the specified user's pool or the default if no user specific value is defined.getPerUserDefaultAutoCommit
(String userName) Gets the user specific default value forConnection.setAutoCommit(boolean)
for the specified user's pool.getPerUserDefaultReadOnly
(String userName) Gets the user specific default value forConnection.setReadOnly(boolean)
for the specified user's pool.getPerUserDefaultTransactionIsolation
(String userName) Gets the user specific default value forConnection.setTransactionIsolation(int)
for the specified user's pool.getPerUserEvictionPolicyClassName
(String userName) Gets the user specific value forBaseGenericObjectPool.getEvictionPolicyClassName()
for the specified user's pool or the default if no user specific value is defined.boolean
getPerUserLifo
(String userName) Gets the user specific value forBaseGenericObjectPool.getLifo()
for the specified user's pool or the default if no user specific value is defined.int
getPerUserMaxIdle
(String userName) Gets the user specific value forGenericObjectPool.getMaxIdle()
for the specified user's pool or the default if no user specific value is defined.int
getPerUserMaxTotal
(String userName) Gets the user specific value forBaseGenericObjectPool.getMaxTotal()
for the specified user's pool or the default if no user specific value is defined.long
getPerUserMaxWaitMillis
(String userName) Gets the user specific value forBaseGenericObjectPool.getMaxWaitMillis()
for the specified user's pool or the default if no user specific value is defined.long
getPerUserMinEvictableIdleTimeMillis
(String userName) Gets the user specific value forBaseGenericObjectPool.getMinEvictableIdleTimeMillis()
for the specified user's pool or the default if no user specific value is defined.int
getPerUserMinIdle
(String userName) Gets the user specific value forGenericObjectPool.getMinIdle()
for the specified user's pool or the default if no user specific value is defined.int
getPerUserNumTestsPerEvictionRun
(String userName) Gets the user specific value forBaseGenericObjectPool.getNumTestsPerEvictionRun()
for the specified user's pool or the default if no user specific value is defined.long
Gets the user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()
for the specified user's pool or the default if no user specific value is defined.boolean
getPerUserTestOnBorrow
(String userName) Gets the user specific value forBaseGenericObjectPool.getTestOnBorrow()
for the specified user's pool or the default if no user specific value is defined.boolean
getPerUserTestOnCreate
(String userName) Gets the user specific value forBaseGenericObjectPool.getTestOnCreate()
for the specified user's pool or the default if no user specific value is defined.boolean
getPerUserTestOnReturn
(String userName) Gets the user specific value forBaseGenericObjectPool.getTestOnReturn()
for the specified user's pool or the default if no user specific value is defined.boolean
getPerUserTestWhileIdle
(String userName) Gets the user specific value forBaseGenericObjectPool.getTestWhileIdle()
for the specified user's pool or the default if no user specific value is defined.long
Gets the user specific value forBaseGenericObjectPool.getTimeBetweenEvictionRunsMillis()
for the specified user's pool or the default if no user specific value is defined.protected org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionAndInfo
getPooledConnectionAndInfo
(String userName, String password) Returns aPerUserPoolDataSource
Reference
.void
setPerUserBlockWhenExhausted
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getBlockWhenExhausted()
for the specified user's pool.void
setPerUserDefaultAutoCommit
(String userName, Boolean value) Sets a user specific default value forConnection.setAutoCommit(boolean)
for the specified user's pool.void
setPerUserDefaultReadOnly
(String userName, Boolean value) Sets a user specific default value forConnection.setReadOnly(boolean)
for the specified user's pool.void
setPerUserDefaultTransactionIsolation
(String userName, Integer value) Sets a user specific default value forConnection.setTransactionIsolation(int)
for the specified user's pool.void
setPerUserEvictionPolicyClassName
(String userName, String value) Sets a user specific value forBaseGenericObjectPool.getEvictionPolicyClassName()
for the specified user's pool.void
setPerUserLifo
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getLifo()
for the specified user's pool.void
setPerUserMaxIdle
(String userName, Integer value) Sets a user specific value forGenericObjectPool.getMaxIdle()
for the specified user's pool.void
setPerUserMaxTotal
(String userName, Integer value) Sets a user specific value forBaseGenericObjectPool.getMaxTotal()
for the specified user's pool.void
setPerUserMaxWaitMillis
(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getMaxWaitMillis()
for the specified user's pool.void
setPerUserMinEvictableIdleTimeMillis
(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getMinEvictableIdleTimeMillis()
for the specified user's pool.void
setPerUserMinIdle
(String userName, Integer value) Sets a user specific value forGenericObjectPool.getMinIdle()
for the specified user's pool.void
setPerUserNumTestsPerEvictionRun
(String userName, Integer value) Sets a user specific value forBaseGenericObjectPool.getNumTestsPerEvictionRun()
for the specified user's pool.void
setPerUserSoftMinEvictableIdleTimeMillis
(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()
for the specified user's pool.void
setPerUserTestOnBorrow
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnBorrow()
for the specified user's pool.void
setPerUserTestOnCreate
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnCreate()
for the specified user's pool.void
setPerUserTestOnReturn
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnReturn()
for the specified user's pool.void
setPerUserTestWhileIdle
(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestWhileIdle()
for the specified user's pool.void
setPerUserTimeBetweenEvictionRunsMillis
(String userName, Long value) Sets a user specific value for()
for the specified user's pool.protected void
setupDefaults
(Connection con, String userName) Methods inherited from class org.apache.tomcat.dbcp.dbcp2.datasources.InstanceKeyDataSource
assertInitializationAllowed, getConnection, getConnection, getConnectionPoolDataSource, getDataSourceName, getDefaultBlockWhenExhausted, getDefaultEvictionPolicyClassName, getDefaultLifo, getDefaultMaxIdle, getDefaultMaxTotal, getDefaultMaxWaitMillis, getDefaultMinEvictableIdleTimeMillis, getDefaultMinIdle, getDefaultNumTestsPerEvictionRun, getDefaultSoftMinEvictableIdleTimeMillis, getDefaultTestOnBorrow, getDefaultTestOnCreate, getDefaultTestOnReturn, getDefaultTestWhileIdle, getDefaultTimeBetweenEvictionRunsMillis, getDefaultTransactionIsolation, getDescription, getInstanceKey, getJndiEnvironment, getLoginTimeout, getLogWriter, getMaxConnLifetimeMillis, getParentLogger, getValidationQuery, getValidationQueryTimeout, isDefaultAutoCommit, isDefaultReadOnly, isRollbackAfterValidation, isWrapperFor, setConnectionPoolDataSource, setDataSourceName, setDefaultAutoCommit, setDefaultBlockWhenExhausted, setDefaultEvictionPolicyClassName, setDefaultLifo, setDefaultMaxIdle, setDefaultMaxTotal, setDefaultMaxWaitMillis, setDefaultMinEvictableIdleTimeMillis, setDefaultMinIdle, setDefaultNumTestsPerEvictionRun, setDefaultReadOnly, setDefaultSoftMinEvictableIdleTimeMillis, setDefaultTestOnBorrow, setDefaultTestOnCreate, setDefaultTestOnReturn, setDefaultTestWhileIdle, setDefaultTimeBetweenEvictionRunsMillis, setDefaultTransactionIsolation, setDescription, setJndiEnvironment, setLoginTimeout, setLogWriter, setMaxConnLifetimeMillis, setRollbackAfterValidation, setValidationQuery, setValidationQueryTimeout, testCPDS, toString, toStringFields, unwrap
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface javax.sql.CommonDataSource
createShardingKeyBuilder
Methods inherited from interface javax.sql.DataSource
createConnectionBuilder
-
Constructor Details
-
PerUserPoolDataSource
public PerUserPoolDataSource()Default no-arg constructor for Serialization.
-
-
Method Details
-
clear
public void clear()Clears pool(s) maintained by this data source.- Since:
- 2.3.0
- See Also:
-
close
public void close()Closes pool(s) maintained by this data source.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in classInstanceKeyDataSource
- See Also:
-
getConnectionManager
protected org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionManager getConnectionManager(org.apache.tomcat.dbcp.dbcp2.datasources.UserPassKey upKey) - Specified by:
getConnectionManager
in classInstanceKeyDataSource
-
getNumActive
public int getNumActive()Gets the number of active connections in the default pool.- Returns:
- The number of active connections in the default pool.
-
getNumActive
Gets the number of active connections in the pool for a given user.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getNumIdle
public int getNumIdle()Gets the number of idle connections in the default pool.- Returns:
- The number of idle connections in the default pool.
-
getNumIdle
Gets the number of idle connections in the pool for a given user.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserBlockWhenExhausted
Gets the user specific value forBaseGenericObjectPool.getBlockWhenExhausted()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserDefaultAutoCommit
Gets the user specific default value forConnection.setAutoCommit(boolean)
for the specified user's pool.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserDefaultReadOnly
Gets the user specific default value forConnection.setReadOnly(boolean)
for the specified user's pool.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserDefaultTransactionIsolation
Gets the user specific default value forConnection.setTransactionIsolation(int)
for the specified user's pool.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserEvictionPolicyClassName
Gets the user specific value forBaseGenericObjectPool.getEvictionPolicyClassName()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserLifo
Gets the user specific value forBaseGenericObjectPool.getLifo()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserMaxIdle
Gets the user specific value forGenericObjectPool.getMaxIdle()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserMaxTotal
Gets the user specific value forBaseGenericObjectPool.getMaxTotal()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserMaxWaitMillis
Gets the user specific value forBaseGenericObjectPool.getMaxWaitMillis()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserMinEvictableIdleTimeMillis
Gets the user specific value forBaseGenericObjectPool.getMinEvictableIdleTimeMillis()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserMinIdle
Gets the user specific value forGenericObjectPool.getMinIdle()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserNumTestsPerEvictionRun
Gets the user specific value forBaseGenericObjectPool.getNumTestsPerEvictionRun()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserSoftMinEvictableIdleTimeMillis
Gets the user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserTestOnBorrow
Gets the user specific value forBaseGenericObjectPool.getTestOnBorrow()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserTestOnCreate
Gets the user specific value forBaseGenericObjectPool.getTestOnCreate()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserTestOnReturn
Gets the user specific value forBaseGenericObjectPool.getTestOnReturn()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserTestWhileIdle
Gets the user specific value forBaseGenericObjectPool.getTestWhileIdle()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPerUserTimeBetweenEvictionRunsMillis
Gets the user specific value forBaseGenericObjectPool.getTimeBetweenEvictionRunsMillis()
for the specified user's pool or the default if no user specific value is defined.- Parameters:
userName
- The user name key.- Returns:
- The user specific value.
-
getPooledConnectionAndInfo
protected org.apache.tomcat.dbcp.dbcp2.datasources.PooledConnectionAndInfo getPooledConnectionAndInfo(String userName, String password) throws SQLException - Specified by:
getPooledConnectionAndInfo
in classInstanceKeyDataSource
- Throws:
SQLException
-
getReference
Returns aPerUserPoolDataSource
Reference
.- Throws:
NamingException
-
setPerUserBlockWhenExhausted
Sets a user specific value forBaseGenericObjectPool.getBlockWhenExhausted()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserDefaultAutoCommit
Sets a user specific default value forConnection.setAutoCommit(boolean)
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserDefaultReadOnly
Sets a user specific default value forConnection.setReadOnly(boolean)
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserDefaultTransactionIsolation
Sets a user specific default value forConnection.setTransactionIsolation(int)
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserEvictionPolicyClassName
Sets a user specific value forBaseGenericObjectPool.getEvictionPolicyClassName()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserLifo
Sets a user specific value forBaseGenericObjectPool.getLifo()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserMaxIdle
Sets a user specific value forGenericObjectPool.getMaxIdle()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserMaxTotal
Sets a user specific value forBaseGenericObjectPool.getMaxTotal()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserMaxWaitMillis
Sets a user specific value forBaseGenericObjectPool.getMaxWaitMillis()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserMinEvictableIdleTimeMillis
Sets a user specific value forBaseGenericObjectPool.getMinEvictableIdleTimeMillis()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserMinIdle
Sets a user specific value forGenericObjectPool.getMinIdle()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserNumTestsPerEvictionRun
Sets a user specific value forBaseGenericObjectPool.getNumTestsPerEvictionRun()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserSoftMinEvictableIdleTimeMillis
Sets a user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserTestOnBorrow
Sets a user specific value forBaseGenericObjectPool.getTestOnBorrow()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserTestOnCreate
Sets a user specific value forBaseGenericObjectPool.getTestOnCreate()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserTestOnReturn
Sets a user specific value forBaseGenericObjectPool.getTestOnReturn()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserTestWhileIdle
Sets a user specific value forBaseGenericObjectPool.getTestWhileIdle()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setPerUserTimeBetweenEvictionRunsMillis
Sets a user specific value for()
for the specified user's pool.- Parameters:
userName
- The user name key.value
- The user specific value.
-
setupDefaults
- Specified by:
setupDefaults
in classInstanceKeyDataSource
- Throws:
SQLException
-