Package org.apache.torque

# Klasse Torque

java.lang.Object
org.apache.torque.Torque

public final class Torque extends Object

A static facade wrapper around the Torque implementation (which is in `TorqueInstance`).

Version:
  $Id: Torque.java 1917245 2024-04-21 14:06:23Z tv $
Autor:
  Daniel Rall, Magnï¿½s ï¿½ï¿½r Torfason, Jason van Zyl, Rafal Krzewski, Martin Poeschl, Henning P. Schmiedehausen, Kurt Schrader

- ## Feldübersicht

  Felder
  Modifizierer und Typ
  Feld
  Beschreibung
  `static final String`
  `CACHE_KEY`
  Name of config property to determine whether caching is used.
  `static final String`
  `DATABASE_KEY`
  The prefix for configuring the database adapters and the default database.
  `static final String`
  `DEFAULT_KEY`
  The key used to configure the name of the default database.
  `static final String`
  `DEFAULT_SCHEMA_KEY`
  default schema name for the configuration
  `static final String`
  `DEFAULTS_KEY`
  "defaults" Key for the configuration
  `static final String`
  `MANAGER_PREFIX`
  A prefix for `Manager` properties in the configuration.
  `static final String`
  `MANAGER_SUFFIX`
  A `Service` property determining its implementing class name .
  `static final String`
  `SCHEMA_KEY`
  "schema" Key for the configuration
  `static final String`
  `TORQUE_KEY`
  The prefix for all configuration keys used by Torque.
  `static final String`
  `TRANSACTION_MANAGER_KEY`
  The prefix for configuring the transaction manger.

