|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.turbine.services.db.TurbineDB
This class provides a common front end to all database - related
services in Turbine. Currently these are PoolBrokerService
and
MapBrokerService
. This class contains static methods that you
can call to access the methods of system's configured service
implementations.
Assuming that your TurbineResources.properties file is setup correctly, the sample code below demonstrates the right way to get and release a database connection (exception handling is application dependent):
DBConnection dbConn = null;
try
{
dbConn = TurbineDB.getConnection();
// Do something with the connection here...
}
catch (Exception e)
{
// Either from obtaining the connection or from your application code.
}
finally
{
try
{
TurbineDB.releaseConnection(dbConn);
}
catch (Exception e)
{
// Error releasing database connection back to pool.
}
}
Constructor Summary | |
TurbineDB()
|
Method Summary | |
static DBConnection |
getConnection()
This method returns a DBConnection from the default pool. |
static DBConnection |
getConnection(java.lang.String name)
This method returns a DBConnection from the pool with the specified name. |
static 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. |
static DatabaseMap |
getDatabaseMap()
Returns the default database map information. |
static DatabaseMap |
getDatabaseMap(java.lang.String name)
Returns the database map information. |
static DB |
getDB()
Returns the database adapter for the default connection pool. |
static DB |
getDB(java.lang.String name)
Returns database adapter for a specific connection pool. |
static java.lang.String |
getDefaultDB()
Returns the pool name for the default database. |
static java.lang.String |
getDefaultMap()
Returns the map name for the default database. |
private static MapBrokerService |
getMapBroker()
Returns the system's configured MapBrokerService implementation. |
private static PoolBrokerService |
getPoolBroker()
Returns the system's configured PoolBrokerService implementation. |
static 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. |
static void |
releaseConnection(DBConnection dbconn)
Release a connection back to the database pool. |
Methods inherited from class java.lang.Object |
|
Constructor Detail |
public TurbineDB()
Method Detail |
public static java.lang.String getDefaultMap()
public static DatabaseMap getDatabaseMap() throws TurbineException
TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static DatabaseMap getDatabaseMap(java.lang.String name) throws TurbineException
name
- The name of the DatabaseMap
to
retrieve.DatabaseMap
.TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static java.lang.String getDefaultDB()
public static DBConnection getConnection() throws java.lang.Exception
TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static DBConnection getConnection(java.lang.String name) throws java.lang.Exception
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
name
- The name of the pool to get a connection from.TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static DBConnection getConnection(java.lang.String driver, java.lang.String url, java.lang.String username, java.lang.String password) throws java.lang.Exception
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.TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static void releaseConnection(DBConnection dbconn) throws java.lang.Exception
TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.java.lang.Exception
- A generic exception.public static 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
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.TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static DB getDB() throws java.lang.Exception
TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.public static DB getDB(java.lang.String name) throws java.lang.Exception
name
- A pool name.TurbineException
- Any exceptions caught during processing will be
rethrown wrapped into a TurbineException.private static MapBrokerService getMapBroker()
private static PoolBrokerService getPoolBroker()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |