First lets make sure we have all the definitions correct here because the term "database name" has been WAY overloaded and folks get the variations confused.
Torque's Schema Database name: This is a compile time value that is used to connect the OM layer objects with their schema info (Map objects) and find the DB connection info. DB Server Database name: This is a DB specific collection of tables, e.g. a Catalog in MySQL, a Database in MS SQL, and the like. The only relationship between these two "database names" is that the Torque initialization properties map the Schema database name to the Server Database name. Specifically, via the JDBC connection info. That said, the base question here is: What are you trying to accomplish here. Are you are trying to have MULTIPLE application instances (e.g. different web apps) using the same OM layer but accessing different Database server databases? Maybe with the server info coming from some external source (e.g. user supplied property or a DB table). In this case, it easy to dynamically create a Configuration object that maps the Torque database schema name to your DB Server database. Then use this with the Torque.init(Configuration ) method. If you are trying to use the same OM layer in the SAME application to access different server databases, life becomes a lot more complicated. You have to start thinking about multiple threads using different DB info (in both senses of the word) and how not to have transactions start on one server and end on another (because another thread changed the DB info). Currently, the best way to do this is to write your code using the methods that include a Connection object, e.g, RecordPeer.doSelect(c, conn); For the most part, these methods will perform the actions using the specified connections. I think most of the areas that used to "automagically" get connection have been fixed so any method with a connection specified will use it all the way down. That said, you can then use Torque's DB pooling to manage your connections by using the Torque.getConnection(DBName) method and initializing Torque with multiple Schema database names. These can be in your Torque init properties file or dynamically created (as per above). > -----Original Message----- > From: Mehmet Erdem [mailto:[EMAIL PROTECTED] > Sent: Wednesday, April 18, 2007 11:40 AM > To: torque-user@db.apache.org > Subject: How to make the default database settable during runtime? > > Hi, > > I am using Torque 3.2 and I try to make the default database settable > during runtime. > > I created a class DefaultDatabase with a static method getName() that > takes the default > database name from a property file. > > Then I modified the MapBuilder.vm and Peer.vm to refer to > this getName() > method instead of the template variable $table.Database.Name. > > MapBuilder.vm: > > < dbMap = Torque.getDatabaseMap(DefaultDatabase.getName()); > --- > > dbMap = Torque.getDatabaseMap("$table.Database.Name"); > > > Peer.vm: > > < public static final String DATABASE_NAME = > DefaultDatabase.getName(); > < > --- > > public static final String DATABASE_NAME = > "$table.Database.Name"; > > > > > So is this the right way to make the default database > settable. Or did I > miss something ? It seems > unlikely that I am the only one so far who wants to change > the database > without regenerating > classes. > > Thanks, > > Mehmet Erdem > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > Duke CE Privacy Statement Please be advised that this e-mail and any files transmitted with it are confidential communication or may otherwise be privileged or confidential and are intended solely for the individual or entity to whom they are addressed. If you are not the intended recipient you may not rely on the contents of this email or any attachments, and we ask that you please not read, copy or retransmit this communication, but reply to the sender and destroy the email, its contents, and all copies thereof immediately. Any unauthorized dissemination, distribution or copying of this communication is strictly prohibited. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]