db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guy Galil <Guy_Ga...@guardium.com>
Subject Re: change of base configuration at runtime
Date Tue, 24 May 2005 14:10:13 GMT
Following is the message I posted on this subject on August 04.
Note that I am using an old version of Torque and that I had to modify
Torque.java to get this to work - My impression was that
Torque.shutDown() does not do what it is supposed to do, One problem I
had to fix was that Torque.initialize() is not reentrant - it
initializes logging which should be done only once and it sets - 
mapBuilders = null; which results in a nullPointerException
I dont know if this is true in newer versions.
Cheers Guy



>We change database host as well as other properties at runtime.
> We are using an old version of Torque - 3.02
> In order to achieve this I had to modify org.apache.torque.Torque.java
> so that it is re-entrant and added a reConfig(Configuration c) method.
> Then in my code I created a utility class that can be used to change the
> configuration at runtime:
> 
> public static  void changeDbHost(String logicName, String host) throws
> TorqueException
> {
> 	Configuration config = Torque.getConfiguration();
> 	replaceProperty(config,URL.replaceAll("logic_name",logicName),"jdbc:mysql://"+host+"/DATABASE");
> 	Torque.reConfig(config);
> }
> 
> public static void replaceProperty(Configuration config, String key,
> String value)
> {
> 	if(config.containsKey(key))
> 		config.setProperty(key, value);
> 	else
> 		config.addProperty(key, value);	
> }
> This works well for me.
> I understand that Torque changed since the version I use and my
> modifications to Torque.java are either not needed or not compatible
> with the latest code, I am willing to send my Torque.java if you are
> interested.
> Guy
> 

On Tue, 2005-05-24 at 12:01 +0200, Lionel Pasquier wrote:
> I know you posted something about it, but I was unable to retrieve the 
> thread.
> 
> What I tried to do was also:
> 
> Configuration torqueconf = Torque.getConfiguration();
> torqueconf.setProperty("torque.dsfactory.mydb.connection.url", 
> newproperties.get("torque.dsfactory.mydb.connection.url"));
> torqueconf.setProperty("torque.dsfactory.customer.connection.user", 
> newproperties.get("torque.dsfactory.customer.connection.user"));
> torqueconf.setProperty("torque.dsfactory.customer.connection.password", 
> newproperties.get("torque.dsfactory.customer.connection.password"));
> Torque.setConfiguration(torqueconf);
> Torque.getInstance().shutdown(); // with or without
> Torque.getInstance().init(ConfigurationConverter.getConfiguration(properties));
> 
> But this led me to the a Nullpointer (db = 
> Torque.getDB(criteria.getDbName()) is null) if the shutdown is present, 
> and to contacting the wrong DB is the shutdown is not present.
> 
> Could you re-post your solution?
> 
> 
> Guy Galil wrote:
> 
> >It depends on the version of Torque you use.
> >I posted a solution for Torque 3.02 a while ago, The idea is to get the
> >Configuration object, change some
> >settings and reconfigure Torque.
> >It requires some digging into the Torque code but is doable.
> >I can provide the 3.02 code if you want but I know those things changed
> >since that version.
> >On Mon, 2005-05-23 at 18:55 +0200, Lionel Pasquier wrote:
> >  
> >
> >>Hello,
> >>
> >>I 've read a few threads on this mailing list about the problem of 
> >>changing of database configuration using:
> >>Torque.init(pathToConf);
> >>Torque.shutdown();
> >>Torque.init(newPathOfConf);
> >>
> >>Unfortunatly I still have the classic NullpointerException at any torque 
> >>access after the 2nd init.
> >>
> >>Has anyone solved this problem and knows a workaround?
> >>
> >>Lionel
> >>
> >>
> >>
> >>---------------------------------------------------------------------
> >>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
> 


---------------------------------------------------------------------
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