Everything Java Apache Geospatial Open Source. Hello Shinning Stars!!! Vincent Massol, Raphael Luta, Santiago Gala, Carsten Z.

Thursday, July 29, 2004

XML Data Binding Resources - A resource archive of xml binding tools.

Thursday, July 22, 2004

HowTo get the most out of open source database mapping tools. Which one should I choose? Castor, Hibernate, Ojb, Torque.

Tuesday, July 06, 2004

Up until now I am putting in practice XMLBeans, Ojb, and Castor. Let's just say I like diversity. So from the bottom up it would be described this way. We have a database schema which I need to represent in xml. So I use Ojb 1.0.0 ReverseDB tool (org.apache.ojb.tools.mapping.reversedb.Main in the db-ojb-1.0.0-tools.jar) to create a xml and all the JavaBeans that I need for Castor. This xml is very nice, it describes all the tables, columns, primary and foreign keys, relations, collections that exist in our database schema. This will help me when using Castor.

I need a mapping file for Castor so I wrote a small xslt to convert my database xml into a mapping xml. Here it is :

<?xml version="1.0" encoding="UTF-8"?>
<!-- Warning the key-generator="SEQ" has to be added manually to mapping.xml -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<mapping>
<key-generator name="SEQUENCE" alias="SEQ">
<param name="sequence" value="seq_id"/>
</key-generator>
<xsl:apply-templates/>
</mapping>
</xsl:template>
<xsl:template match="class-descriptor">
<xsl:if test="field-descriptor[@primarykey='true']">
<class>
<xsl:attribute name="identity"><xsl:for-each select="field-descriptor[@primarykey='true']"><xsl:value-of select="concat(@name, ' ')"/></xsl:for-each></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="concat('db.finaixm.', @class)"/></xsl:attribute>
<map-to>
<xsl:attribute name="table"><xsl:value-of select="@table"/></xsl:attribute>
</map-to>
<xsl:apply-templates/>
</class>
</xsl:if>
</xsl:template>
<xsl:template match="field-descriptor">
<field>
<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
<xsl:attribute name="type"><xsl:choose><xsl:when test="@jdbc-type = 'DECIMAL'">long</xsl:when><xsl:when test="@jdbc-type = 'VARCHAR'">string</xsl:when><xsl:when test="@jdbc-type = 'TIMESTAMP'">timestamp</xsl:when></xsl:choose></xsl:attribute>
<sql>
<xsl:attribute name="name"><xsl:value-of select="@column"/></xsl:attribute>
</sql>
</field>
</xsl:template>
</xsl:stylesheet>

Here is a quick Ant task to run it,

<target name="finaixm-mapping">
<echo>Building Castor mapping file</echo>
<xslt style="xslt/oracle2mapping.xslt" in="oracle.xml" out="etc/mapping.xml" />
</target>

I also want to manipulate xml files that conform to a given xml schema. So I use XMLBeans to read the schema and create a parser and custom API for the given schema. Practical! So I've got JavaBeans on both sides, all I need to do now is apply business logic to some Velocity templates that can import xml to the database and export from the database to xml. Thanks to the Open Source community.

Friday, July 02, 2004

Hierarchial database inserts can be made using Castor. The difficulty becomes creating the hierachial object.
An interesting trend is to see Open Source binaries distributed with the code source CVS tree. Velocity 1.4 is an example.