public final class Torque extends Object
 A static facade wrapper around the Torque implementation (which is in
 TorqueInstance).
 
| Modifier and Type | Field and Description | 
|---|---|
| static String | CACHE_KEYName of config property to determine whether caching is used. | 
| static String | DATABASE_KEYThe prefix for configuring the database adapters
 and the default database. | 
| static String | DEFAULT_KEYThe key used to configure the name of the default database. | 
| static String | DEFAULT_SCHEMA_KEYdefault schema name for the configuration | 
| static String | DEFAULTS_KEY"defaults" Key for the configuration | 
| static String | MANAGER_PREFIXA prefix for  Managerproperties in the configuration. | 
| static String | MANAGER_SUFFIXA  Serviceproperty determining its implementing
 class name . | 
| static String | SCHEMA_KEY"schema" Key for the configuration | 
| static String | TORQUE_KEYThe prefix for all configuration keys used by Torque. | 
| static String | TRANSACTION_MANAGER_KEYThe prefix for configuring the transaction manger. | 
| Modifier and Type | Method and Description | 
|---|---|
| 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  TorqueInstanceused by this class. | 
| static <T extends AbstractBaseManager<? extends Persistent>> | getManager(String name)This method returns a Manager for the given name. | 
| static <T extends AbstractBaseManager<? extends Persistent>> | 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>> | 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(org.apache.commons.configuration2.Configuration conf)Initialization of Torque with a configuration. | 
| static void | init(String configFile)Initialization of Torque with a path to a properties file. | 
| 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  TorqueInstanceused 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. | 
public static final String TORQUE_KEY
public static final String DATABASE_KEY
public static final String DEFAULT_KEY
public static final String SCHEMA_KEY
public static final String DEFAULTS_KEY
public static final String DEFAULT_SCHEMA_KEY
public static final String MANAGER_PREFIX
Manager properties in the configuration.public static final String MANAGER_SUFFIX
Service property determining its implementing
 class name .public static final String CACHE_KEY
public static final String TRANSACTION_MANAGER_KEY
public static TorqueInstance getInstance()
TorqueInstance
 used by this class.public static void setInstance(TorqueInstance instance)
TorqueInstance
 used by this class. This is used by the Avalon component
 to make sure that only one instance of Torque exists.instance - Our singleton.public static void init(String configFile) throws TorqueException
configFile - The absolute path to the configuration file.TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static void init(org.apache.commons.configuration2.Configuration conf)
                 throws TorqueException
conf - The Torque configuration.TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static boolean isInit()
public static void setConfiguration(org.apache.commons.configuration2.Configuration conf)
                             throws TorqueException
conf - the ConfigurationTorqueException - if the configuration does not contain
         any keys starting with Torque.TORQUE_KEY.public static org.apache.commons.configuration2.Configuration getConfiguration()
public static <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name)
T - the type of the manager classname - name of the manager.public static <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name, String defaultClassName)
T - the type of the manager classname - name of the manager.defaultClassName - the class to use if name has not been configured.public static <T> void registerPeerInstance(Class<T> omClass, BasePeerImpl<T> peerInstance)
T - the type of the OM classomClass - the class of the associated OM objectpeerInstance - PeerImpl instancepublic static <T,P extends BasePeerImpl<T>> P getPeerInstance(Class<T> omClass)
T - the type of the OM classP - the type of the peer instance classomClass - the class of the associated OM objectpublic static void shutdown()
                     throws TorqueException
TorqueException - if a DataSourceFactory could not be closed
            cleanly. Only the first exception is rethrown, any following
            exceptions are logged but ignored.public static DatabaseMap getDatabaseMap() throws TorqueException
TorqueException - if Torque is not initialized.public static DatabaseMap getDatabaseMap(String name) throws TorqueException
name - The name of the database corresponding to the
        DatabaseMap to retrieve, or null
        for the default database.DatabaseMap, not null.TorqueException - if Torque is not initialized and name is null.public static void registerIDBroker(IDBroker idBroker)
idBroker - the id broker to register, not null.NullPointerException - if idBroker is null.public static Connection getConnection() throws TorqueException
TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static Connection getConnection(String name) throws TorqueException
name - The database name.TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static Connection getConnection(String name, String username, String password) throws TorqueException
name - The database name.username - The name of the database user.password - The password of the database user.TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static Adapter getAdapter(String name) throws TorqueException
name - the database name, or null for the default db.TorqueException - Any exceptions caught during processing will be
         rethrown wrapped into a TorqueException.public static String getDefaultDB()
public static void closeConnection(Connection con)
con - A Connection to close.public static void setSchema(String name, String schema)
name - The database name.schema - The current schema name.NullPointerException - if databaseName is null.public static String getSchema(String name) throws TorqueException
name - The database name.TorqueException - if Torque is not yet initialized.public static Database getDatabase(String name) throws TorqueException
name - the key to get the database for,
        or null for the default database.TorqueException - if Torque is not yet initialized.public static Database getOrCreateDatabase(String name)
databaseName.
 If no database is associated to the specified key,
 a new database is created, mapped to the specified key, and returned.name - the key to get the database for, not null.IllegalArgumentException - if databaseName is null.public static Map<String,Database> getDatabases() throws TorqueException
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.
TorqueException - if Torque is not yet initialized.Copyright © 2000–2020 The Apache Software Foundation. All rights reserved.