org.apache.torque
Class Torque

java.lang.Object
  extended byorg.apache.torque.Torque

public class Torque
extends java.lang.Object

The implementation of Torque.

Version:
$Id: Torque.java,v 1.73 2002/11/28 18:52:02 mpoeschl Exp $
Author:
Daniel Rall, Magnús Þór Torfason, Jason van Zyl, Rafal Krzewski, Martin Poeschl, Henning P. Schmiedehausen, Kurt Schrader

Field Summary
private static java.util.Map adapterMap
          The cache of DB adapter keys
static java.lang.String CACHE_KEY
          property to determine whether caching is used.
private static org.apache.log4j.Category category
          The logging category.
private static org.apache.commons.configuration.Configuration configuration
          Torque-specific configuration.
static java.lang.String DATABASE_DEFAULT
          Name of property that specifies the default map builder and map.
private static java.util.Map dbMaps
          The global cache of database maps
private static java.lang.String DEFAULT_NAME
          A constant for default.
private static java.lang.String defaultDBName
          The db name that is specified as the default in the property file
private static java.util.Map dsFactoryMap
          The cache of DataSourceFactory's
private static boolean isInit
          flag to set to true once this class has been initialized
static java.lang.String MANAGER_PREFIX
          A prefix for Manager properties in TurbineResource.properties.
static java.lang.String MANAGER_SUFFIX
          A Service property determining its implementing class name .
protected static java.util.Map managers
          A repository of Manager instances.
private static java.util.List mapBuilders
          Store mapbuilder classnames for peers that have been referenced prior to Torque being initialized.
 
Constructor Summary
Torque()
           
 
Method Summary
static void closeConnection(java.sql.Connection con)
          Closes a connection.
 void configure(org.apache.commons.configuration.Configuration config)
          configure torque
protected static void configureLogging()
          Configure the logging for this subsystem.
 void dispose()
          Shuts down the service, Lifecycle style
static org.apache.commons.configuration.Configuration getConfiguration()
          Get the configuration for this component.
static java.sql.Connection getConnection()
          This method returns a Connection from the default pool.
static java.sql.Connection getConnection(java.lang.String name)
           
static java.sql.Connection getConnection(java.lang.String name, java.lang.String username, java.lang.String password)
          Deprecated. Database parameters should not be specified each time a Connection 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.
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.
static DB getDB(java.lang.String name)
          Returns database adapter for a specific connection pool.
static java.lang.String getDefaultDB()
          Returns the name of the default database.
static java.lang.String getDefaultMap()
          Deprecated. Use getDefaultDB() instead.
static AbstractBaseManager getManager(java.lang.String name)
          This method returns a Manager for the given name.
static AbstractBaseManager getManager(java.lang.String name, java.lang.String defaultClassName)
          This methods returns either the Manager from the configuration file, or the default one provided by the generated code.
static void init(org.apache.commons.configuration.Configuration c)
          Initialization of Torque with a properties file.
static void init(java.lang.String configFile)
          Initialization of Torque with a properties file.
private static void initAdapters(org.apache.commons.configuration.Configuration configuration)
           
private static DatabaseMap initDatabaseMap(java.lang.String name)
          Creates and initializes the mape for the named database.
private static void initDataSourceFactories(org.apache.commons.configuration.Configuration configuration)
           
 void initialize()
          initialize Torque
private static void initManager(java.lang.String name, java.lang.String className)
          Initialize a manager
protected static void initManagerMappings(org.apache.commons.configuration.Configuration configuration)
          Creates a mapping between classes and their manager classes.
static boolean isInit()
          Determine whether Torque has already been initialized.
protected static boolean isLoggingConfigured()
          Determine whether log4j has already been configured.
static void registerMapBuilder(java.lang.String className)
          Register a MapBuilder
static void setConfiguration(org.apache.commons.configuration.Configuration c)
          Sets the configuration for Torque and all dependencies.
private static void setupIdTable(DatabaseMap map)
          Setup IDBroker's table information within given database map.
static void shutdown()
          Shuts down the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATABASE_DEFAULT

public static final java.lang.String DATABASE_DEFAULT
Name of property that specifies the default map builder and map.

See Also:
Constant Field Values

DEFAULT_NAME

private static final java.lang.String DEFAULT_NAME
A constant for default.

See Also:
Constant Field Values

MANAGER_PREFIX

public static final java.lang.String MANAGER_PREFIX
A prefix for Manager properties in TurbineResource.properties.

See Also:
Constant Field Values

MANAGER_SUFFIX

public static final java.lang.String MANAGER_SUFFIX
A Service property determining its implementing class name .

See Also:
Constant Field Values

CACHE_KEY

public static final java.lang.String CACHE_KEY
property to determine whether caching is used.

See Also:
Constant Field Values

defaultDBName

private static java.lang.String defaultDBName
The db name that is specified as the default in the property file


dbMaps

private static java.util.Map dbMaps
The global cache of database maps


dsFactoryMap

private static java.util.Map dsFactoryMap
The cache of DataSourceFactory's


adapterMap

private static java.util.Map adapterMap
The cache of DB adapter keys


managers

protected static java.util.Map managers
A repository of Manager instances.


category

private static org.apache.log4j.Category category
The logging category.


configuration

private static org.apache.commons.configuration.Configuration configuration
Torque-specific configuration.


isInit

private static boolean isInit
flag to set to true once this class has been initialized


mapBuilders

private static java.util.List mapBuilders
Store mapbuilder classnames for peers that have been referenced prior to Torque being initialized. This can happen if torque om/peer objects are serialized then unserialized prior to Torque being reinitialized. This condition exists in a normal catalina restart.

Constructor Detail

Torque

public Torque()
Method Detail

initialize

public void initialize()
                throws TorqueException
initialize Torque

Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
See Also:
org.apache.stratum.lifecycle.Initializable

initAdapters

private static final void initAdapters(org.apache.commons.configuration.Configuration configuration)
                                throws TorqueException
Parameters:
configuration - the Configuration representing the properties file
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

initDataSourceFactories

private static void initDataSourceFactories(org.apache.commons.configuration.Configuration configuration)
                                     throws TorqueException
Parameters:
configuration - the Configuration representing the properties file
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

configure

public void configure(org.apache.commons.configuration.Configuration config)
               throws TorqueException
configure torque

Parameters:
config - Configuration
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
See Also:
org.apache.stratum.lifecycle.Configurable

init

public static void init(java.lang.String configFile)
                 throws TorqueException
Initialization of Torque with a properties file.

Parameters:
configFile - The absolute path to the configuration file.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

init

public static void init(org.apache.commons.configuration.Configuration c)
                 throws TorqueException
Initialization of Torque with a properties file.

Parameters:
c - The Torque configuration.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

initManagerMappings

protected static void initManagerMappings(org.apache.commons.configuration.Configuration configuration)
                                   throws TorqueException
Creates a mapping between classes and their manager classes. The mapping is built according to settings present in TurbineResources.properties. The entries should have the following form:
 torque.managed_class.com.mycompany.Myclass.manager= \
          com.mycompany.MyManagerImpl
 services.managed_class.com.mycompany.Myotherclass.manager= \
          com.mycompany.MyOtherManagerImpl
 

Generic ServiceBroker provides no Services.

Parameters:
configuration - the Configuration representing the properties file
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

initManager

private static void initManager(java.lang.String name,
                                java.lang.String className)
                         throws TorqueException
Initialize a manager

Parameters:
name - name of the manager
className - name of the manager class
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

isInit

public static boolean isInit()
Determine whether Torque has already been initialized.

Returns:
true if Torque is already initialized

setConfiguration

public static void setConfiguration(org.apache.commons.configuration.Configuration c)
Sets the configuration for Torque and all dependencies.

