org.locomotive.server
Class DBConnectionPool

java.lang.Object
  |
  +--org.locomotive.util.ObjectPool
        |
        +--org.locomotive.server.DBConnectionPool

public class DBConnectionPool
extends ObjectPool
implements LocomotiveService

Manages a pool of JDBC connections. Will broker the connections out until there are no more to give out, whereupon it will either attempt to start a new connection and send that out, or block if the maximum number of connections are already open until a connection is available.


Inner classes inherited from class org.locomotive.util.ObjectPool
ObjectPool.PoolEntry
 
Fields inherited from class org.locomotive.util.ObjectPool
classname, current_open, isRunning, log, log_level, max_open, min_open, pe_in_use_hash, pe_stack, poolentry_id_sequence
 
Constructor Summary
DBConnectionPool()
          Default constructor for the connection pool.
DBConnectionPool(java.lang.String driver_classname_in, java.lang.String url_in, java.lang.String username_in, java.lang.String password_in, int min_open_in, int max_open_in, Log l)
          creates a new pool, and fills it with the specified minumum number of database connections.
 
Method Summary
 java.lang.Object createNewObject()
          creates a new database connection
 void destroyObject(java.lang.Object obj)
          calls connection.close() on the object.
 java.sql.Connection getConnection()
          gets a JDBC Connection object from the pool.
static int getDefaultLogLevel()
           
 java.lang.String getDriverClassName()
          Get name of the driver class for this connection pool.
 java.lang.String getUrl()
          Get the url to the database in this connection pool.
 java.lang.String getUserName()
          Get the database username to use for connections in this pool.
 void returnToPool(java.lang.Object obj)
          returns this connection to the pool, allowing other threads to have access to it.
 void setDriverClassName(java.lang.String driverClassName)
          Set the driver class name for this connection pool.
 void setPassword(java.lang.String password)
          Set the password for the username.
 void setUrl(java.lang.String url)
          Set the url to the database in this connection pool.
 void setUserName(java.lang.String userName)
          Set the database username to use for connections in this pool.
 void startService()
          Start the DBConnectionPool service.
 
Methods inherited from class org.locomotive.util.ObjectPool
closeCurrentPoolMembers, getLogLevel, getMaxSize, getMinSize, getNextId, getObject, getPoolSize, initialize, isRunning, log, logError, setLog, setLogLevel, setMaxSize, setMinSize, stopService, wipeFromPool
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBConnectionPool

public DBConnectionPool(java.lang.String driver_classname_in,
                        java.lang.String url_in,
                        java.lang.String username_in,
                        java.lang.String password_in,
                        int min_open_in,
                        int max_open_in,
                        Log l)
                 throws InitializationException
creates a new pool, and fills it with the specified minumum number of database connections.
Parameters:
driver_classname_in - the class name for the JDBC driver to use.
url_in - the URL to use with the driver. See the driver documanetation for more details.
username_in - the username to connect to the database with
password_in - the user's password
min_open_in - the minumum number of connections to remain in the pool
max_open_in - the maximum number of connections to maintain at any given time
l - the log to use to log any major events
id - the unique id for this pool- pass -1 to not use an id

DBConnectionPool

public DBConnectionPool()
Default constructor for the connection pool.
Method Detail

getDefaultLogLevel

public static int getDefaultLogLevel()

createNewObject

public java.lang.Object createNewObject()
                                 throws InitializationException
creates a new database connection
Overrides:
createNewObject in class ObjectPool

destroyObject

public void destroyObject(java.lang.Object obj)
calls connection.close() on the object.
Overrides:
destroyObject in class ObjectPool

getConnection

public java.sql.Connection getConnection()
gets a JDBC Connection object from the pool. If the pool is currently empty (meaning all connections are in use by other threads) and the current total is less than the configured maximum, a new connection is created and returned. Otherwise this method blocks until a connection is released by another thread.

returnToPool

public void returnToPool(java.lang.Object obj)
returns this connection to the pool, allowing other threads to have access to it. This should be called when the calling thread no longer needs the connection.
Overrides:
returnToPool in class ObjectPool

startService

public void startService()
                  throws ServiceException
Start the DBConnectionPool service.
Specified by:
startService in interface LocomotiveService
Overrides:
startService in class ObjectPool
Throws:
ServiceException - if the connection pool not could be started.

getDriverClassName

public java.lang.String getDriverClassName()
Get name of the driver class for this connection pool.
Returns:
Returns name of the driver class for this connection pool.

setDriverClassName

public void setDriverClassName(java.lang.String driverClassName)
Set the driver class name for this connection pool.
Parameters:
driverClassName - The name of the driver class for this connection pool.

getUrl

public java.lang.String getUrl()
Get the url to the database in this connection pool.
Returns:
Return the url to the database in this connection pool.

setUrl

public void setUrl(java.lang.String url)
Set the url to the database in this connection pool.
Parameters:
url - the url to the database in this connection pool.

getUserName

public java.lang.String getUserName()
Get the database username to use for connections in this pool.
Returns:
Returns the database username to use for connections in this pool.

setUserName

public void setUserName(java.lang.String userName)
Set the database username to use for connections in this pool.
Parameters:
userName - The database username.

setPassword

public void setPassword(java.lang.String password)
Set the password for the username.
Parameters:
password - The password for the username.