Class BaseKeyedPooledObjectFactory<K,V>

java.lang.Object
org.datanucleus.store.rdbms.datasource.dbcp2.pool2.BaseObject
org.datanucleus.store.rdbms.datasource.dbcp2.pool2.BaseKeyedPooledObjectFactory<K,V>
Type Parameters:
K - The type of keys managed by this factory.
V - Type of element managed by this factory.
All Implemented Interfaces:
KeyedPooledObjectFactory<K,V>

public abstract class BaseKeyedPooledObjectFactory<K,V> extends BaseObject implements KeyedPooledObjectFactory<K,V>
A base implementation of KeyedPooledObjectFactory.

All operations defined here are essentially no-op's.

This class is immutable, and therefore thread-safe.

Since:
2.0
See Also:
  • Constructor Details

    • BaseKeyedPooledObjectFactory

      public BaseKeyedPooledObjectFactory()
  • Method Details

    • create

      public abstract V create(K key) throws Exception
      Create an instance that can be served by the pool.
      Parameters:
      key - the key used when constructing the object
      Returns:
      an instance that can be served by the pool
      Throws:
      Exception - if there is a problem creating a new instance, this will be propagated to the code requesting an object.
    • wrap

      public abstract PooledObject<V> wrap(V value)
      Wrap the provided instance with an implementation of PooledObject.
      Parameters:
      value - the instance to wrap
      Returns:
      The provided instance, wrapped by a PooledObject
    • makeObject

      public PooledObject<V> makeObject(K key) throws Exception
      Description copied from interface: KeyedPooledObjectFactory
      Create an instance that can be served by the pool and wrap it in a PooledObject to be managed by the pool.
      Specified by:
      makeObject in interface KeyedPooledObjectFactory<K,V>
      Parameters:
      key - the key used when constructing the object
      Returns:
      a PooledObject wrapping an instance that can be served by the pool.
      Throws:
      Exception - if there is a problem creating a new instance, this will be propagated to the code requesting an object.
    • destroyObject

      public void destroyObject(K key, PooledObject<V> p) throws Exception
      Destroy an instance no longer needed by the pool.

      The default implementation is a no-op.

      Specified by:
      destroyObject in interface KeyedPooledObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the instance
      p - a PooledObject wrapping the instance to be destroyed
      Throws:
      Exception - should be avoided as it may be swallowed by the pool implementation.
      See Also:
    • validateObject

      public boolean validateObject(K key, PooledObject<V> p)
      Ensures that the instance is safe to be returned by the pool.

      The default implementation always returns true.

      Specified by:
      validateObject in interface KeyedPooledObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      p - a PooledObject wrapping the instance to be validated
      Returns:
      always true in the default implementation
    • activateObject

      public void activateObject(K key, PooledObject<V> p) throws Exception
      Reinitialize an instance to be returned by the pool.

      The default implementation is a no-op.

      Specified by:
      activateObject in interface KeyedPooledObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      p - a PooledObject wrapping the instance to be activated
      Throws:
      Exception - if there is a problem activating obj, this exception may be swallowed by the pool.
      See Also:
    • passivateObject

      public void passivateObject(K key, PooledObject<V> p) throws Exception
      Uninitialize an instance to be returned to the idle object pool.

      The default implementation is a no-op.

      Specified by:
      passivateObject in interface KeyedPooledObjectFactory<K,V>
      Parameters:
      key - the key used when selecting the object
      p - a PooledObject wrapping the instance to be passivated
      Throws:
      Exception - if there is a problem passivating obj, this exception may be swallowed by the pool.
      See Also: