db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard Lin" <Howard....@vonage.com>
Subject RE: Configuration for different databases
Date Mon, 03 Mar 2003 17:35:22 GMT
Torque run time supports multiple database configuration but not at "generation" time. Here
is the quote from that tutorial:
"It is worth re-iterating that these run-time properties are not used by Torque when generating
your object model and creating your database. They are used only by the application utilizing
the Torque-generated object model classes at run-time."

My understanding of Martin's request is that he wants to generate sql scripts at build time,
not run time. 

My own experience was to use torque-jdbc task to generate om classes for different databases.
So instead of editing build-torque.properties for different databases, 
what I did was to create a master build-torque.properties file, with tokens for database name,
user-name, password etc. Something like this:

torque.database.createUrl = @DATABASE_URL@
torque.database.buildUrl = @DATABASE_URL@
torque.database.url = @DATABASE_URL@
torque.database.driver = @DATABASE_DRIVER@
torque.database.user = @DATABASE_USER@
torque.database.password = @DATABASE_PASSWORD@
torque.database.host = @DATABASE_HOST@
torque.database.schema = @DATABASE_SCHEMA@
torque.database.name = @DATABASE_NAME@

And then create a filter file for each database, with values for those tokens. Something like

DATABASE_URL = jdbc:mysql://
DATABASE_DRIVER = org.gjt.mm.mysql.Driver

Then in your build.xml, you can do this:

<target name="torque-jdbc-filter" if="torque.jdbc.filtersfile">
		<delete file="build-torque.properties"/>
		<filter filtersfile="${torque.jdbc.filtersfile}"/>
		<copy file="build-torque-master.properties" tofile="build-torque.properties" filtering="true"/>
		<antcall target="torque-jdbc"/>

When you call ant, you can specify which filter file to use (as a property). For the sql task,
it didn't use so many properties (I think only ${torque.database} is relevant) so you only
need to use one token.

Let me know if there are any simpler ways to do this. Now in the torque 3.1 development version,
generation part is separated from run time but I'm not sure if it supports multiple databases.

Howard Lin

> -----Original Message-----
> From: Eric Emminger [mailto:eric@ericemminger.com]
> Sent: Monday, March 03, 2003 12:06 PM
> To: Turbine Torque Users List
> Subject: Re: Configuration for different databases
> Martin and Howard
> Please, correct me if I'm wrong, but I'm pretty sure you CAN 
> do this in 
> Torque without special Ant stuff. I believe it would look like the 
> following.
> torque.database.mysql=yourdb
> torque.database.mysql.username=mysqluser
> torque.database.db2=yourdb
> torque.database.db2.username=db2user
> . . .
> See the tutorial.
> http://db.apache.org/torque/tutorial/step2.html
> Eric
>  >>I am searching for a simple way for handling different database
>  >>configurations with one configuration file.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

View raw message