Parameters:
c - the Configuration

getConfiguration

public static org.apache.commons.configuration.Configuration getConfiguration()
Get the configuration for this component.

Returns:
the Configuration

configureLogging

protected static void configureLogging()
Configure the logging for this subsystem.


isLoggingConfigured

protected static boolean isLoggingConfigured()
Determine whether log4j has already been configured.

Returns:
boolean Whether log4j is configured.

getManager

public static AbstractBaseManager getManager(java.lang.String name)
This method returns a Manager for the given name.

Parameters:
name - name of the manager
Returns:
a Manager

getManager

public static AbstractBaseManager getManager(java.lang.String name,
                                             java.lang.String defaultClassName)
This methods returns either the Manager from the configuration file, or the default one provided by the generated code.

Parameters:
name - name of the manager
defaultClassName - the class to use if name has not been configured
Returns:
a Manager

dispose

public void dispose()
Shuts down the service, Lifecycle style


shutdown

public static void shutdown()
Shuts down the service. This method halts the IDBroker's daemon thread in all of the DatabaseMap's.


getDatabaseMap

public static DatabaseMap getDatabaseMap()
                                  throws TorqueException
Returns the default database map information.

Returns:
A DatabaseMap.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getDatabaseMap

public static DatabaseMap getDatabaseMap(java.lang.String name)
                                  throws TorqueException
Returns the database map information. Name relates to the name of the connection pool to associate with the map.

Parameters:
name - The name of the database corresponding to the DatabaseMap to retrieve.
Returns:
The named DatabaseMap.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

initDatabaseMap

private static final DatabaseMap initDatabaseMap(java.lang.String name)
                                          throws TorqueException
Creates and initializes the mape for the named database. Assumes that dbMaps member is sync'd.

Parameters:
name - The name of the database to map.
Returns:
The desired map.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

registerMapBuilder

public static void registerMapBuilder(java.lang.String className)
Register a MapBuilder

Parameters:
className - the MapBuilder

getDatabaseProperty

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.

Parameters:
db - The name of the database whose property to get.
prop - The name of the property to get.
Returns:
The property's value.

setupIdTable

private static final void setupIdTable(DatabaseMap map)
Setup IDBroker's table information within given database map. This method should be called on all new database map to ensure that IDBroker functionality is available in all databases used by the application.

Parameters:
map - the DataBaseMap to setup.

getConnection

public static java.sql.Connection getConnection()
                                         throws TorqueException,
                                                java.sql.SQLException,
                                                javax.naming.NamingException
This method returns a Connection from the default pool.

Returns:
The requested connection.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
java.sql.SQLException - never thrown
javax.naming.NamingException - never thrown

getConnection

public static java.sql.Connection getConnection(java.lang.String name,
                                                java.lang.String username,
                                                java.lang.String password)
                                         throws TorqueException
Deprecated. Database parameters should not be specified each time a Connection is fetched from the service.

This method returns a Connecton using the given parameters.

Parameters:
name - The database name.
username - The name of the database user.
password - The password of the database user.
Returns:
A Connection.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getConnection

public static java.sql.Connection getConnection(java.lang.String name)
                                         throws TorqueException
Parameters:
name - The database name.
Returns:
a database connection
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getDB

public static DB getDB(java.lang.String name)
                throws TorqueException
Returns database adapter for a specific connection pool.

Parameters:
name - A pool name.
Returns:
The corresponding database adapter.
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

getDefaultDB

public static java.lang.String getDefaultDB()
Returns the name of the default database.

Returns:
name of the default DB

getDefaultMap

public static java.lang.String getDefaultMap()
Deprecated. Use getDefaultDB() instead.

Returns:
name of the default Map

closeConnection

public static void closeConnection(java.sql.Connection con)
Closes a connection.

Parameters:
con - A Connection to close.


Copyright © 1999-2003 Apache Software Foundation. All Rights Reserved.