org.apache.torque
Class TorqueInstance

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

public class TorqueInstance
extends java.lang.Object

The core of Torque's implementation. Both the classic Torque static wrapper and the TorqueComponent Avalon implementation leverage this class.

Version:
$Id: TorqueInstance.java,v 1.5.2.5 2004/08/23 02:54:16 seade Exp $
Author:
Daniel Rall, Magn?s ??r Torfason, Jason van Zyl, Rafal Krzewski, Martin Poeschl, Henning P. Schmiedehausen, Kurt Schrader

Constructor Summary
TorqueInstance()
          Creates a new instance with default configuration.
 
Method Summary
 void closeConnection(java.sql.Connection con)
          Closes a connection.
 org.apache.commons.configuration.Configuration getConfiguration()
          Get the configuration for this component.
 java.sql.Connection getConnection()
          This method returns a Connection from the default pool.
 java.sql.Connection getConnection(java.lang.String name)
           
 java.sql.Connection getConnection(java.lang.String name, java.lang.String username, java.lang.String password)
          This method returns a Connecton using the given parameters.
 DatabaseMap getDatabaseMap()
          Returns the default database map information.
 DatabaseMap getDatabaseMap(java.lang.String name)
          Returns the database map information.
 DB getDB(java.lang.String name)
          Returns database adapter for a specific connection pool.
 java.lang.String getDefaultDB()
          Returns the name of the default database.
 AbstractBaseManager getManager(java.lang.String name)
          This method returns a Manager for the given name.
 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.
 void init(org.apache.commons.configuration.Configuration conf)
          Initialization of Torque with a properties file.
 void init(java.lang.String configFile)
          Initialization of Torque with a properties file.
protected  void initManagerMappings(org.apache.commons.configuration.Configuration conf)
          Creates a mapping between classes and their manager classes.
 boolean isInit()
          Determine whether Torque has already been initialized.
 void registerMapBuilder(java.lang.String className)
          Register a MapBuilder
 void setConfiguration(org.apache.commons.configuration.Configuration conf)
          Sets the configuration for Torque and all dependencies.
 void shutdown()
          Shuts down the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TorqueInstance

public TorqueInstance()
Creates a new instance with default configuration.

See Also:
#resetConfiguration()
Method Detail

init

public 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 void init(org.apache.commons.configuration.Configuration conf)
          throws TorqueException
Initialization of Torque with a properties file.

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

initManagerMappings

protected void initManagerMappings(org.apache.commons.configuration.Configuration conf)
                            throws TorqueException
Creates a mapping between classes and their manager classes. The mapping is built according to settings present in properties file. 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:
conf - the Configuration representing the properties file
Throws:
TorqueException - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

isInit

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

Returns:
true if Torque is already initialized

setConfiguration

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

Parameters:
conf - the Configuration

getConfiguration

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

Returns:
the Configuration

getManager

public 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 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

shutdown

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


getDatabaseMap

public 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 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.

registerMapBuilder

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

Parameters:
className - the MapBuilder

getConnection

public java.sql.Connection getConnection()
                                  throws TorqueException
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.

getConnection

public 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.

getConnection

public java.sql.Connection getConnection(java.lang.String name,
                                         java.lang.String username,
                                         java.lang.String password)
                                  throws TorqueException
This method returns a Connecton using the given parameters. You should only use this method if you need user based access to the database!

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.

getDB

public 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 java.lang.String getDefaultDB()
Returns the name of the default database.

Returns:
name of the default DB

closeConnection

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

Parameters:
con - A Connection to close.


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