|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.torque.TorqueInstance
public class TorqueInstance
The core of Torque's implementation. Both the classic Torque
static wrapper and the TorqueComponent
Avalon implementation leverage
this class.
Constructor Summary | |
---|---|
TorqueInstance()
Creates a new instance with default configuration. |
Method Summary | ||
---|---|---|
void |
closeConnection(Connection con)
Closes a connection. |
|
Adapter |
getAdapter(String name)
Returns the database adapter for a specific database. |
|
org.apache.commons.configuration.Configuration |
getConfiguration()
Get the configuration for this component. |
|
Connection |
getConnection()
This method returns a Connection from the default pool. |
|
Connection |
getConnection(String name)
Returns a database connection to the database with the key name . |
|
Connection |
getConnection(String name,
String username,
String password)
This method returns a Connection using the given parameters. |
|
Database |
getDatabase(String databaseName)
Returns the database for the key databaseName . |
|
DatabaseMap |
getDatabaseMap()
Returns the database map information for the default db. |
|
DatabaseMap |
getDatabaseMap(String name)
Returns the database map information for the given database name. |
|
Map<String,Database> |
getDatabases()
Returns a Map containing all Databases registered to Torque. |
|
DataSourceFactory |
getDataSourceFactory(String name)
Returns the DataSourceFactory for the database with the name name . |
|
Adapter |
getDB(String name)
Deprecated. use getAdapter(String) instead. This method will be removed in a future version of Torque. |
|
String |
getDefaultDB()
Returns the name of the default database. |
|
|
getManager(String name)
This method returns a Manager for the given name. |
|
|
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 |
|
void |
init(org.apache.commons.configuration.Configuration conf)
Initialization of Torque with a Configuration object. |
|
void |
init(String configFile)
Initialization of Torque with a path to a properties file. |
|
protected void |
initManagerMappings(org.apache.commons.configuration.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. |
|
void |
setConfiguration(org.apache.commons.configuration.Configuration conf)
Sets the configuration for Torque and all dependencies. |
|
void |
setSchema(String name,
String schema)
Sets the current schema for a database connection |
|
void |
shutdown()
Shuts down Torque. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TorqueInstance()
resetConfiguration()
Method Detail |
---|
public 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 void init(org.apache.commons.configuration.Configuration conf) throws TorqueException
conf
- The Torque configuration.
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.protected void initManagerMappings(org.apache.commons.configuration.Configuration conf) throws TorqueException
torque.managed_class.com.mycompany.Myclass.manager= \ com.mycompany.MyManagerImpl services.managed_class.com.mycompany.Myotherclass.manager= \ com.mycompany.MyOtherManagerImpl
conf
- the Configuration representing the properties file
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public boolean isInit()
public void setConfiguration(org.apache.commons.configuration.Configuration conf) throws TorqueException
TORQUE_KEY
will be removed from the
configuration keys for the provided configuration.
conf
- the Configuration.
TorqueException
- if the configuration does not contain
any keys starting with Torque.TORQUE_KEY
.public org.apache.commons.configuration.Configuration getConfiguration()
public <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name)
name
- name of the manager
public <T extends AbstractBaseManager<? extends Persistent>> T getManager(String name, String defaultClassName)
name
- name of the manager.defaultClassName
- the class to use if name has not been configured.
public 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 DatabaseMap getDatabaseMap() throws TorqueException
TorqueException
- if Torque is not initialized.public 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 void registerIDBroker(IDBroker idBroker)
idBroker
- the id broker to register, not null.
NullPointerException
- if idBroker is null.public Connection getConnection() throws TorqueException
TorqueException
- Any exceptions caught during processing will be
rethrown wrapped into a TorqueException.public Connection getConnection(String name) throws TorqueException
name
.
name
- The database name.
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.public DataSourceFactory getDataSourceFactory(String name) throws TorqueException
name
.
name
- The name of the database to get the DSF for.
TorqueException
- if Torque is not initialized, or
no DatasourceFactory is configured for the given name.public 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.@Deprecated public Adapter getDB(String name) throws TorqueException
name
- the database name, or null for the default db.
TorqueException
- if Torque is not initialized.public Adapter getAdapter(String name) throws TorqueException
name
- the database name, or null for the default db.
TorqueException
- if Torque is not initialized.public String getDefaultDB()
public void closeConnection(Connection con)
con
- A Connection to close.public void setSchema(String name, String schema)
name
- The database name, not null.schema
- The current schema name.
NullPointerException
- if databaseName is null.public String getSchema(String name) throws TorqueException
name
- The database name.
TorqueException
- if Torque is not yet initialized.public Database getDatabase(String databaseName) throws TorqueException
databaseName
.
databaseName
- the key to get the database for,
or null for the default database.
TorqueException
- if Torque is not yet initialized.public Map<String,Database> getDatabases() throws TorqueException
TorqueException
- if Torque is not yet initialized.public Database getOrCreateDatabase(String databaseName)
databaseName
.
If no database is associated to the specified key,
a new database is created, mapped to the specified key, and returned.
databaseName
- the key to get the database for, not null.
NullPointerException
- if databaseName is null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |