You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by svallet <sv...@t-systems.fr> on 2003/04/29 16:19:11 UTC

Using generator directly from Java ?

Hi !

I'm trying to use Torque's Generator directly from Java, possibly without
using Ant.
I think I figured out how to get an AppData out of XML, but I'm a bit lost
when it comes to transform this AppData to SQL.

Any hint ?

Simon

--
Simon Vallet
T-Systems e-technologies
svallet@t-systems.fr


RE: Using generator directly from Java ?

Posted by svallet <sv...@t-systems.fr>.
Ok, I found an answer in the archives... wanted to do the things too fast

So I do the following :

set some properties
[...]
torqueSQLTask.initControlContext();
torqueSQLTask.execute();
torqueSQLTask.getDataModels().clear();

It works fine, but when I look at the generated SQL, the tables are
generated twice
for example :

--- begin generated file ---

# -----------------------------------------------------------------------
# ADOPTION
# -----------------------------------------------------------------------
drop table if exists ADOPTION;

CREATE TABLE ADOPTION
(
        ID_ADOPTION INTEGER NOT NULL AUTO_INCREMENT,
        ID_PARENT INTEGER,
        TABLE_PARENT VARCHAR (16),
        ID_ENFANT INTEGER NOT NULL,
        TABLE_ENFANT VARCHAR (16) NOT NULL,
    PRIMARY KEY(ID_ADOPTION)
);


# -----------------------------------------------------------------------
# ADOPTION
# -----------------------------------------------------------------------
drop table if exists ADOPTION;

CREATE TABLE ADOPTION
(
        ID_ADOPTION INTEGER NOT NULL AUTO_INCREMENT,
        ID_PARENT INTEGER,
        TABLE_PARENT VARCHAR (16),
        ID_ENFANT INTEGER NOT NULL,
        TABLE_ENFANT VARCHAR (16) NOT NULL,
    PRIMARY KEY(ID_ADOPTION)
);

--- end generated file ---

The schema is here :
&lt;?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?&gt;
&lt;!DOCTYPE database SYSTEM "database.dtd"&gt;

<database name="catgen2" defaultIdMethod="idbroker">

<table name="ADOPTION" skipSql="false">
<column name="ID_ADOPTION" type="INTEGER" required="true"
autoIncrement="true" primaryKey="true"/>
<column name="ID_PARENT" type="INTEGER" required="false"/>
<column name="TABLE_PARENT" type="VARCHAR" size="16" required="false"/>
<column name="ID_ENFANT" type="INTEGER" required="true"/>
<column name="TABLE_ENFANT" type="VARCHAR" size="16" required="true"/>
</table>

</database>

I didn't notice this when running Torque/ant from the command-line.
Is it possible that using it directly from a Java Class causes this ?
I wonder what I may have done wrong...

Thanks for any suggestions,
Simon