Getting started with XMLGenerator

63 views
Skip to first unread message

Daniel Einspanjer

unread,
Dec 23, 2016, 1:43:25 PM12/23/16
to jOOQ User Group
I managed to get an XML schema generated for the SQL Server database I'm working on:
<generator>
<name>org.jooq.util.XMLGenerator</name>
<database>
<name>org.jooq.util.sqlserver.SQLServerDatabase</name>
<inputCatalog>${jooq-codegen.my-database}</inputCatalog>
<outputCatalog>mydb</outputCatalog>
<inputSchema>dbo</inputSchema>
</database>
<target>
<packageName>xxx</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>


I then tried to read it in to generate some java classes:

<database>
<name>org.jooq.util.xml.XMLDatabase</name>
<properties>
<property>
<key>xml-file</key>
<value>${project.basedir}/src/xml-schemas/mydb/information_schema.xml</value>
</property>
</properties>
<inputCatalog>mydb</inputCatalog>
<outputCatalog>mydb</outputCatalog>
<inputSchema>dbo</inputSchema>
<includes>
^(A|B|C).*
</includes>
<excludes></excludes>
</database>
<generate>
<deprecated>true</deprecated>
<instanceFields>true</instanceFields>
<immutablePojos>true</immutablePojos>
<validationAnnotations>true</validationAnnotations>
<globalCatalogReferences>false</globalCatalogReferences>
<javaTimeTypes>true</javaTimeTypes>
</generate>
<target>
<packageName>com.example.data.db.entities</packageName>
<directory>target/generated-sources/jooq</directory>
</target>

And it generated!  Unfortunately, it looks like all the integer based fields are getting mapped to Object.

public class CountryCode implements Serializable {

private static final long serialVersionUID = 2091889765;

private final Object Id;
private final Object CountryCode;
...


The generated information_schema.xml file has these columns defined as:

<column>
<table_catalog>mydb</table_catalog>
<table_schema>dbo</table_schema>
<table_name>CountryCode</table_name>
<column_name>Id</column_name>
<data_type>int</data_type>
<character_maximum_length>0</character_maximum_length>
<numeric_precision>10</numeric_precision>
<numeric_scale>0</numeric_scale>
<ordinal_position>1</ordinal_position>
</column>
<column>
<table_catalog>mydb</table_catalog>
<table_schema>dbo</table_schema>
<table_name>CountryCode</table_name>
<column_name>CountryCode</column_name>
<data_type>int</data_type>
<character_maximum_length>0</character_maximum_length>
<numeric_precision>10</numeric_precision>
<numeric_scale>0</numeric_scale>
<ordinal_position>2</ordinal_position>
</column>


What might be going on to cause it to fail to map back to integer?

-Daniel

Daniel Einspanjer

unread,
Dec 23, 2016, 1:53:49 PM12/23/16
to jOOQ User Group
Aha.  I was missing the property telling it what dialect to use.  This configuration caused it to use Integer types as expected:

<database>
<name>org.jooq.util.xml.XMLDatabase</name>
<properties>
<property>
            <key>dialect</key>
<value>SQLSERVER</value>
</property>
<property>
<key>xml-file</key>

-Daniel

Lukas Eder

unread,
Dec 28, 2016, 5:54:44 AM12/28/16
to jooq...@googlegroups.com
Thanks for documenting this, Daniel.

While it is correct that you should specify the SQLDialect for best results, there's still a bug hidden in there. The exported data type is SQL Server's INT type, which should work out of the box when re-importing the XML. The point being that there should either be:

- Some standardisation when exporting
- Some lenience when importing

Probably, standardisation is the cleaner approach. I've registered an issue for this:

Thanks again for reporting!
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages