com.infoengine.jdbc
Class ResourcePool

java.lang.Object
  extended bycom.infoengine.jdbc.ResourcePool
All Implemented Interfaces:
PoolProcessor

public class ResourcePool
extends Object
implements PoolProcessor

ResourcePool class is the super class of your sesssion pooling or connection pooling class that provides the basic functionalities for you to implement the connection pooling. You may need to modify this file or rewrite the code to fit your implementation requirement.


Field Summary
protected  Hashtable available
           
protected  int currentCount
           
private  boolean dp
           
private  int errCode
           
(package private) static int ERROR_CREATE_CONNECTION
           
(package private) static int ERROR_INITIALIZE_POOL
           
(package private) static int ERROR_NO_AVAILABLE_CONNECTION
           
(package private) static int ERROR_NO_DRIVER_INSTALLED
           
protected  int initCount
           
private  String jdbcDriver
           
protected  com.infoengine.log.LogWriter logWriter
           
protected  int maximumCount
           
protected  String serviceName
           
protected  Hashtable unavailable
           
protected  String url
           
 
Constructor Summary
ResourcePool()
          Default constructor.
ResourcePool(String svcName, String urlink, String users, String passwds, int initCount, int maxCount)
          Constructor for the pooling.
 
Method Summary
protected  Connection addConnection(String user, String paswd)
          This method create a connection with credential pair user/paswd and then add it to the connection/session pool.
 void closeConnection(Connection connection)
           
 Connection createConnection(String url, String user, String paswd)
           
 Hashtable getAvailableData()
           
 int getAvailableSize()
           
 Connection getConnection(String user, String paswd)
          This method gets a connection from the available pool if there is one, or checks for the idle connection from the other user to find one available before creating a new connection.
 int getErrorCode()
           
 int getMaxCount()
           
 String getServiceName()
           
 Hashtable getUnavailableData()
           
 int getUnavailableSize()
           
private  void initPool(String users, String passwds)
          This method initialize the connection/session pooling.
 void putConnection(String user, String paswd, Connection conn)
          This method add a connection to the connection/session pool.
 void removeConnection(Connection conn)
          This method remove a connection from the unavailable pool.
 void removeConnection(String user, String pwd, Connection conn)
          This method remove a connection from the unavailable pool.
 void returnConnection(Connection conn)
          This method return a connection from the unavailable pool to the available pool.
 void returnConnection(String user, String pwd, Connection conn)
          This method return a connection from the unavailable pool to the available pool.
protected  void setAvailable(Hashtable a)
           
protected  void setCurrentCount(int c)
           
protected  void setErrorCode(int e)
           
protected  void setInitCount(int initCount)
           
protected  void setLogWriter(com.infoengine.log.LogWriter log)
           
protected  void setMaxCount(int maxCount)
           
protected  void setServiceName(String svcName)
           
protected  void setUnavailable(Hashtable ua)
           
private  String userKey(String user, String passwd)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maximumCount

protected int maximumCount

currentCount

protected int currentCount

initCount

protected int initCount

available

protected Hashtable available

unavailable

protected Hashtable unavailable

serviceName

protected String serviceName

logWriter

protected com.infoengine.log.LogWriter logWriter

url

protected String url

jdbcDriver

private String jdbcDriver

dp

private boolean dp

errCode

private int errCode

ERROR_CREATE_CONNECTION

static final int ERROR_CREATE_CONNECTION
See Also:
Constant Field Values

ERROR_NO_AVAILABLE_CONNECTION

static final int ERROR_NO_AVAILABLE_CONNECTION
See Also:
Constant Field Values

ERROR_INITIALIZE_POOL

static final int ERROR_INITIALIZE_POOL
See Also:
Constant Field Values

ERROR_NO_DRIVER_INSTALLED

static final int ERROR_NO_DRIVER_INSTALLED
See Also:
Constant Field Values
Constructor Detail

ResourcePool

public ResourcePool()
Default constructor.


ResourcePool

public ResourcePool(String svcName,
                    String urlink,
                    String users,
                    String passwds,
                    int initCount,
                    int maxCount)
             throws IEException
Constructor for the pooling. This method will be invoked by the subclass to necessary resources for the implementation.

