Hi Ekkehard,

To my understanding, torque is able to connect many databases at the same
time without avoiding singleton and static.

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

At runtime you can call it dynamically:

Connection dbcon1 = Torque.getConnection(); //Get a connection for default
database
Connection dbcon2 = Torque.getConnection("another");
 
 
Regards
Jiaqi Guo
 
email: [EMAIL PROTECTED]
site: http://cyclops-group.sourceforge.net

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

Reply via email to