You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Ekkehard Kraemer <ek...@pluto.camelot.de> on 2003/12/31 12:48:28 UTC

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: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Re: Torque with more dynamic DB connections, avoiding singleton and statics?

Posted by Jürgen Hoffmann <jh...@byteaction.de>.
Hi,

AFAIK you cannot do that. there is one default class and thats it. BUT Nobody 
is stopping you to extend Torque and add a method setDefaultDb(String 
connection) and use your new class to initialize Torque.

If yu would want to, you could create some kind of registry within a 
hashtable, which would manage you different Torque Connections which each 
have a different properties file for each Torque Instance. 

Kind Regards

Jürgen Hoffmann

On Friday 02 January 2004 20:00, Ekkehard Kraemer wrote:
> On Thu, 1 Jan 2004 22:12:14 -0600, Jiaqi Guo <ch...@hotmail.com>
> wrote:
>
> 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:ekraemer@pluto.camelot.de]
> > Sent: Wednesday, December 31, 2003 5:48 AM
> > To: torque-user@db.apache.org
> > 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: 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


Re: Torque with more dynamic DB connections, avoiding singleton and statics?

Posted by Ekkehard Kraemer <ek...@pluto.camelot.de>.
On Thu, 1 Jan 2004 22:12:14 -0600, Jiaqi Guo <ch...@hotmail.com> wrote:

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:ekraemer@pluto.camelot.de]
> Sent: Wednesday, December 31, 2003 5:48 AM
> To: torque-user@db.apache.org
> 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: 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
>



-- 
Ekkehard Kraemer

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


Re: Unable to connect to mysql

Posted by Sonu Vijay <so...@yahoo.com>.
The driver you are using is the older outdated one,
try using the new driver.

It coming in the same jar as the one that u are using.

Try using this one: com.mysql.jdbc.Driver ( I'm pretty
confident that this is the name but make sure
anyways).




--- Hassan Abolhassani <ns...@ybb.ne.jp> wrote:
> Hi,
> 
> When I try to connect to a mysql server following
> error appears:
> 
> ...
> [ERROR] AbstractDataSourceFactory - -Property:
> driver
> value:org.gjt.mm.mysql.Driver is not supported by
>
DataSource:org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS
> ...
> 
> Any guide about how to resolve this issue.
> 
> My property file looks like below:
> 
> torque.applicationRoot = .
> log4j.category.org.apache.torque = ALL,
> org.apache.torque
> log4j.appender.org.apache.torque =
> org.apache.log4j.FileAppender
> log4j.appender.org.apache.torque.file =
> ${torque.applicationRoot}/logs/torque.log
> log4j.appender.org.apache.torque.layout =
> org.apache.log4j.PatternLayout
>
log4j.appender.org.apache.torque.layout.conversionPattern
> = %d [%t] %-5p
> %c - %m%n
> log4j.appender.org.apache.torque.append = false
> torque.defaults.pool.logInterval = 0
> torque.defaults.pool.connectionWaitTimeout = 10
> torque.defaults.pool.defaultMaxConnections = 80
> torque.defaults.pool.maxExpiryTime = 3600
> torque.defaults.connection.driver =
> org.gjt.mm.mysql.Driver
> torque.defaults.connection.url =
> jdbc:mysql://127.0.0.1/m3c
> torque.defaults.connection.user = root
> torque.defaults.connection.password = password
> torque.database.default=m3c
> torque.database.m3c.adapter=mysql
>
torque.dsfactory.m3c.factory=org.apache.torque.dsfactory.SharedPoolDataSourc
> eFactory
> torque.dsfactory.m3c.pool.defaultMaxActive=10
> torque.dsfactory.m3c.pool.testOnBorrow=true
> torque.dsfactory.m3c.pool.validationQuery=SELECT 1
> torque.dsfactory.m3c.connection.driver =
> org.gjt.mm.mysql.Driver
> torque.dsfactory.m3c.connection.url =
> jdbc:mysql://127.0.0.1/m3c
> torque.dsfactory.m3c.connection.user = root
> torque.dsfactory.m3c.connection.password = leila168
> torque.idbroker.cleverquantity=true
> torque.manager.useCache = true
> 
> Hassan
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail:
> torque-user-help@db.apache.org
> 


__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

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


Unable to connect to mysql

Posted by Hassan Abolhassani <ns...@ybb.ne.jp>.
Hi,

When I try to connect to a mysql server following error appears:

...
[ERROR] AbstractDataSourceFactory - -Property: driver
value:org.gjt.mm.mysql.Driver is not supported by
DataSource:org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS
...

Any guide about how to resolve this issue.

My property file looks like below:

torque.applicationRoot = .
log4j.category.org.apache.torque = ALL, org.apache.torque
log4j.appender.org.apache.torque = org.apache.log4j.FileAppender
log4j.appender.org.apache.torque.file =
${torque.applicationRoot}/logs/torque.log
log4j.appender.org.apache.torque.layout = org.apache.log4j.PatternLayout
log4j.appender.org.apache.torque.layout.conversionPattern = %d [%t] %-5p
%c - %m%n
log4j.appender.org.apache.torque.append = false
torque.defaults.pool.logInterval = 0
torque.defaults.pool.connectionWaitTimeout = 10
torque.defaults.pool.defaultMaxConnections = 80
torque.defaults.pool.maxExpiryTime = 3600
torque.defaults.connection.driver = org.gjt.mm.mysql.Driver
torque.defaults.connection.url = jdbc:mysql://127.0.0.1/m3c
torque.defaults.connection.user = root
torque.defaults.connection.password = password
torque.database.default=m3c
torque.database.m3c.adapter=mysql
torque.dsfactory.m3c.factory=org.apache.torque.dsfactory.SharedPoolDataSourc
eFactory
torque.dsfactory.m3c.pool.defaultMaxActive=10
torque.dsfactory.m3c.pool.testOnBorrow=true
torque.dsfactory.m3c.pool.validationQuery=SELECT 1
torque.dsfactory.m3c.connection.driver = org.gjt.mm.mysql.Driver
torque.dsfactory.m3c.connection.url = jdbc:mysql://127.0.0.1/m3c
torque.dsfactory.m3c.connection.user = root
torque.dsfactory.m3c.connection.password = leila168
torque.idbroker.cleverquantity=true
torque.manager.useCache = true

Hassan


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


RE: Torque with more dynamic DB connections, avoiding singleton and statics?

Posted by Jiaqi Guo <ch...@hotmail.com>.
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: g-cyclops@users.sourceforge.net
site: http://cyclops-group.sourceforge.net

-----Original Message-----
From: Ekkehard Kraemer [mailto:ekraemer@pluto.camelot.de] 
Sent: Wednesday, December 31, 2003 5:48 AM
To: torque-user@db.apache.org
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: 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