Class PerUserPoolDataSource

java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.datasources.InstanceKeyDataSource
org.datanucleus.store.rdbms.datasource.dbcp2.datasources.PerUserPoolDataSource
All Implemented Interfaces:
Serializable, AutoCloseable, Wrapper, Referenceable, CommonDataSource, DataSource

public class PerUserPoolDataSource extends InstanceKeyDataSource

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 Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • log

      private static final org.datanucleus.util.NucleusLogger log
    • perUserBlockWhenExhausted

      private Map<String,Boolean> perUserBlockWhenExhausted
    • perUserEvictionPolicyClassName

      private Map<String,String> perUserEvictionPolicyClassName
    • perUserLifo

      private Map<String,Boolean> perUserLifo
    • perUserMaxIdle

      private Map<String,Integer> perUserMaxIdle
    • perUserMaxTotal

      private Map<String,Integer> perUserMaxTotal
    • perUserMaxWaitMillis

      private Map<String,Long> perUserMaxWaitMillis
    • perUserMinEvictableIdleTimeMillis

      private Map<String,Long> perUserMinEvictableIdleTimeMillis
    • perUserMinIdle

      private Map<String,Integer> perUserMinIdle
    • perUserNumTestsPerEvictionRun

      private Map<String,Integer> perUserNumTestsPerEvictionRun
    • perUserSoftMinEvictableIdleTimeMillis

      private Map<String,Long> perUserSoftMinEvictableIdleTimeMillis
    • perUserTestOnCreate

      private Map<String,Boolean> perUserTestOnCreate
    • perUserTestOnBorrow

      private Map<String,Boolean> perUserTestOnBorrow
    • perUserTestOnReturn

      private Map<String,Boolean> perUserTestOnReturn
    • perUserTestWhileIdle

      private Map<String,Boolean> perUserTestWhileIdle
    • perUserTimeBetweenEvictionRunsMillis

      private Map<String,Long> perUserTimeBetweenEvictionRunsMillis
    • perUserDefaultAutoCommit

      private Map<String,Boolean> perUserDefaultAutoCommit
    • perUserDefaultTransactionIsolation

      private Map<String,Integer> perUserDefaultTransactionIsolation
    • perUserDefaultReadOnly

      private Map<String,Boolean> perUserDefaultReadOnly
    • managers

      private transient Map<PoolKey,PooledConnectionManager> 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:
      close in interface AutoCloseable
      Specified by:
      close in class InstanceKeyDataSource
      See Also:
    • createMap

      private HashMap<String,Boolean> createMap()
    • getConnectionManager

      protected PooledConnectionManager getConnectionManager(UserPassKey upKey)
      Specified by:
      getConnectionManager in class InstanceKeyDataSource
    • 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

      public int getNumActive(String userName)
      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

      public int getNumIdle(String userName)
      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

      public boolean getPerUserBlockWhenExhausted(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public Boolean getPerUserDefaultAutoCommit(String userName)
      Gets the user specific default value for Connection.setAutoCommit(boolean) for the specified user's pool.
      Parameters:
      userName - The user name key.
      Returns:
      The user specific value.
    • getPerUserDefaultReadOnly

      public Boolean getPerUserDefaultReadOnly(String userName)
      Gets the user specific default value for Connection.setReadOnly(boolean) for the specified user's pool.
      Parameters:
      userName - The user name key.
      Returns:
      The user specific value.
    • getPerUserDefaultTransactionIsolation

      public Integer getPerUserDefaultTransactionIsolation(String userName)
      Gets the user specific default value for Connection.setTransactionIsolation(int) for the specified user's pool.
      Parameters:
      userName - The user name key.
      Returns:
      The user specific value.
    • getPerUserEvictionPolicyClassName

      public String getPerUserEvictionPolicyClassName(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public boolean getPerUserLifo(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public int getPerUserMaxIdle(String userName)
      Gets the user specific value for GenericObjectPool.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

      public int getPerUserMaxTotal(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public long getPerUserMaxWaitMillis(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public long getPerUserMinEvictableIdleTimeMillis(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public int getPerUserMinIdle(String userName)
      Gets the user specific value for GenericObjectPool.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

      public int getPerUserNumTestsPerEvictionRun(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public long getPerUserSoftMinEvictableIdleTimeMillis(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public boolean getPerUserTestOnBorrow(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public boolean getPerUserTestOnCreate(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public boolean getPerUserTestOnReturn(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public boolean getPerUserTestWhileIdle(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      public long getPerUserTimeBetweenEvictionRunsMillis(String userName)
      Gets the user specific value for BaseGenericObjectPool.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

      private ObjectPool<PooledConnectionAndInfo> getPool(PoolKey poolKey)
      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:
      getPooledConnectionAndInfo in class InstanceKeyDataSource
      Throws:
      SQLException
    • getPoolKey

      private PoolKey getPoolKey(String userName)
      Creates a pool key from the provided parameters.
      Parameters:
      userName - User name
      Returns:
      The pool key
    • getReference

      public Reference getReference() throws NamingException
      Returns a PerUserPoolDataSource Reference.
      Throws:
      NamingException
    • readObject

      private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
      Supports Serialization interface.
      Parameters:
      in - a java.io.ObjectInputStream value
      Throws:
      IOException - if an error occurs
      ClassNotFoundException - if an error occurs
    • registerPool

      private void registerPool(String userName, String password) throws NamingException, SQLException
      Throws:
      NamingException
      SQLException
    • setPerUserBlockWhenExhausted

      void setPerUserBlockWhenExhausted(Map<String,Boolean> userDefaultBlockWhenExhausted)
    • setPerUserBlockWhenExhausted

      public void setPerUserBlockWhenExhausted(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getBlockWhenExhausted() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserDefaultAutoCommit

      void setPerUserDefaultAutoCommit(Map<String,Boolean> userDefaultAutoCommit)
    • setPerUserDefaultAutoCommit

      public void setPerUserDefaultAutoCommit(String userName, Boolean value)
      Sets a user specific default value for Connection.setAutoCommit(boolean) for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserDefaultReadOnly

      void setPerUserDefaultReadOnly(Map<String,Boolean> userDefaultReadOnly)
    • setPerUserDefaultReadOnly

      public void setPerUserDefaultReadOnly(String userName, Boolean value)
      Sets a user specific default value for Connection.setReadOnly(boolean) for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserDefaultTransactionIsolation

      void setPerUserDefaultTransactionIsolation(Map<String,Integer> userDefaultTransactionIsolation)
    • setPerUserDefaultTransactionIsolation

      public void setPerUserDefaultTransactionIsolation(String userName, Integer value)
      Sets a user specific default value for Connection.setTransactionIsolation(int) for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserEvictionPolicyClassName

      void setPerUserEvictionPolicyClassName(Map<String,String> userDefaultEvictionPolicyClassName)
    • setPerUserEvictionPolicyClassName

      public void setPerUserEvictionPolicyClassName(String userName, String value)
      Sets a user specific value for BaseGenericObjectPool.getEvictionPolicyClassName() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserLifo

      void setPerUserLifo(Map<String,Boolean> userDefaultLifo)
    • setPerUserLifo

      public void setPerUserLifo(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getLifo() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserMaxIdle

      void setPerUserMaxIdle(Map<String,Integer> userDefaultMaxIdle)
    • setPerUserMaxIdle

      public void setPerUserMaxIdle(String userName, Integer value)
      Sets a user specific value for GenericObjectPool.getMaxIdle() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserMaxTotal

      void setPerUserMaxTotal(Map<String,Integer> userDefaultMaxTotal)
    • setPerUserMaxTotal

      public void setPerUserMaxTotal(String userName, Integer value)
      Sets a user specific value for BaseGenericObjectPool.getMaxTotal() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserMaxWaitMillis

      void setPerUserMaxWaitMillis(Map<String,Long> userDefaultMaxWaitMillis)
    • setPerUserMaxWaitMillis

      public void setPerUserMaxWaitMillis(String userName, Long value)
      Sets a user specific value for BaseGenericObjectPool.getMaxWaitMillis() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserMinEvictableIdleTimeMillis

      void setPerUserMinEvictableIdleTimeMillis(Map<String,Long> userDefaultMinEvictableIdleTimeMillis)
    • setPerUserMinEvictableIdleTimeMillis

      public void setPerUserMinEvictableIdleTimeMillis(String userName, Long value)
      Sets a user specific value for BaseGenericObjectPool.getMinEvictableIdleTimeMillis() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserMinIdle

      void setPerUserMinIdle(Map<String,Integer> userDefaultMinIdle)
    • setPerUserMinIdle

      public void setPerUserMinIdle(String userName, Integer value)
      Sets a user specific value for GenericObjectPool.getMinIdle() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserNumTestsPerEvictionRun

      void setPerUserNumTestsPerEvictionRun(Map<String,Integer> userDefaultNumTestsPerEvictionRun)
    • setPerUserNumTestsPerEvictionRun

      public void setPerUserNumTestsPerEvictionRun(String userName, Integer value)
      Sets a user specific value for BaseGenericObjectPool.getNumTestsPerEvictionRun() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserSoftMinEvictableIdleTimeMillis

      void setPerUserSoftMinEvictableIdleTimeMillis(Map<String,Long> userDefaultSoftMinEvictableIdleTimeMillis)
    • setPerUserSoftMinEvictableIdleTimeMillis

      public void setPerUserSoftMinEvictableIdleTimeMillis(String userName, Long value)
      Sets a user specific value for BaseGenericObjectPool.getSoftMinEvictableIdleTimeMillis() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserTestOnBorrow

      void setPerUserTestOnBorrow(Map<String,Boolean> userDefaultTestOnBorrow)
    • setPerUserTestOnBorrow

      public void setPerUserTestOnBorrow(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getTestOnBorrow() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserTestOnCreate

      void setPerUserTestOnCreate(Map<String,Boolean> userDefaultTestOnCreate)
    • setPerUserTestOnCreate

      public void setPerUserTestOnCreate(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getTestOnCreate() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserTestOnReturn

      void setPerUserTestOnReturn(Map<String,Boolean> userDefaultTestOnReturn)
    • setPerUserTestOnReturn

      public void setPerUserTestOnReturn(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getTestOnReturn() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserTestWhileIdle

      void setPerUserTestWhileIdle(Map<String,Boolean> userDefaultTestWhileIdle)
    • setPerUserTestWhileIdle

      public void setPerUserTestWhileIdle(String userName, Boolean value)
      Sets a user specific value for BaseGenericObjectPool.getTestWhileIdle() for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setPerUserTimeBetweenEvictionRunsMillis

      void setPerUserTimeBetweenEvictionRunsMillis(Map<String,Long> userDefaultTimeBetweenEvictionRunsMillis)
    • setPerUserTimeBetweenEvictionRunsMillis

      public void setPerUserTimeBetweenEvictionRunsMillis(String userName, Long value)
      Sets a user specific value for () for the specified user's pool.
      Parameters:
      userName - The user name key.
      value - The user specific value.
    • setupDefaults

      protected void setupDefaults(Connection con, String userName) throws SQLException
      Specified by:
      setupDefaults in class InstanceKeyDataSource
      Throws:
      SQLException