I use the following xsl to convert the repository file to torque-style schema.
It handles indexes and foreign keys. For indexes you have to add an index
attribute to the field descriptors. For this project every class has an cld
for an interface and then a cld for the implementation with all the fields, so
if you have a different setup you may have to adjust this.
I think this should work with Torque as well, but we use a patched version of
commons-sandbox/sql to do the ddl. If you just want to create full create ddl
from an ant task then the code in cvs is good enough. I patched it to allow
creation of ddl that will alter an existing db to bring it up to date with the
current schema. It also allows you to do this from code and not just ant, so
we actually ensure the db is up-to-date on each startup via the factory that
configures OJB. I submitted the patch but it was never taken. If you search
the commons-dev archives you can find it.
Here's how our repository looks:
<class-descriptor class="ABC">
<extent-class class-ref="ABCImpl" />
</class-descriptor>
<class-descriptor
class="ABCImpl"
table="abc"
>
<field-descriptor id="1"
name="xyz"
column="xyz"
jdbc-type="INTEGER"
nullable="false"
indexed="true"
/>
</class-descriptor>
John Marshall
Connectria
>===== Original Message From Eli Anderson <[EMAIL PROTECTED]> =====
>Dave,
>
>download the contrib.tgz file and take a look at the ojb module for
>xdoclet. I haven't tried it for generating the torque XML file but when
>I read the documentation it appears to have the functionality you want.
>
>
>
>
>On Mon, 2003-08-04 at 16:11, Durham David Contr 805 CSS/SCBE wrote:
>> I would like to generate the DDL from the class-definitions in
>> repository.xml. I see that the unit tests that come with OJB use Torque
>> to generate DDL. Is there a way to take the repository.xml and run it
>> through Torque? It seems like a transformation might be in order to
>> take the data from the repository.xml format and put it in Torque's
>> format. (As you may be able to tell, I'm not very experienced with XML)
>> I'm wondering if anyone else on the list has a solution for this
>> problem.
>>
>> Thanks,
>>
>>
>> Dave
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>--
>Eli Anderson
>
>
>--=-XZqpeUFzQyBxcp2QpDbT
>Content-Type: application/pgp-signature; name=signature.asc
>Content-Description: This is a digitally signed message part
>
>-----BEGIN PGP SIGNATURE-----
>Version: GnuPG v1.2.1 (GNU/Linux)
>
>iD8DBQA/Lx2UKBM7jJD0qewRAjcvAKDHtkcRgxxff7R3kf73uXjlupzceACeNNke
>76HeZnITOFVOoh461U87d3w=NCE+
>-----END PGP SIGNATURE-----
>
>--=-XZqpeUFzQyBxcp2QpDbT--
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" indent="yes" xalan:indent-amount="4" />
<xsl:template match="/">
<xsl:text disable-output-escaping="yes">
<!DOCTYPE database SYSTEM "http://jakarta.apache.org/turbine/dtd/database.dtd">
</xsl:text>
<database name="xyz">
<xsl:apply-templates select="//class-descriptor[string-length(@table) > 0]" />
</database>
</xsl:template>
<xsl:template match="class-descriptor">
<table name="[EMAIL PROTECTED]">
<xsl:apply-templates mode="column" select="field-descriptor" />
<xsl:apply-templates mode="index" select="[EMAIL PROTECTED]'true']" />
<xsl:apply-templates select="reference-descriptor" />
</table>
</xsl:template>
<xsl:template mode="column" match="field-descriptor">
<column>
<xsl:attribute name="name"><xsl:value-of select="@column" /></xsl:attribute>
<xsl:attribute name="type"><xsl:value-of select="@jdbc-type" /></xsl:attribute>
<xsl:attribute name="primaryKey"><xsl:value-of select="@primarykey" /></xsl:attribute>
<xsl:if test="@nullable='false'">
<xsl:attribute name="required">true</xsl:attribute>
</xsl:if>
<xsl:if test="@nullable='true'">
<xsl:attribute name="required">false</xsl:attribute>
</xsl:if>
<xsl:if test="@autoincrement='true'">
<xsl:attribute name="autoIncrement">true</xsl:attribute>
</xsl:if>
<xsl:if test="@conversion">
<xsl:attribute name="converter"><xsl:value-of select="@conversion" /></xsl:attribute>
</xsl:if>
<xsl:if test="@length">
<xsl:attribute name="size"><xsl:value-of select="@length" /></xsl:attribute>
</xsl:if>
</column>
</xsl:template>
<xsl:template mode="index" match="field-descriptor">
<xsl:variable name="index_name">
index_<xsl:value-of select="../@table"/>_<xsl:value-of select="@column"/>
</xsl:variable>
<index name="{normalize-space($index_name)}">
<index-column name="[EMAIL PROTECTED]"/>
</index>
</xsl:template>
<xsl:template match="reference-descriptor">
<xsl:variable name="temp-class-ref" select="@class-ref" />
<!-- may need to redirect from an interface to an impl, or may not, so handle both -->
<xsl:variable name="impl-class">
<xsl:value-of select="//[EMAIL PROTECTED]/extent-class/@class-ref" />
</xsl:variable>
<xsl:variable name="impl-class2">
<xsl:if test="string-length($impl-class) > 0">
<xsl:value-of select="$impl-class" />
</xsl:if>
<xsl:if test="string-length($impl-class) = 0">
<xsl:value-of select="$temp-class-ref" />
</xsl:if>
</xsl:variable>
<xsl:variable name="foreign-table">
<xsl:value-of select="//[EMAIL PROTECTED]/@table" />
</xsl:variable>
<xsl:variable name="temp-field-name" select="foreignkey/@field-ref" />
<xsl:variable name="local-field" select="../[EMAIL PROTECTED]/@column" />
<xsl:variable name="foreign-field" select="//[EMAIL PROTECTED]/[EMAIL PROTECTED]'true']/@column" />
<foreign-key foreignTable="{$foreign-table}">
<reference local="{$local-field}" foreign="{$foreign-field}" />
</foreign-key>
</xsl:template>
</xsl:stylesheet>---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]