com.bristle.javalib.sql
Class ConnectionPoolFinder

java.lang.Object
  extended by com.bristle.javalib.sql.ConnectionPoolFinder

public class ConnectionPoolFinder
extends Object

This class makes it possible for Java servlets to access an existing ConnectionPool that may be stored in the servlet's Session context, the servlet's ServletContext (application context), or as the ConnectionPool global singleton.

Usage:
       - The typical scenario for using this class is:
         - To find a ConnectionPool:
             ConnectionPoolFinder finder = new ConnectionPoolFinder(request);
             ConnectionPool pool = finder.find();
         - To save a ConnectionPool to be found by future calls to find(): 
             finder.saveInSession(pool);
             finder.saveInServletContext(pool)
             finder.saveAsGlobalSingleton(pool)  
Assumptions:
Effects:
       - Can update the servlet's Session context, ServletContext, and/or
         the ConnectionPool global singleton.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class ConnectionPoolFinder.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
private  HttpServletRequest m_request
           
static HttpServletRequest poolFIND_SINGLETON_ONLY
          Constant for use as parameter to constructor.
private  String strCONNECTION_POOL_ATTRIBUTE_NAME
           
 
Constructor Summary
ConnectionPoolFinder(HttpServletRequest request)
          Constructor.
 
Method Summary
 ConnectionPool find()
          Find an existing ConnectionPool, searching first the Session context of the previously specified HttpServletRequest (if any), then the ServletContext (application context) of the servlet associated with that HttpServletRequest (if any), then the ConnectionPool global singleton (if any), returning null if no ConnectionPool is found in any of those places.
 void saveAsGlobalSingleton(ConnectionPool pool)
          Save the specified ConnectionPool as the ConnectionPool global singleton, to be found by future calls to find().
 void saveInServletContext(ConnectionPool pool)
          Save the specified ConnectionPool in the ServletContext to be found by future calls to find().
 void saveInSession(ConnectionPool pool)
          Save the specified ConnectionPool in the Session to be found by future calls to find().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_request

private HttpServletRequest m_request

strCONNECTION_POOL_ATTRIBUTE_NAME

private final String strCONNECTION_POOL_ATTRIBUTE_NAME

poolFIND_SINGLETON_ONLY

public static final HttpServletRequest poolFIND_SINGLETON_ONLY
Constant for use as parameter to constructor.

Constructor Detail

ConnectionPoolFinder

public ConnectionPoolFinder(HttpServletRequest request)
Constructor.

Parameters:
request - The HttpServletRequest used to locate the contexts to be searched for the ConnectionPool, or null to cause find to skip directly to the singleton when searching.
Method Detail

find

public ConnectionPool find()
Find an existing ConnectionPool, searching first the Session context of the previously specified HttpServletRequest (if any), then the ServletContext (application context) of the servlet associated with that HttpServletRequest (if any), then the ConnectionPool global singleton (if any), returning null if no ConnectionPool is found in any of those places.

Returns:
The found ConnectionPool or null.

saveInSession

public void saveInSession(ConnectionPool pool)
Save the specified ConnectionPool in the Session to be found by future calls to find().

Parameters:
pool - The ConnectionPool.

saveInServletContext

public void saveInServletContext(ConnectionPool pool)
Save the specified ConnectionPool in the ServletContext to be found by future calls to find().

Parameters:
pool - The ConnectionPool.

saveAsGlobalSingleton

public void saveAsGlobalSingleton(ConnectionPool pool)
Save the specified ConnectionPool as the ConnectionPool global singleton, to be found by future calls to find(). Note: Since the ConnectionPool singleton is global, this affects all users of all ConnectionPool instances, not only users of ConnectionPoolFinder.

Parameters:
pool - The ConnectionPool.