Package org.apache.torque
Klasse TorqueInstance
java.lang.Object
org.apache.torque.TorqueInstance
- Bekannte direkte Unterklassen:
TorqueComponent
The core of Torque's implementation. Both the classic
Torque
static wrapper and the TorqueComponent
Avalon implementation leverage
this class.- Version:
- $Id: TorqueInstance.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, Thomas Vandahl
-
Konstruktorübersicht
Konstruktoren -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
Closes a connection.getAdapter
(String name) Returns the database adapter for a specific database.org.apache.commons.configuration2.Configuration
Get the configuration for this component.This method returns a Connection from the default pool.getConnection
(String name) Returns a database connection to the database with the keyname
.getConnection
(String name, String username, String password) This method returns a Connection using the given parameters.getDatabase
(String databaseName) Returns the database for the keydatabaseName
.Returns the database map information for the default db.getDatabaseMap
(String name) Returns the database map information for the given database name.Returns a Map containing all Databases registered to Torque.getDataSourceFactory
(String name) Returns the DataSourceFactory for the database with the namename
.Returns the name of the default database.<T extends AbstractBaseManager<? extends Persistent>>
TgetManager
(String name) This method returns a Manager for the given name.<T extends AbstractBaseManager<? extends Persistent>>
TgetManager
(String name, String defaultClassName) This methods returns either the Manager from the configuration file, or the default one provided by the generated code.getOrCreateDatabase
(String databaseName) Returns the database for the keydatabaseName
.<T,
P extends BasePeerImpl<T>>
PgetPeerInstance
(Class<T> omClass) This method returns a PeerImpl for the given class.This method returns the current schema for a database connectionvoid
Initialization of Torque with a path to a properties or xml file.void
init
(org.apache.commons.configuration2.Configuration conf) Initialization of Torque with a Configuration object.protected void
initManagerMappings
(org.apache.commons.configuration2.Configuration conf) Creates a mapping between classes and their manager classes.boolean
isInit()
Determine whether Torque has already been initialized.void
registerIDBroker
(IDBroker idBroker) Registers an id broker.<T> void
registerPeerInstance
(Class<T> omClass, BasePeerImpl<T> peerInstance) This method registers a PeerImpl for a given class.void
setConfiguration
(org.apache.commons.configuration2.Configuration conf) Sets the configuration for Torque and all dependencies.void
Sets the current schema for a database connectionvoid
shutdown()
Shuts down Torque.
-
Konstruktordetails
-
TorqueInstance
public TorqueInstance()Creates a new instance with default configuration.- Siehe auch:
-
-
Methodendetails
-
init
Initialization of Torque with a path to a properties or xml 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
Initialization of Torque with a Configuration object.- Parameter:
conf
- The Torque configuration.- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
initManagerMappings
protected void initManagerMappings(org.apache.commons.configuration2.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.- Parameter:
conf
- the Configuration representing the properties file- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
isInit
public boolean isInit()Determine whether Torque has already been initialized.- Gibt zurück:
- true if Torque is already initialized
-
setConfiguration
public void setConfiguration(org.apache.commons.configuration2.Configuration conf) throws TorqueException Sets the configuration for Torque and all dependencies. The prefixTORQUE_KEY
will be removed from the configuration keys for the provided configuration.- Parameter:
conf
- the Configuration.- Löst aus:
TorqueException
- if the configuration does not contain any keys starting withTorque.TORQUE_KEY
.
-
getConfiguration
public org.apache.commons.configuration2.Configuration getConfiguration()Get the configuration for this component.- Gibt zurück:
- the Configuration
-
getManager
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:
- a Manager
-
getManager
public <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
This method registers a PeerImpl for a given class.- Typparameter:
T
- the type of the OM class and the type of the peerInstance class, which is of type BasePeerImpl.- Parameter:
omClass
- the class of the associated OM objectpeerInstance
- PeerImpl instance
-
getPeerInstance
This method returns a PeerImpl for the given class.- Typparameter:
T
- the type of the OM classP
- the type of the peerInstance class- Parameter:
omClass
- the class of the associated OM object- Gibt zurück:
- a PeerImpl instance
-
shutdown
Shuts down Torque. 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
Returns the database map information for the default db.- Gibt zurück:
- the requested DatabaseMap, not null.
- Löst aus:
TorqueException
- if Torque is not initialized.
-
getDatabaseMap
Returns the database map information for the given database name.- Parameter:
name
- The name of the database corresponding to theDatabaseMap
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
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
This method returns a Connection from the default pool.- Gibt zurück:
- The requested connection, never null.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
getConnection
Returns a database connection to the database with the keyname
.- Parameter:
name
- The database name.- Gibt zurück:
- a database connection to the named database, never null.
- Löst aus:
TorqueException
- if Torque is not initialized, if no DataSourceFactory is configured for the named database, the connection information is wrong, or the connection cannot be returned for any other reason.
-
getDataSourceFactory
Returns the DataSourceFactory for the database with the namename
.- Parameter:
name
- The name of the database to get the DSF for.- Gibt zurück:
- A DataSourceFactory object, never null.
- Löst aus:
TorqueException
- if Torque is not initialized, or no DatasourceFactory is configured for the given name.
-
getConnection
public Connection getConnection(String name, String username, String password) throws TorqueException This method returns a Connection 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 named database.
- Löst aus:
TorqueException
- Any exceptions caught during processing will be rethrown wrapped into a TorqueException.
-
getAdapter
Returns the database adapter for a specific database.- 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
- if Torque is not initialized.
-
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
Closes a connection.- Parameter:
con
- A Connection to close.
-
setSchema
Sets the current schema for a database connection- Parameter:
name
- The database name, not null.schema
- The current schema name.- Löst aus:
NullPointerException
- if databaseName is null.
-
getSchema
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 or no database with the given name exists.
- Löst aus:
TorqueException
- if Torque is not yet initialized.
-
getDatabase
Returns the database for the keydatabaseName
.- Parameter:
databaseName
- the key to get the database for, or null for the default database.- Gibt zurück:
- the database for the specified key, or null if the database does not exist.
- Löst aus:
TorqueException
- if Torque is not yet initialized.
-
getDatabases
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.
- Gibt zurück:
- a Map containing all Databases known to Torque, never null.
- Löst aus:
TorqueException
- if Torque is not yet initialized.
-
getOrCreateDatabase
Returns the database for the keydatabaseName
. If no database is associated to the specified key, a new database is created, mapped to the specified key, and returned.- Parameter:
databaseName
- 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:
NullPointerException
- if databaseName is null.
-