db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeremy Kincaid" <Jeremy.Kinc...@intermoco.com>
Subject RE: How to dynamically add new database to Torque
Date Thu, 27 Nov 2003 23:41:58 GMT
Thankyou for the response Gerhard, but unfortunately it didn't work for me.  I still get the
error "java.lang.NullPointerException: There was no DataSourceFactory configured for the connection
newDatabase".  I am using Torque version 3.1.  I read that they have changed the re-entry
to the initialize method from earlier versions.

Torque is a static wapper for the TorqueInstance class.  The TorqueInstance.init(Configuration)
method calls setConfiguration(Configuration) and then initialize().  Inside the initialize()
method there is an if statement that checks if Torque has already been initialized.  If so,
then simply returns and the adapters and data source factories are not initialized. I think
this is a safety measure as the initialize() method also creates new hashmaps for mapping
databases to adapters and data source factories which would override existing maps.  If the
creation of these hashmaps were done else where, then it might be easier.

At this stage I am comptemplating creating a class that inherits from TorqueInstance and has
the ablility to add to the hashmaps.
//------------------------------------------------------------
        Jeremy Kincaid
          Software Systems Engineer
 
          Intermoco Solutions Pty. Ltd.
          488-494 La Trobe Street
          Melbourne, Victoria, 3000
          AUSTRALIA
          
          Voice: +61 3 8080 8709
          Fax:    +61 3 8080 8700
          email:  jeremy.kincaid@intermoco.com
          www.intermoco.com


-----Original Message-----
From: Gerhard Otte [mailto:Gerhard.Otte@emediapark.de] 
Sent: Thursday, 27 November 2003 6:52 PM
To: Apache Torque Users List
Subject: AW: How to dynamically add new database to Torque


You have to start a new configuration with
Configuration c = (Configuration)new PropertiesConfiguration("Torque.properties");
Then change youtr properties and finally call
Torque.init(c);
At least that worked for me.

Gerhard Otte
__
mailto:G.Otte@emediapark.de     emediapark GmbH http://www.emediapark.de
Tel:+49 (0)941 630804-2 Fax:-9  Hemauerstr.14,93047 Regensburg,Germany

-----Urspr√ľngliche Nachricht-----
Von: Jeremy Kincaid [mailto:Jeremy.Kincaid@intermoco.com]
Gesendet: Donnerstag, 27. November 2003 07:31
An: torque-user@db.apache.org
Betreff: How to dynamically add new database to Torque


	I am trying to find a way to dynamically add a new database to Torque after it as already
been initialized.  I tried retreiving the configuration from Torque and then adding properties
that would normally have appeared in the torque.properties file, then called Torque.init(configuration),
or Torque.setConfiguration(configuration),
but these didn't work.  After looking at the source code, it was easy to see why.  So does
anyone have an alternative for the following:

Configuration config = Torque.getConfiguration();
//add adpater information
config.addProperty( "database.newDatabase.adapter", "mysql" );	
//add pooling information
config.addProperty( "dsfactory.newDatabase.factory", "org.apache.torque.dsfactory.SharedPoolDataSourceFactory"
); config.addProperty( "dsfactory.newDatabase.defaultMaxActive", "10" ); config.addProperty(
"dsfactory.newDatabase.testOnBorrow", "true" ); config.addProperty( "dsfactory.newDatabase.validationQuery",
"SELECT 1" ); config.addProperty( "dsfactory.newDatabase.connection.driver",
"org.gjt.mm.mysql.Driver" );
config.addProperty( "dsfactory.newDatabase.connection.url",
"jdbc:mysql://localhost:3306/NewDatabase" );

Torque.init( config );
Connection newConnection = Torque.getConnection( "newDatabase" );

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message