Hello Jiaqi,
First it's possible to define more than one database connection for torque like this:
Torque.database.default=dsf1 Torque.dsfactory.dsf1.factory=.. ..... Torque.database.another=dsf2 Torque.dsfactory.dsf2.factory=.. .....
Aye, I'm doing that already, works well.
At runtime you can call it dynamically:
Connection dbcon1 = Torque.getConnection(); //Get a connection for default database Connection dbcon2 = Torque.getConnection("another");
I'm doing that too, to get Connections which I then use directly (i.e. without using the Torque OM classes).
But how do I instruct Torque to use dbcon2 instead of the default when using the Torque OM classes (i.e., "SomePeer.doSelect(crit)")?
Thanks, Ekkehard
-----Original Message----- From: Ekkehard Kraemer [mailto:[EMAIL PROTECTED] Sent: Wednesday, December 31, 2003 5:48 AM To: [EMAIL PROTECTED] Subject: Torque with more dynamic DB connections, avoiding singleton and statics?
Hello,
is it possible to avoid the Torque singleton and static OM members altogether?
I have some quite dynamic needs for my DBMS connections. In the easiest case, it boils down to being able to specify which of several databases (defined in the standard Torque property file) to use during runtime.
Ideally, I would do something like
for (Iterator i=SomePeer.doSelect(whichDb,crit).iterator(); i.hasNext(); ) { Some some=(Some)(i.next()); // some is from whichDb doSomething(some); }
Or
TorqueInstance torq=new TorqueInstance(whichDb); for (Iterator i=SomePeer.doSelect(torq,crit).iterator(); i.hasNext(); ) ...
Or
SomePeer somePeer=new SomePeer(whichDb); for (Iterator i=somePeer.doSelect(torq,crit).iterator(); i.hasNext(); ) ...
Where whichDb tells Torque which database should be used.
While a TorqueInstance exists already, the generated OM classes contain static members for the database name (and maybe other things). I see no place to put the "whichDb" in.
Any hint on whether this can be solved, and how? I didn't find much in the documentation or the archives; and looking at the source code made me suspect it is not possible at the moment. Am I wrong? Is this functionality being planned for the future of Torque?
Simply changing the "final static" members to "static" and overwriting them as needed is probably not a solution for me, as the next step would be to work on two different databases at the same time (with the same set of OM classes)...
Thanks in advance, Ekkehard
--------------------------------------------------------------------- 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]
-- Ekkehard Kraemer
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]