db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: TorqueInstance & non-static initialization Help!
Date Wed, 18 May 2005 12:46:02 GMT




Hi Aaron,

at the moment, the TorqueInstance is a singleton, and as such, it is not
possible to have multiple instances at the moment.
I believe that this can not be changed easily. E.g. the peer classes rely
on TorqueInstance being a Singleton for retrieving a connection, and I see
no easy way to tell the Peer clases which instance they should use, if
there are multiple instances.

What do you need the multiple instances of Torque for ?

      Thomas


"Aaron Loucks" <aaronl@GardnerInc.com> schrieb am 18.05.2005 14:14:51:

>
> EDIT:
> Criteria c = new Criteria(ProductPeer.DATA_BASE_NAME);
>
>
> From: Aaron Loucks [mailto:aaronl@GardnerInc.com]
> Sent: Tuesday, May 17, 2005 5:02 PM
> To: Apache Torque Users List
> Subject: TorqueInstance & non-static initialization Help!
>
> I'm trying to initialize torque in a non-static way so that I can have
> multiple instances (for different databases/functionality) in a single
> web application.
>
> I tried initializing a TorqueInstance and pass the database name and
> connection to a peer class, without success:
>
> ...
>
> TorqueInstance torqueInstance = new TorqueInstance();
> torqueInstance.setConfiguration(config);
> torqueInstance.initalize();
>
> Criteria c = ProductPeer.DATABASE_NAME;
>
> List list = ProductPeer.doSelect(c, torqueInstance.getConnection());
>
>
> java.lang.NullPointerException
>    at
> org.apache.torque.TorqueInstance.getDB(TorqueInstance.java:772)
>    at org.apache.torque.Torque.getDB(Torque.java:299)
>    at
> org.apache.torque.util.BasePeer.createQuery(BasePeer.java:918)
>    at org.apache.torque.util.BasePeer.doSelect(BasePeer.java:1221)
>    at
> test.torque.BaseProductPeer.doSelectVillageRecords(BaseProductPeer.java:
> 664)
>    at
> test.torque.BaseProductPeer.doSelect(BaseProductPeer.java:607)
>    at test.torque.Product.lookup(Product.java:318)
>    at test.actions.Test1.execute(Test1.java:63)
>
> ...
>
> I looked into the source code a bit, and saw that the static Torque
> wrapper creates a new instance of TorqueInstance if the static
> torqueSingleton is null. This leads me to believe that what I'm trying
> to do isn't possible, but according to the change log, this feature was
> implemented long ago:
>
>
> Release 3.1-BETA1 - 2003-08-19
> update     Introduced the TorqueInstance class to do away with
> static initialization woes and allow multiple instances of Torque per
> ClassLoader.
>
>
> Apparently, I'm missing something... Any help would be highly
> appreciated.
>
>
>
>
> Aaron Loucks
> Web Developer
> Gardner, Inc.
> 3641 Interchange Road
> Columbus, OH 43204
> 614.456.3492
>
> ---------------------------------------------------------------------
> 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