--- Craig Longman <[EMAIL PROTECTED]> wrote:
> so, assuming these properties:
> 
> db.host=somehost.begeek.com
> db.port=1234
> db.dbname=test_db
> db.uid=dba
> db.pwd=dba

> db.type.pgsql=true
>  OR
> db.type.db2=true

If you're going to pass the type in on the command line -- eg:
  $ ant -Dtype=db2 deploy   # or whatever you call your deployment target
you can reduce your "init" target's <antcall>'s to only one, which has:
  <antcall target="db.${type}"/>
and change the db-pgsql and db-db2 targets to use <propertyfile> to add
the properties they set to the "dbconfig.properties" file (or whatever
you're calling the file that has db.host, etc. in it) instead. Then have
"init" read the file in. Get rid of all the 'depends' and 'if's (and the
props they were if'ing against) and the check-db-config target.

In other words:

dbconfig.properties:

db.host=somehost.begeek.com
db.port=1234
db.name=test_db
db.uid=dba
db.pwd=dba

Targets:
<target name="deploy" depends="dbconfig">
  <echo message="db.host   = ${db.host}"/>
  <echo message="db.port   = ${db.port}"/>
  <echo message="db.name   = ${db.name}"/>
  <echo message="db.uid    = ${db.uid}"/>
  <echo message="db.pwd    = ${db.pwd}"/>
  <echo message="db.url    = ${db.url}"/>
  <echo message="db.driver = ${db.driver}"/>
</target>

<target name="dbconfig">
  <antcall target="db-${type}"/>
  <property file="dbconfig.properties"/>
</target>

<target name="db-db2">
  <propertyfile file="dbconfig.properties">
    <entry key="db.url"
value="jdbc:db2:${db.host}:${db.port}/${db.name}"/>
    <entry key="db.driver" value="COM.ibm.db2.jdbc.net.DB2Driver"/>
  </propertyfile>
</target>

<target name="db-pgsql">
  <propertyfile file="dbconfig.properties">
    <entry key="db.url"
           value="jdbc:postgresql://${db.host}:${db.port}/${db.name}"/>
    <entry key="db.driver" value="org.postgresql.Driver"/>
  </propertyfile>
</target>

$ ant -Dtype=db2 deploy
db-db2:
     [propertyfile] Updating property file: dbconfig.properties

deploy:
     [echo] db.host   = somehost.begeek.com
     [echo] db.port   = 1234
     [echo] db.name   = test_db
     [echo] db.uid    = dba
     [echo] db.pwd    = dba
     [echo] db.url    = jdbc:db2:somehost.begeek.com:1234/test_db
     [echo] db.driver = COM.ibm.db2.jdbc.net.DB2Driver

Note: If your "dbconfig.properties" file is source-controlled, so it ends
up being read-only in your build tree, you'll need to work that out.

Diane

=====
([EMAIL PROTECTED])



__________________________________________________
Terrorist Attacks on U.S. - How can you help?
Donate cash, emergency relief information
http://dailynews.yahoo.com/fc/US/Emergency_Information/

Reply via email to