Parameters:
svcName - The service name passed from the I*E server as the adapter instance.
urlink - The url that is used to connect to the back end application.
users - The user id(s), if more than one, they are separated by '+'.
passwds - The corresponding password(s), in the same order defined by the user(s) that are separated by '+'.
maxCount - The maximum number of connections allowed for the pool.
Method Detail

createConnection

public Connection createConnection(String url,
                                   String user,
                                   String paswd)
                            throws IEException
Specified by:
createConnection in interface PoolProcessor
Throws:
IEException

closeConnection

public void closeConnection(Connection connection)
                     throws IEException
Specified by:
closeConnection in interface PoolProcessor
Throws:
IEException

initPool

private void initPool(String users,
                      String passwds)
               throws IEException
This method initialize the connection/session pooling. It takes a set of user names and passwords separated by either '+' and create connections from these credentials before adding them to the pool.

Parameters:
users - The user id(s), if more than one, they are separated by '+'.
passwds - The corresponding password(s), if more than one, separated by '+'.
Throws:
IEException

addConnection

protected Connection addConnection(String user,
                                   String paswd)
                            throws IEException
This method create a connection with credential pair user/paswd and then add it to the connection/session pool.

Parameters:
user - A single uesr id.
paswd - The corresponding password.
Returns:
The connection if added to the pool successfully, or null if not.
Throws:
IEException

putConnection

public void putConnection(String user,
                          String paswd,
                          Connection conn)
This method add a connection to the connection/session pool. It validates the available and unavailable pool, then add the connection based on the credential pair.

Parameters:
user - The single user id.
paswd - The corresponding password.
conn - The connection object to be added with the above credentials.

getConnection

public Connection getConnection(String user,
                                String paswd)
                         throws IEException
This method gets a connection from the available pool if there is one, or checks for the idle connection from the other user to find one available before creating a new connection. It will throw exceptions in the case where there is no available connection and the maximum count is also reached.

Parameters:
user - The single user id.
paswd - The corresponding password.
Returns:
The connection object associated with the above credentials.
Throws:
IEException

returnConnection

public void returnConnection(String user,
                             String pwd,
                             Connection conn)
                      throws IEException
This method return a connection from the unavailable pool to the available pool. It is called after the task is executed and the connection is available for the next task or for other user to grap.

Parameters:
user - The single user id.
pwd - The corresponding password.
conn - The connection associated with the above credentials to be returned to the available pool for reuse.
Throws:
IEException

returnConnection

public void returnConnection(Connection conn)
                      throws IEException
This method return a connection from the unavailable pool to the available pool. It is called after the task is executed and the connection is available for the next task or for other user to grap.

Parameters:
conn - The connection to be returned to the available pool for reuse.
Throws:
IEException

removeConnection

public void removeConnection(String user,
                             String pwd,
                             Connection conn)
                      throws IEException
This method remove a connection from the unavailable pool.

Parameters:
user - The single user id.
pwd - The corresponding password.
conn - The connection associated with the above credentials to be returned to the available pool for reuse.
Throws:
IEException

removeConnection

public void removeConnection(Connection conn)
                      throws IEException
This method remove a connection from the unavailable pool.

Parameters:
conn - The connection to be returned to the available pool for reuse.
Throws:
IEException

getMaxCount

public int getMaxCount()

getServiceName

public String getServiceName()

getUnavailableSize

public int getUnavailableSize()

getAvailableSize

public int getAvailableSize()

getAvailableData

public Hashtable getAvailableData()

getUnavailableData

public Hashtable getUnavailableData()

getErrorCode

public int getErrorCode()

userKey

private String userKey(String user,
                       String passwd)

setMaxCount

protected void setMaxCount(int maxCount)

setInitCount

protected void setInitCount(int initCount)

setServiceName

protected void setServiceName(String svcName)

setLogWriter

protected void setLogWriter(com.infoengine.log.LogWriter log)

setUnavailable

protected void setUnavailable(Hashtable ua)

setAvailable

protected void setAvailable(Hashtable a)

setCurrentCount

protected void setCurrentCount(int c)

setErrorCode

protected void setErrorCode(int e)