db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Malcolm Kendall" <mikend...@blueyonder.co.uk>
Subject RE: Multiple Database
Date Mon, 02 Jun 2003 19:47:45 GMT
Hi Damien,
I had a similar problem and ended up modifying the Base Peer and Map files,
where the DATABASE_NAME is used. The java code represents a logical database
and the database name represents a physical mapping. With one more level
of indirection alot of this type of problem could be solved. Whether this
approach works when changing at runtime you would have to try, (mine only set
up the database name during static initialisation), - probably a complete can
of worms but should be fun trying. 

-----Original Message-----
From: Damien SAUVAGEOT [mailto:dsauvageot@omnikles.com]
Sent: 26 May 2003 16:35
To: Turbine Torque Users List (E-mail)
Subject: Multiple Database


I am new to torque and I am facing a problem connecting to multiples databases using
the same java code generated by torque.
I need to connect to 2 databases (A and B) defined with the same XML torque schema.
In order to process a select, I do : 

Connection c = null;
c = DriverManager.getConnection(getDburl(),getDbusername(),getDbpass());
List v;
v = AliasPeer.doSelect(crit, c);

This connect to the database A and works fine, 
I then iterate on the 'v' list :
                    while (i.hasNext()) {
                        Alias alias = (Alias) i.next();

and then need to retrieve a object customer which is a foreign key
in alias. So alias.getCustomer() should retrieve me that object.
In fact, it seems to retrieve it from the B database as in BaseCustomersPeer.java
there is 
    public static final String DATABASE_NAME = "B";
which is used by 
    public static Customers retrieveByPK(ObjectKey pk)
        throws TorqueException {
        Connection db = null;
        Customers retVal = null;
        try {
            Log.getAppLogger().info("database connection : " + DATABASE_NAME);
            db = Torque.getConnection(DATABASE_NAME);
            retVal = retrieveByPK(pk, db);
        } finally {
        return (retVal);

Does it mean that torque needs to generate java files for each database even if it is the
same database?
I could always give the connection c as I do for do Select, but this is not working for all
functions as
in this case.

Does someone has a solution?


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

View raw message