org.apache.turbine.services.db
Class TurbinePoolBrokerService

java.lang.Object
  |
  +--org.apache.turbine.services.BaseInitable
        |
        +--org.apache.turbine.services.BaseService
              |
              +--org.apache.turbine.services.db.TurbinePoolBrokerService
All Implemented Interfaces:
Initable, PoolBrokerService, Service

public class TurbinePoolBrokerService
extends BaseService
implements PoolBrokerService

Turbine's default implementation of PoolBrokerService.

Version:
$Id: TurbinePoolBrokerService.java,v 1.3 2002/03/13 19:43:35 mpoeschl Exp $
Author:
Frank Y. Kim, Brett McLaughlin, Greg Ritter, Daniel Rall, Magnús Þór Torfason, Jason van Zyl, Rafal Krzewski

Inner Class Summary
protected  class TurbinePoolBrokerService.Monitor
          This inner class monitors the PoolBrokerService.
 
Field Summary
static java.lang.String DEFAULT
          Name of the default connection pool.
private  java.lang.String defaultPool
          Default database pool
private  java.util.Map pools
          The various connection pools this broker contains.
 
Fields inherited from class org.apache.turbine.services.BaseService
configuration, name, properties, serviceBroker
 
Fields inherited from class org.apache.turbine.services.BaseInitable
initableBroker, isInitialized
 
Fields inherited from interface org.apache.turbine.services.db.PoolBrokerService
DEFAULT_POOL, SERVICE_NAME
 
