You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by to...@db.apache.org on 2004/03/03 17:23:24 UTC

[DB Torque Wiki] Updated: TorqueProjectPages/GettingTorqueToWork

   Date: 2004-03-02T12:37:22
   Editor: 166.70.24.15 <>
   Wiki: DB Torque Wiki
   Page: TorqueProjectPages/GettingTorqueToWork
   URL: http://wiki.apache.org/db-torque/TorqueProjectPages/GettingTorqueToWork

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -182,3 +182,38 @@
  1. Now, admittedly the torque.props is hardcoded, but this should get you started.  Just make sure all your constructors do call the <code>super( name)<code> method!
 - EricPugh
 
+
+----
+== Using Torque with multiple databases ==
+
+This section deals with the trials and tribulations of using multiple databases with Torque.
+
+It's fairly easy to get multiple databases working.  The following examples assume you are using JNDI, since it's what I know best, but the differences are restricted to the torque.properties file. Start off by choosing a ''handle'' name for each of the databases to which you will connect.  In this example there will be two databases, with handles '''dbA''' and '''dbB'''.  Do the following:
+
+ 1. In the schema file for '''dbA''', the <database> element must have a ''name'' attribute with value '''dbA'''.  Likewise for the '''dbB''' schema file.  When the object model files are generated (by ''ant -f build.properties om''), the name will be hard-coded in them, and cannot be overriden.
+
+ 2. In the torque.properties file, create an adapter for each of your databases:
+
+ {{{
+torque.database.dbA.adapter=mysql
+torque.dsfactory.dbA.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
+torque.dsfactory.dbA.jndi.path=java:comp/env/jdbc/dbA
+
+torque.database.dbB.adapter=mysql
+torque.dsfactory.dbB.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
+torque.dsfactory.dbB.jndi.path=java:comp/env/jdbc/dbB
+ }}}
+
+ [Note: your JNDI path may be different!]
+
+ The key point here is the handle, emphasized in ''torque.database.'''dbA'''.adapter=mysql''.  The torque.properties file handles and the handles in the schema files must correspond.  This is the a fundamental issue with getting multiple databases working with Torque.
+
+ 2. Every use of the database in the code must reference a handle [this is a simplification, there is a ''default'' handle, and rules for automatic creation of a default handle, but... let's not go there].  Here is an example:
+
+ {{{
+  Criteria criteria = new Criteria("dbA");
+  criteria.add(SomePeer.SOME_FIELD, "some value");
+  SomePeer.doDelete(criteria);
+}}}
+
+ -- Gary Shea

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