Thanks ! That helped a lot, now I need to see if init is reentrant or
not on my version.
Guy Galil wrote:
I have a situation in my applications that I need to switch databases
dynamically - I use a pretty old version of Torque (3.02) so I had to
tweak it a little but basically what I do is get the Configuration
object, modify the properties in it and re-configure Torque:
public static final String URL = "dsfactory.logic_name.connection.url";
public static void switchDatabase(String logicName, String oldDatabase,
String newDatabase) throws Exception
{
Configuration config = Torque.getConfiguration();
String key = URL.replaceAll("logic_name",logicName);
String url = config.getString(key);
if(url == null)
throw new InvalidArgumentException("Wrong logic name -
"+logicName);
url = url.replaceAll(oldDatabase, newDatabase);
config.setProperty(key, url);
Torque.reConfig(config);
}
Note that Torque.reConfig(Configuration config); is a method I added
because in that version Torque.init(Configuration) was not re-entrant, I
think it is fixed in later versions.
Guy
On Thu, 2006-04-20 at 09:55 -0400, Eustache wrote:
OK sorry for not being clear:
It's a single web app that wants to have access to several databases at
runtime.
Roughly: the user can select the database he is going to work on, and he
can even use this webapp to add a new database he is going to work on.
Those databases have the same structure though.
I hope this helps clarify
Before I answer this, it would be nice to know more about
how you are defining "using multiple databases". In
particular, are you talking about multiple separate
instances of your code, each using different DB's (e.g
multiple web applications) or a single monolithic code
base that does this (e.g a single web application or
standalone application).
-----Original Message-----
From: Eustache [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 20, 2006 9:44 AM
To: [email protected]
Subject: using unknown number of databases having the same "structure"
Hi, maybe somebody can give me an idea or point me to some resource:
I have several databases having the same structure but the number of
databases and their name are not known at design time (I have another
database to remember all that).
I would like to be able to use Torque generated classes with
parameters
at runtime (db name, host, user, etc.).
Of course I would like to generate only one bunch of classes for all
these databases since they have the same structure.
I looked at DB Schema support
http://db.apache.org/torque/releases/torque-3.2/docs-all-compo
nents/other-howtos/schema-howto.html
but I don't think it is what I want.
I also looked at "using Torque with multiple databases" but it is only
part of the answer because first I would like to make this configuration
dynamic (at runtime) and second the generated classes sould use a
"parameterized" database name (not sure there).
Any ideas ?
Thx very much,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are
confidential communication or may otherwise be privileged or confidential and
are intended solely for the individual or entity to whom they are addressed.
If you are not the intended recipient you may not rely on the contents of this
email or any attachments, and we ask that you please not read, copy or
retransmit this communication, but reply to the sender and destroy the email,
its contents, and all copies thereof immediately. Any unauthorized
dissemination, distribution or copying of this communication is strictly
prohibited.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]