Constructor Summary
TurbinePoolBrokerService()
           
 
Method Summary
 DBConnection getConnection()
          This method returns a DBConnection from the default pool.
 DBConnection getConnection(java.lang.String name)
          This method returns a DBConnection from the pool with the specified name.
 DBConnection getConnection(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
          Deprecated. Database parameters should not be specified each time a DBConnection is fetched from the service.
private static java.lang.String getDatabaseProperty(java.lang.String db, java.lang.String prop)
          Returns the specified property of the given database, or the empty string if no value is set for the property.
 DB getDB()
          Returns the database adapter for the default connection pool.
 DB getDB(java.lang.String name)
          Returns database adapter for a specific connection pool.
 java.lang.String getDefaultDB()
          Return the default pool.
private  ConnectionPool getPool()
          This method returns the default pool.
private  ConnectionPool getPool(java.lang.String name)
          This method returns a pool with the specified name.
private  java.lang.String getProperty(java.lang.String db, java.lang.String prop)
          Returns the string for the specified property of the given database.
 void init()
          Initialize the connection pool broker.
 void registerPool(java.lang.String name, java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password)
          This method registers a new pool using the given parameters.
 void registerPool(java.lang.String name, java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password, int maxCons, long expiryTime)
          This thread-safe method registers a new pool using the given parameters.
 void releaseConnection(DBConnection dbconn)
          Release a connection back to the database pool.
 void shutdown()
          Release the database connections for all pools on service shutdown.
 
Methods inherited from class org.apache.turbine.services.BaseService
getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker
 
Methods inherited from class org.apache.turbine.services.BaseInitable
getInit, getInitableBroker, init, setInit, setInitableBroker
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 
Methods inherited from interface org.apache.turbine.services.Service
getConfiguration, getName, getProperties, setName, setServiceBroker
 
Methods inherited from interface org.apache.turbine.services.Initable
getInit, init, setInitableBroker
 

Field Detail

DEFAULT

public static final java.lang.String DEFAULT
Name of the default connection pool.

defaultPool

private java.lang.String defaultPool
Default database pool

pools

private java.util.Map pools
The various connection pools this broker contains. Keyed by database URL.
Constructor Detail

TurbinePoolBrokerService

public TurbinePoolBrokerService()
Method Detail

init

public void init()
Initialize the connection pool broker.
Specified by:
init in interface Initable
Overrides:
init in class BaseInitable
Following copied from interface: org.apache.turbine.services.Initable
Throws:
InitializationException, - if initialization of this class was not successful.

getDefaultDB

public java.lang.String getDefaultDB()
Return the default pool.
Specified by:
getDefaultDB in interface PoolBrokerService

shutdown

public void shutdown()
Release the database connections for all pools on service shutdown.
Specified by:
shutdown in interface Initable
Overrides:
shutdown in class BaseInitable

getConnection

public DBConnection getConnection()
                           throws java.lang.Exception
This method returns a DBConnection from the default pool.
Specified by:
getConnection in interface PoolBrokerService
Returns:
The requested connection.
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

getConnection

public DBConnection getConnection(java.lang.String name)
                           throws java.lang.Exception
This method returns a DBConnection from the pool with the specified name. The pool must either have been registered with the registerPool(String,String,String,String,String) method, or be specified in the property file using the following syntax:
 database.[name].driver
 database.[name].url
 database.[name].username
 database.[name].password
 
Specified by:
getConnection in interface PoolBrokerService
Parameters:
name - The name of the pool to get a connection from.
Returns:
The requested connection.
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

getConnection

public DBConnection getConnection(java.lang.String driver,
                                  java.lang.String url,
                                  java.lang.String username,
                                  java.lang.String password)
                           throws java.lang.Exception
Deprecated. Database parameters should not be specified each time a DBConnection is fetched from the service.

This method returns a DBConnecton using the given parameters.
Specified by:
getConnection in interface PoolBrokerService
Parameters:
driver - The fully-qualified name of the JDBC driver to use.
url - The URL of the database from which the connection is desired.
username - The name of the database user.
password - The password of the database user.
Returns:
A DBConnection.
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

releaseConnection

public void releaseConnection(DBConnection dbconn)
                       throws java.lang.Exception
Release a connection back to the database pool. null references are ignored.
Specified by:
releaseConnection in interface PoolBrokerService
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.
java.lang.Exception - A generic exception.

registerPool

public void registerPool(java.lang.String name,
                         java.lang.String driver,
                         java.lang.String url,
                         java.lang.String username,
                         java.lang.String password)
                  throws java.lang.Exception
This method registers a new pool using the given parameters.
Specified by:
registerPool in interface PoolBrokerService
Parameters:
name - The name of the pool to register.
driver - The fully-qualified name of the JDBC driver to use.
url - The URL of the database to use.
username - The name of the database user.
password - The password of the database user.
Throws:
java.lang.Exception - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

registerPool

public void registerPool(java.lang.String name,
                         java.lang.String driver,
                         java.lang.String url,
                         java.lang.String username,
                         java.lang.String password,
                         int maxCons,
                         long expiryTime)
                  throws java.lang.Exception
This thread-safe method registers a new pool using the given parameters.
Parameters:
name - The name of the pool to register.
driver - The fully-qualified name of the JDBC driver to use.
url - The URL of the database to use.
username - The name of the database user.
password - The password of the database user.
Throws:
java.lang.Exception - A generic exception.

getDB

public DB getDB()
         throws java.lang.Exception
Returns the database adapter for the default connection pool.
Specified by:
getDB in interface PoolBrokerService
Returns:
The database adapter.
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

getDB

public DB getDB(java.lang.String name)
         throws java.lang.Exception
Returns database adapter for a specific connection pool.
Specified by:
getDB in interface PoolBrokerService
Parameters:
name - A pool name.
Returns:
The corresponding database adapter.
Throws:
TurbineException - Any exceptions caught during processing will be rethrown wrapped into a TurbineException.

getPool

private ConnectionPool getPool()
                        throws java.lang.Exception
This method returns the default pool.
Returns:
The default pool.
Throws:
java.lang.Exception - A generic exception.

getPool

private ConnectionPool getPool(java.lang.String name)
                        throws java.lang.Exception
This method returns a pool with the specified name. The pool must either have been registered with the registerPool(String,String,String,String,String) methd, or be specified in the TurbineResources properties. This method is used interanlly by the service.
Parameters:
name - The name of the pool to get.
Returns:
The requested pool.
Throws:
java.lang.Exception - A generic exception.

getDatabaseProperty

private static final java.lang.String getDatabaseProperty(java.lang.String db,
                                                          java.lang.String prop)
Returns the specified property of the given database, or the empty string if no value is set for the property.
Parameters:
db - The name of the database whose property to get.
prop - The name of the property to get.
Returns:
The property's value.

getProperty

private java.lang.String getProperty(java.lang.String db,
                                     java.lang.String prop)
Returns the string for the specified property of the given database.
Parameters:
db - The name of the database whose property to get.
prop - The name of the property to get.
Returns:
The string of the property.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.