org.apache.torque.avalon
Class TorqueComponent

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.torque.avalon.TorqueComponent
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.activity.Startable, org.apache.avalon.framework.thread.ThreadSafe

public class TorqueComponent
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.activity.Initializable, org.apache.avalon.framework.context.Contextualizable, org.apache.avalon.framework.activity.Startable, org.apache.avalon.framework.thread.ThreadSafe

Avalon component for Torque.

Version:
$Id: TorqueComponent.java 239636 2005-08-24 12:38:09Z henning $
Author:
Martin Poeschl, Henning P. Schmiedehausen

Constructor Summary
  TorqueComponent()
          Creates a new instance.
protected TorqueComponent(TorqueInstance torqueInstance)
          Creates a new instance.
 
Method Summary
 void closeConnection(java.sql.Connection con)
          Closes a connection.
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
 void contextualize(org.apache.avalon.framework.context.Context context)
           
 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 initialize()
           
 boolean isInit()
          Determine whether Torque has already been initialized.
 void registerMapBuilder(java.lang.String className)
          Register a MapBuilder
 void start()
           
 void stop()
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TorqueComponent

public TorqueComponent()
Creates a new instance. Default constructor used by Avalon.


TorqueComponent

protected TorqueComponent(TorqueInstance torqueInstance)
Creates a new instance.

Parameters:
torqueInstance - The instance of the Torque core used by this component.
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(org.apache.avalon.framework.configuration.Configuration)

contextualize

public void contextualize(org.apache.avalon.framework.context.Context context)
                   throws org.apache.avalon.framework.context.ContextException
Specified by:
contextualize in interface org.apache.avalon.framework.context.Contextualizable
Throws:
org.apache.avalon.framework.context.ContextException
See Also:
Contextualizable

initialize

public void initialize()
                throws java.lang.Exception
Specified by:
initialize in interface org.apache.avalon.framework.activity.Initializable
Throws:
java.lang.Exception
See Also:
Initializable.initialize()

start

public void start()
Specified by:
start in interface org.apache.avalon.framework.activity.Startable
See Also:
Startable.start()

stop

public void stop()
Specified by:
stop in interface org.apache.avalon.framework.activity.Startable
See Also:
Startable.stop()

isInit

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

Returns:
true if Torque is already initialized

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

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-2006 Apache Software Foundation. All Rights Reserved.