- ## Methodenübersicht

  Modifizierer und Typ
  Methode
  Beschreibung
  `static void`
  `closeConnection(Connection con)`
  Closes a connection.
  `static Adapter`
  `getAdapter(String name)`
  Returns the database adapter for a specific database name.
  `static org.apache.commons.configuration2.Configuration`
  `getConfiguration()`
  Get the configuration for this component.
  `static Connection`
  `getConnection()`
  This method returns a Connection from the default pool.
  `static Connection`
  `getConnection(String name)`
  This method returns a Connecton using the given database name.
  `static Connection`
  `getConnection(String name, String username, String password)`
  This method returns a Connecton using the given parameters.
  `static Database`
  `getDatabase(String name)`
  Returns the database for the given key.
  `static DatabaseMap`
  `getDatabaseMap()`
  Returns the default database map information.
  `static DatabaseMap`
  `getDatabaseMap(String name)`
  Returns the database map information for a given database.
  `static Map<String,Database>`
  `getDatabases()`
  Returns a Map containing all Databases registered to Torque.
  `static String`
  `getDefaultDB()`
  Returns the name of the default database.
  `static TorqueInstance`
  `getInstance()`
  Retrieves the single `TorqueInstance` used by this class.
  `static <T extends AbstractBaseManager<? extends Persistent>>
  T`
  `getManager(String name)`
  This method returns a Manager for the given name.
  `static <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.
  `static Database`
  `getOrCreateDatabase(String name)`
  Returns the database for the key `databaseName`.
  `static <T, P extends BasePeerImpl<T>>
  P`
  `getPeerInstance(Class<T> omClass)`
  This method returns a PeerImpl for the given class.
  `static String`
  `getSchema(String name)`
  This method returns the current schema for a database connection
  `static void`
  `init(String configFile)`
  Initialization of Torque with a path to a properties file.
  `static void`
  `init(org.apache.commons.configuration2.Configuration conf)`
  Initialization of Torque with a configuration.
  `static boolean`
  `isInit()`
  Determine whether Torque has already been initialized.
  `static void`
  `registerIDBroker(IDBroker idBroker)`
  Registers an id broker.
  `static <T> void`
  `registerPeerInstance(Class<T> omClass, BasePeerImpl<T> peerInstance)`
  This method registers a PeerImpl for a given class.
  `static void`
  `setConfiguration(org.apache.commons.configuration2.Configuration conf)`
  Sets the configuration for Torque and all dependencies.
  `static void`
  `setInstance(TorqueInstance instance)`
  Sets the single `TorqueInstance` used by this class.
  `static void`
  `setSchema(String name, String schema)`
  Sets the current schema for a database connection
  `static void`
  `shutdown()`
  Shuts down the service.

  ### Von Klasse geerbte Methoden java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Felddetails

  - ### TORQUE_KEY

    public static final String TORQUE_KEY
    The prefix for all configuration keys used by Torque.
    Siehe auch:
      - Konstantenfeldwerte

  - ### DATABASE_KEY

    public static final String DATABASE_KEY
    The prefix for configuring the database adapters and the default database.
    Siehe auch:
      - Konstantenfeldwerte

  - ### DEFAULT_KEY

    public static final String DEFAULT_KEY
    The key used to configure the name of the default database.
    Siehe auch:
      - Konstantenfeldwerte

  - ### SCHEMA_KEY

    public static final String SCHEMA_KEY
    "schema" Key for the configuration
    Siehe auch:
      - Konstantenfeldwerte

  - ### DEFAULTS_KEY

    public static final String DEFAULTS_KEY
    "defaults" Key for the configuration
    Siehe auch:
      - Konstantenfeldwerte

  - ### DEFAULT_SCHEMA_KEY

    public static final String DEFAULT_SCHEMA_KEY
    default schema name for the configuration
    Siehe auch:
      - Konstantenfeldwerte

  - ### MANAGER_PREFIX

    public static final String MANAGER_PREFIX
    A prefix for `Manager` properties in the configuration.
    Siehe auch:
      - Konstantenfeldwerte

  - ### MANAGER_SUFFIX

    public static final String MANAGER_SUFFIX
    A `Service` property determining its implementing class name .
    Siehe auch:
      - Konstantenfeldwerte

  - ### CACHE_KEY

    public static final String CACHE_KEY
    Name of config property to determine whether caching is used.
    Siehe auch:
      - Konstantenfeldwerte

  - ### TRANSACTION_MANAGER_KEY

    public static final String TRANSACTION_MANAGER_KEY
    The prefix for configuring the transaction manger.
    Siehe auch:
      - Konstantenfeldwerte

- ## Methodendetails

  - ### getInstance

    public static TorqueInstance getInstance()
    Retrieves the single `TorqueInstance` used by this class.
    Gibt zurück:
      Our singleton.

  - ### setInstance

    public static void setInstance(TorqueInstance instance)
    Sets the single `TorqueInstance` used by this class. This is used by the Avalon component to make sure that only one instance of Torque exists.
    Parameter:
      `instance` - Our singleton.

  - ### init

    public static void init(String configFile) throws TorqueException
    Initialization of Torque with a path to a properties file.
    Parameter:
      `configFile` - The absolute path to the configuration file.
    Löst aus:
      `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

  - ### init

    public static void init(org.apache.commons.configuration2.Configuration conf) throws TorqueException
    Initialization of Torque with a configuration.
    Parameter:
      `conf` - The Torque configuration.
    Löst aus:
      `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.
    Gibt zurück:
      true if Torque is already initialized

  - ### setConfiguration

    public static void setConfiguration(org.apache.commons.configuration2.Configuration conf) throws TorqueException
    Sets the configuration for Torque and all dependencies.
    Parameter:
      `conf` - the Configuration
    Löst aus:
      `TorqueException` - if the configuration does not contain any keys starting with `Torque.TORQUE_KEY`.

  - ### getConfiguration

    public static org.apache.commons.configuration2.Configuration getConfiguration()
    Get the configuration for this component.
    Gibt zurück:
      the Configuration

  - ### getManager

    public static <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name)
    This method returns a Manager for the given name.
    Typparameter:
      `T` - the type of the manager class
    Parameter:
      `name` - name of the manager.
    Gibt zurück:
      The requested Manager.

  - ### getManager

    public static <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.
    Typparameter:
      `T` - the type of the manager class
    Parameter:
      `name` - name of the manager.
      `defaultClassName` - the class to use if name has not been configured.
    Gibt zurück:
      a Manager

  - ### registerPeerInstance

    public static <T> void registerPeerInstance(Class<T> omClass, BasePeerImpl<T> peerInstance)
    This method registers a PeerImpl for a given class.
    Typparameter:
      `T` - the type of the OM class
    Parameter:
      `omClass` - the class of the associated OM object
      `peerInstance` - PeerImpl instance

  - ### getPeerInstance

    public static <T, P extends BasePeerImpl<T>> P getPeerInstance(Class<T> omClass)
    This method returns a PeerImpl for the given class.
    Typparameter:
      `T` - the type of the OM class
      `P` - the type of the peer instance class
    Parameter:
      `omClass` - the class of the associated OM object
    Gibt zurück:
      a PeerImpl instance

  - ### shutdown

    public static void shutdown() throws TorqueException
    Shuts down the service. This method halts the IDBroker's daemon thread in all of the DatabaseMap's. It also closes all SharedPoolDataSourceFactories and PerUserPoolDataSourceFactories initialized by Torque.
    Löst aus:
      `TorqueException` - if a DataSourceFactory could not be closed cleanly. Only the first exception is rethrown, any following exceptions are logged but ignored.

  - ### getDatabaseMap

    public static DatabaseMap getDatabaseMap() throws TorqueException
    Returns the default database map information.
    Gibt zurück:
      A DatabaseMap.
    Löst aus:
      `TorqueException` - if Torque is not initialized.

  - ### getDatabaseMap

    public static DatabaseMap getDatabaseMap(String name) throws TorqueException
    Returns the database map information for a given database.
    Parameter:
      `name` - The name of the database corresponding to the `DatabaseMap` to retrieve, or null for the default database.
    Gibt zurück:
      The named `DatabaseMap`, not null.
    Löst aus:
      `TorqueException` - if Torque is not initialized and name is null.

  - ### registerIDBroker

    public static void registerIDBroker(IDBroker idBroker)
    Registers an id broker. If Torque is already initialized, the id broker is started. If Torque is not initialized, the id broker will be started on initialization.
    Parameter:
      `idBroker` - the id broker to register, not null.
    Löst aus:
      `NullPointerException` - if idBroker is null.

  - ### getConnection

    public static Connection getConnection() throws TorqueException
    This method returns a Connection from the default pool.
    Gibt zurück:
      The requested connection.
    Löst aus:
      `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

  - ### getConnection

    public static Connection getConnection(String name) throws TorqueException
    This method returns a Connecton using the given database name.
    Parameter:
      `name` - The database name.
    Gibt zurück:
      a database connection to the database with the given name.
    Löst aus:
      `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

  - ### getConnection

    public static 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!
    Parameter:
      `name` - The database name.
      `username` - The name of the database user.
      `password` - The password of the database user.
    Gibt zurück:
      A Connection to the database with the given name.
    Löst aus:
      `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

  - ### getAdapter

    public static Adapter getAdapter(String name) throws TorqueException
    Returns the database adapter for a specific database name.
    Parameter:
      `name` - the database name, or null for the default db.
    Gibt zurück:
      The corresponding database adapter, or null if no database adapter is defined for the given database.
    Löst aus:
      `TorqueException` - Any exceptions caught during processing will be rethrown wrapped into a TorqueException.

  - ### getDefaultDB

    public static String getDefaultDB()
    Returns the name of the default database.
    Gibt zurück:
      name of the default DB, or null if Torque is not initialized yet

  - ### closeConnection

    public static void closeConnection(Connection con)
    Closes a connection.
    Parameter:
      `con` - A Connection to close.

  - ### setSchema

    public static void setSchema(String name, String schema)
    Sets the current schema for a database connection
    Parameter:
      `name` - The database name.
      `schema` - The current schema name.
    Löst aus:
      `NullPointerException` - if databaseName is null.

  - ### getSchema

    public static String getSchema(String name) throws TorqueException
    This method returns the current schema for a database connection
    Parameter:
      `name` - The database name.
    Gibt zurück:
      The current schema name. Null means, no schema has been set.
    Löst aus:
      `TorqueException` - if Torque is not yet initialized.

  - ### getDatabase

    public static Database getDatabase(String name) throws TorqueException
    Returns the database for the given key.
    Parameter:
      `name` - the key to get the database for, or null for the default database.
    Gibt zurück:
      the Database for the given name, or null if no database exists for the given name.
    Löst aus:
      `TorqueException` - if Torque is not yet initialized.

  - ### getOrCreateDatabase

    public static Database getOrCreateDatabase(String name)
    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.
    Parameter:
      `name` - the key to get the database for, not null.
    Gibt zurück:
      the database associated with specified key, or the newly created database, never null.
    Löst aus:
      `IllegalArgumentException` - if databaseName is null.

  - ### getDatabases

    public static 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. However, Databases should be initialized in the init() method, so this will not happen if Torque is used properly.

    Gibt zurück:
      a Map containing all Databases known to Torque, never null.
    Löst aus:
      `TorqueException` - if Torque is not yet initialized.