org.apache.torque.avalon

## Interface Torque

- All Superinterfaces:
    org.apache.avalon.framework.component.Component
  All Known Implementing Classes:
    TorqueComponent

      public interface Torque
      extends org.apache.avalon.framework.component.Component

  Avalon role interface for Torque.
  Version:
    $Id: Torque.java 1867515 2019-09-25 15:02:03Z gk $
  Author:
    Henning P. Schmiedehausen, Thomas Vandahl

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ROLE` The avalon role.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `closeConnection(Connection con)` Closes a connection.
    `Adapter` | `getAdapter(String name)` Returns database adapter for a specific connection pool.
    `org.apache.commons.configuration2.Configuration` | `getConfiguration()` Get the configuration for this component.
    `Connection` | `getConnection()` This method returns a Connection from the default pool.
    `Connection` | `getConnection(String name)`
    `Connection` | `getConnection(String name, String username, String password)` This method returns a Connecton using the given parameters.
    `Database` | `getDatabase(String databaseName)` Returns the database for the key `databaseName`.
    `DatabaseMap` | `getDatabaseMap()` Returns the default database map information.
    `DatabaseMap` | `getDatabaseMap(String name)` Returns the database map information.
    `Map<String,Database>` | `getDatabases()` Returns a Map containing all Databases registered to Torque.
    `String` | `getDefaultDB()` Returns the name of the default database.
    `<T extends AbstractBaseManager<? extends Persistent>> T` | `getManager(String name)` This method returns a Manager for the given name.
    `<T extends AbstractBaseManager<? extends Persistent>> T` | `getManager(String name, String defaultClassName)` This methods returns either the Manager from the configuration file, or the default one provided by the generated code.
    `Database` | `getOrCreateDatabase(String databaseName)` Returns the database for the key `databaseName`.
    `String` | `getSchema(String name)` This method returns the current schema for a database connection
    `boolean` | `isInit()` Determine whether Torque has already been initialized.
    `void` | `setSchema(String name, String schema)` Sets the current schema for a database connection

- - ### Field Detail

    - #### ROLE

          static final String ROLE

      The avalon role.

  - ### Method Detail

    - #### isInit

          boolean isInit()

      Determine whether Torque has already been initialized.
      Returns:
        true if Torque is already initialized

    - #### getConfiguration

          org.apache.commons.configuration2.Configuration getConfiguration()

      Get the configuration for this component.
      Returns:
        the Configuration

    - #### getManager

          <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name)

      This method returns a Manager for the given name.
      Type Parameters:
        `T` - manager class type
      Parameters:
        `name` - name of the manager
      Returns:
        a Manager

    - #### getManager

          <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name,
                                                                             String defaultClassName)

      This methods returns either the Manager from the configuration file, or the default one provided by the generated code.
      Type Parameters:
        `T` - manager class type
      Parameters:
        `name` - name of the manager
        `defaultClassName` - the class to use if name has not been configured
      Returns:
        a Manager

    - #### getDatabaseMap

          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

          DatabaseMap getDatabaseMap(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.

    - #### getConnection

          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

          Connection getConnection(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

          Connection getConnection(String name,
                                   String username,
                                   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.

    - #### getAdapter

          Adapter getAdapter(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

          String getDefaultDB()

      Returns the name of the default database.
      Returns:
        name of the default DB

    - #### closeConnection

          void closeConnection(Connection con)

      Closes a connection.
      Parameters:
        `con` - A Connection to close.

    - #### setSchema

          void setSchema(String name,
                         String schema)
                  throws TorqueException

      Sets the current schema for a database connection
      Parameters:
        `name` - The database name.
        `schema` - The current schema name
      Throws:
        `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

    - #### getSchema

          String getSchema(String name)
                    throws TorqueException

      This method returns the current schema for a database connection
      Parameters:
        `name` - The database name.
      Returns:
        The current schema name. Null means, no schema has been set.
      Throws:
        `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

    - #### getDatabase

          Database getDatabase(String databaseName)
                        throws TorqueException

      Returns the database for the key `databaseName`.
      Parameters:
        `databaseName` - the key to get the database for.
      Returns:
        the database for the specified key, or null if the database does not exist.
      Throws:
        `TorqueException` - if Torque is not yet initialized.

    - #### getDatabases

          Map<String,Database> getDatabases()
                                     throws TorqueException

      Returns a Map containing all Databases registered to Torque. The key of the Map is the name of the database, and the value is the database instance.

      Note that in the very special case where a new database which is not configured in Torque's configuration gets known to Torque at a later time, the returned map may change, and there is no way to protect you against this.

      Returns:
        a Map containing all Databases known to Torque, never null.
      Throws:
        `TorqueException` - if Torque is not yet initialized.

    - #### getOrCreateDatabase

          Database getOrCreateDatabase(String databaseName)

      Returns the database for the key `databaseName`. If no database is associated to the specified key, a new database is created, mapped to the specified key, and returned.
      Parameters:
        `databaseName` - the key to get the database for.
      Returns:
        the database associated with specified key, or the newly created database, never null.

Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.