Hi Thomas, 
Can you please give me a specific pointer on where you call Ant tasks
from within a program.  I use HSQL as my database and would find this
really useful.
Thanks in advance.
Raghavan

-----Original Message-----
From: Thomas Dudziak [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 20, 2003 1:22 AM
To: OJB Users List
Subject: Re: Auto create tables in the DB




On Wed, 19 Nov 2003, Gus Heck wrote:

> Well things seem to be moving along, and I finally have tamed enough 
> of
> struts, xdoclet and OJB configuration  and understood enough JDO to 
> actually get to the point where my web app tries to write to the 
> database. (YEA!) I was not supprised however to get this exception:
> 
> java.sql.SQLException: General error,  message from server: "Table
'fdbtest2.LocationBase' doesn't exist"
>       at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1825)
>       at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1020)
> 
> I kinda figured that I handn't yet done anything to propogate the 
> tables
> into the database. XDoclet is nicely generating my repository_user.xml

> file, and I am wondering if there is a way to push the tables into the

> database (based on the repository.xml file) at runtime. Ideally, I
would 
> like the following in the end:
> 
>  From my ant file;
> reload (with tomcat ant task) mode.testing = true
>   -  drop the test database
>   -  recreate the test database
>   -  create the tables
>   -  run the app.
> 
> reload (with tomcat ant task) mode.testing = false
>   -  DO NOT drop the test database
>   -  add any tables that are missing (new classes to persist) to the
> database
>   -  run the app.
> 
> The first scenario basically mirrors the unit test test database setup

> I
> think, but the second seems to require the ability to do a create if 
> needed, which I suspect won't be easy from ant (unless I write a
custom 
> task, which is somthing I might consider doing). I am hopping that
there 
> is a nice easy way to push tables into the database (using OJB from 
> java), if they don't exist. (but I havn't found it yet in the docs) 
> Since It didn't jump out at me I was wondering if this is something 
> already well know to people on this list. If I can do it via 
> configuration settings for the OJB back end and not venture beyond the

> JDO API in my code that would be nice too, but I expect that that is 
> probably asking too much.
> 
> Seeking suggestions....

The xdoclet ojb module can generate both the repository descriptor and a
torque database schema. Since your database (MySQL it seems) is
supported by Torque, you can use it to push the database schema into the
database (see the xdoclet ojb module docs, there is a short example on
how to do this). You can even have data in a separate xml file that
torque imports into the database (there are targets in the torque build
file - build-torque.xml - that generate the dtd for this data xml file,
and that import/export the data xml file). You can also invoke the ant
targets from code, e.g. at runtime, though this is a bit more tricky
(invoking ant from within a program, that is). I do that in the unit
tests for the xdoclet ojb module.

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to