db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Loucks" <aar...@GardnerInc.com>
Subject RE: TorqueInstance & non-static initialization Help!
Date Wed, 18 May 2005 14:40:10 GMT
We use a legacy database running on a VMS system which is nearly
impossible query. There are a few programs written to query specific
data via flat files, but the majority of interaction with it is with a
terminal/telnet session.  Unfortunately, migrating to a modern system
isn't possible at this time. In an effort to provide more functionally
and ease of use to our customers, I want to provide more (web)tools
online to place orders, check order status, view account information,
etc... 

My solution is to simply mirror some of the tables in the legacy
database with mysql. This has been a difficult process, but Torque has
eased the transition. 

My problem now is when the same application needs to access our mirrored
database and some other unrelated database/table. (Both residing in
mysql) What I would like to do is have one api for the mirrored
database, and separate api's for other databases/tables. 

For Example, I'll call our mirrored legacy database 'mirror' which
contains the tables 'product', 'order', and 'customer'. 

mirror
   product
   order
   customer

Now, lets say I have another db named 'salesmen' with tables 'employee'
and 'territory'. Assume this database has no equivalent in the legacy
database.

salesmen
  employee
  territory


Now let's say we have some business operation that requires us to access
both databases. I don't want to build my Torque schema in such a way
that it must encompass all of our databases. I want to segregate the
mirrored database api in order to keep things consistent within it. 

In order for something like this to work, I'd need to do something along
the lines of:

TorqueInstance mirror = new TorqueInstance();
mirror.init("Mirror.properties");

TorqueInstance salesmen = new TorqueInstance();
salesmen.init("Salesmen.properties");


In the event that I would want add another table to the mirrored
database, or perform some other maintenance, I wouldn't affect the
'salesmen' torque api. Also, when one application only requires access
to one of the databases, say 'salesmen', I wouldn't have to load the
'mirror' torque api. 

Perhaps another way to go about this would be to extend the Torque class
and hard code the database names into it per schema. 

static TorqueMirror extends Torque
All references in BaseProduct, Product, BaseProductPeer, ProductPeer
would reference TorqueMirror rather than Torque. (the same for other
tables in this db)

static TorqueSalesmen extends Torque 
All references in BaseEmployee, Product, BaseEmployeePeer, EmployeePeer
would reference TorqueSalesmen rather than Torque. (the same for other
tables in this db)

Then we could initialize by:
TorqueMirror.init("mirror.properties");
TorqueSalesmen.init("salesmen.properties");



I understand that I can multiple databases in the torque schema, but I
want to avoid having one torque generated api to encompass any and all
database access. 


Aaron



 


-----Original Message-----
From: Thomas Fischer [mailto:fischer@seitenbau.net] 
Sent: Wednesday, May 18, 2005 8:46 AM
To: Apache Torque Users List
Subject: RE: TorqueInstance & non-static initialization Help!





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


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