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
FieldsModifier and TypeFieldDescriptionprivate static final org.datanucleus.util.NucleusLoggerprivate Map<PoolKey, PooledConnectionManager> Map to keep track of Pools for a given user.private static final longFields inherited from class InstanceKeyDataSource
UNKNOWN_TRANSACTIONISOLATION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears pool(s) maintained by this data source.voidclose()Closes pool(s) maintained by this data source.protected PooledConnectionManagergetConnectionManager(UserPassKey upKey) private ObjectPool<PooledConnectionAndInfo> intGets the number of active connections in the default pool.intgetNumActive(String userName) Gets the number of active connections in the pool for a given user.intGets the number of idle connections in the default pool.intgetNumIdle(String userName) Gets the number of idle connections in the pool for a given user.booleangetPerUserBlockWhenExhausted(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.booleangetPerUserLifo(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.intgetPerUserMaxIdle(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.intgetPerUserMaxTotal(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.longgetPerUserMaxWaitMillis(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.longgetPerUserMinEvictableIdleTimeMillis(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.intgetPerUserMinIdle(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.intgetPerUserNumTestsPerEvictionRun(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.longGets the user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()for the specified user's pool or the default if no user specific value is defined.booleangetPerUserTestOnBorrow(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.booleangetPerUserTestOnCreate(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.booleangetPerUserTestOnReturn(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.booleangetPerUserTestWhileIdle(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.longGets the user specific value forBaseGenericObjectPool.getTimeBetweenEvictionRunsMillis()for the specified user's pool or the default if no user specific value is defined.private ObjectPool<PooledConnectionAndInfo> Returns the object pool associated with the given PoolKey.protected PooledConnectionAndInfogetPooledConnectionAndInfo(String userName, String password) private PoolKeygetPoolKey(String userName) Creates a pool key from the provided parameters.Returns aPerUserPoolDataSourceReference.private voidSupports Serialization interface.private voidregisterPool(String userName, String password) voidsetPerUserBlockWhenExhausted(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getBlockWhenExhausted()for the specified user's pool.(package private) voidsetPerUserBlockWhenExhausted(Map<String, Boolean> userDefaultBlockWhenExhausted) voidsetPerUserDefaultAutoCommit(String userName, Boolean value) Sets a user specific default value forConnection.setAutoCommit(boolean)for the specified user's pool.(package private) voidsetPerUserDefaultAutoCommit(Map<String, Boolean> userDefaultAutoCommit) voidsetPerUserDefaultReadOnly(String userName, Boolean value) Sets a user specific default value forConnection.setReadOnly(boolean)for the specified user's pool.(package private) voidsetPerUserDefaultReadOnly(Map<String, Boolean> userDefaultReadOnly) voidsetPerUserDefaultTransactionIsolation(String userName, Integer value) Sets a user specific default value forConnection.setTransactionIsolation(int)for the specified user's pool.(package private) voidsetPerUserDefaultTransactionIsolation(Map<String, Integer> userDefaultTransactionIsolation) voidsetPerUserEvictionPolicyClassName(String userName, String value) Sets a user specific value forBaseGenericObjectPool.getEvictionPolicyClassName()for the specified user's pool.(package private) voidsetPerUserEvictionPolicyClassName(Map<String, String> userDefaultEvictionPolicyClassName) voidsetPerUserLifo(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getLifo()for the specified user's pool.(package private) voidsetPerUserLifo(Map<String, Boolean> userDefaultLifo) voidsetPerUserMaxIdle(String userName, Integer value) Sets a user specific value forGenericObjectPool.getMaxIdle()for the specified user's pool.(package private) voidsetPerUserMaxIdle(Map<String, Integer> userDefaultMaxIdle) voidsetPerUserMaxTotal(String userName, Integer value) Sets a user specific value forBaseGenericObjectPool.getMaxTotal()for the specified user's pool.(package private) voidsetPerUserMaxTotal(Map<String, Integer> userDefaultMaxTotal) voidsetPerUserMaxWaitMillis(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getMaxWaitMillis()for the specified user's pool.(package private) voidsetPerUserMaxWaitMillis(Map<String, Long> userDefaultMaxWaitMillis) voidsetPerUserMinEvictableIdleTimeMillis(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getMinEvictableIdleTimeMillis()for the specified user's pool.(package private) voidsetPerUserMinEvictableIdleTimeMillis(Map<String, Long> userDefaultMinEvictableIdleTimeMillis) voidsetPerUserMinIdle(String userName, Integer value) Sets a user specific value forGenericObjectPool.getMinIdle()for the specified user's pool.(package private) voidsetPerUserMinIdle(Map<String, Integer> userDefaultMinIdle) voidsetPerUserNumTestsPerEvictionRun(String userName, Integer value) Sets a user specific value forBaseGenericObjectPool.getNumTestsPerEvictionRun()for the specified user's pool.(package private) voidsetPerUserNumTestsPerEvictionRun(Map<String, Integer> userDefaultNumTestsPerEvictionRun) voidsetPerUserSoftMinEvictableIdleTimeMillis(String userName, Long value) Sets a user specific value forBaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis()for the specified user's pool.(package private) voidsetPerUserSoftMinEvictableIdleTimeMillis(Map<String, Long> userDefaultSoftMinEvictableIdleTimeMillis) voidsetPerUserTestOnBorrow(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnBorrow()for the specified user's pool.(package private) voidsetPerUserTestOnBorrow(Map<String, Boolean> userDefaultTestOnBorrow) voidsetPerUserTestOnCreate(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnCreate()for the specified user's pool.(package private) voidsetPerUserTestOnCreate(Map<String, Boolean> userDefaultTestOnCreate) voidsetPerUserTestOnReturn(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestOnReturn()for the specified user's pool.(package private) voidsetPerUserTestOnReturn(Map<String, Boolean> userDefaultTestOnReturn) voidsetPerUserTestWhileIdle(String userName, Boolean value) Sets a user specific value forBaseGenericObjectPool.getTestWhileIdle()for the specified user's pool.(package private) voidsetPerUserTestWhileIdle(Map<String, Boolean> userDefaultTestWhileIdle) voidsetPerUserTimeBetweenEvictionRunsMillis(String userName, Long value) Sets a user specific value for()for the specified user's pool.(package private) voidsetPerUserTimeBetweenEvictionRunsMillis(Map<String, Long> userDefaultTimeBetweenEvictionRunsMillis) protected voidsetupDefaults(Connection con, String userName) Methods inherited from class 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, setJndiEnvironment, setLoginTimeout, setLogWriter, setMaxConnLifetimeMillis, setRollbackAfterValidation, setValidationQuery, setValidationQueryTimeout, testCPDS, toString, toStringFields, unwrapMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CommonDataSource
createShardingKeyBuilderMethods inherited from interface DataSource
createConnectionBuilder
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
log
private static final org.datanucleus.util.NucleusLogger log -
perUserBlockWhenExhausted
-
perUserEvictionPolicyClassName
-
perUserLifo
-
perUserMaxIdle
-
perUserMaxTotal
-
perUserMaxWaitMillis
-
perUserMinEvictableIdleTimeMillis
-
perUserMinIdle
-
perUserNumTestsPerEvictionRun
-
perUserSoftMinEvictableIdleTimeMillis
-
perUserTestOnCreate
-
perUserTestOnBorrow
-
perUserTestOnReturn
-
perUserTestWhileIdle
-
perUserTimeBetweenEvictionRunsMillis
-
perUserDefaultAutoCommit
-
perUserDefaultTransactionIsolation
-
perUserDefaultReadOnly
-
managers
Map to keep track of Pools for a given user.
-
-
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:
closein interfaceAutoCloseable- Specified by:
closein classInstanceKeyDataSource- See Also:
-
createMap
-
getConnectionManager
- Specified by:
getConnectionManagerin classInstanceKeyDataSource
-
getCPDSConnectionFactoryPool
private ObjectPool<PooledConnectionAndInfo> getCPDSConnectionFactoryPool(PooledConnectionManager manager) -
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.
-
getPool
Returns the object pool associated with the given PoolKey.- Parameters:
poolKey- PoolKey identifying the pool- Returns:
- the GenericObjectPool pooling connections for the userName and datasource specified by the PoolKey
-
getPooledConnectionAndInfo
protected PooledConnectionAndInfo getPooledConnectionAndInfo(String userName, String password) throws SQLException - Specified by:
getPooledConnectionAndInfoin classInstanceKeyDataSource- Throws:
SQLException
-
getPoolKey
-
getReference
Returns aPerUserPoolDataSourceReference.- Throws:
NamingException
-
readObject
Supports Serialization interface.- Parameters:
in- ajava.io.ObjectInputStreamvalue- Throws:
IOException- if an error occursClassNotFoundException- if an error occurs
-
registerPool
- Throws:
NamingExceptionSQLException
-
setPerUserBlockWhenExhausted
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
setPerUserTimeBetweenEvictionRunsMillis
-
setupDefaults
- Specified by:
setupDefaultsin classInstanceKeyDataSource- Throws:
SQLException
-