com.is.util.sql
Class JDBCHelperPool

java.lang.Object
  |
  +--com.is.util.sql.JDBCHelperPool

public class JDBCHelperPool
extends java.lang.Object

Before anything else happens, do this:
JDBCHelperPool.createPool(
"XYZ_DB", // Name of the pool
JDBCHelperFactory.create(), // or however you create a JDBCHelper
5); // number of objects in the pool.

Later, when you need a JDBCHelper instance:
JDBCHelperPool.getPool("XYZ_DB").getJDBCHelper();
When done with the pool:
JDBCHelperPool.getPool("XYZ_DB").destroy();


Method Summary
static void createPool(java.lang.String poolName, JDBCHelper aJDBCHelper, int poolSize)
          This method must be called before a pool with this name can be retrieved.
 void destroy()
          Close the JDBCHelper objects and remove them from the stack.
static void destroyPool(java.lang.String poolName)
          This method must be called before a pool with this name can be retrieved.
static JDBCHelper getFrom(java.lang.String poolName)
          Return a JDBCHelper from the pool.
 JDBCHelper getJDBCHelper()
          Gets an object from the pool of available ones.
 int getMaxAttempts()
          Returns the maximum number of attempts that will be made trying to get a connection.
static JDBCHelperPool getPool(java.lang.String poolName)
          Return the pool with the given name.
 long getWaitTime()
          Returns the wait in milliseconds betweent attempts to get a conection
 void returnJDBCHelper(JDBCHelper aJDBCHelper)
          This method returns an object to the available pool and notifies any threads that are waiting for it.
 void setMaxAttempts(int value)
          Sets the number of attempts to try to get an object before failing.
 void setWaitTime(long value)
          Sets the waitTime in milliseconds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createPool

public static void createPool(java.lang.String poolName,
                              JDBCHelper aJDBCHelper,
                              int poolSize)
This method must be called before a pool with this name can be retrieved.
Parameters:
poolName - a value of type 'String'
aJDBCHelper - a value of type 'JDBCHelper'
poolSize - a value of type 'int'
See Also:
JDBCHelperPool.getInstance(poolName)

destroyPool

public static void destroyPool(java.lang.String poolName)
This method must be called before a pool with this name can be retrieved.
Parameters:
poolName - a value of type 'String'
aJDBCHelper - a value of type 'JDBCHelper'
poolSize - a value of type 'int'
See Also:
JDBCHelperPool.getInstance(poolName)

getPool

public static JDBCHelperPool getPool(java.lang.String poolName)
Return the pool with the given name. Null is returned if none is found.
Parameters:
poolName - a value of type 'String'
Returns:
a value of type 'JDBCHelperPool'

getFrom

public static JDBCHelper getFrom(java.lang.String poolName)
                          throws java.sql.SQLException
Return a JDBCHelper from the pool. This is a shortcut/convenience method for JDBCHelperPool.getPool("name").getJDBCHelper();
Parameters:
poolName - a value of type 'String'
Returns:
a value of type 'JDBCHelper'

destroy

public void destroy()
Close the JDBCHelper objects and remove them from the stack. Once this method is called, this instance can never be used again.

getJDBCHelper

public JDBCHelper getJDBCHelper()
                         throws java.sql.SQLException
Gets an object from the pool of available ones. If none are available, it sleeps for waitTime then tries again. It repeats that for the number of times specified in i_maxAttempts. NOTE: Once you are done with a JDBCHelper, you MUST return it to the available pool by calling the returnJDBCHelper() method. /
Returns:
a value of type 'JDBCHelper'
Throws:
java.sql.SQLException - if an object is not found after n attempts.

returnJDBCHelper

public void returnJDBCHelper(JDBCHelper aJDBCHelper)
This method returns an object to the available pool and notifies any threads that are waiting for it.

getMaxAttempts

public int getMaxAttempts()
Returns the maximum number of attempts that will be made trying to get a connection.

setMaxAttempts

public void setMaxAttempts(int value)
Sets the number of attempts to try to get an object before failing. This is the number of times to wait for a connection to be returned..when the pool is empty. Min = 1, Max = 10

getWaitTime

public long getWaitTime()
Returns the wait in milliseconds betweent attempts to get a conection

setWaitTime

public void setWaitTime(long value)
Sets the waitTime in milliseconds. Min = 0, Max = 10000