If you don't want to type all those xml tags to generate a simple table, you can ask the program to scan an already present meta-data from a JDBC connection to write those tags for you. Then you can edit only the column definitions to specify the generator that you want to use.
Example 2.2. JDBC Meta Data Input
<project name="InputProject"> <input> <jdbc> <driver name="postgresql"> <jar>/usr/share/java/postgresql.jar</jar> <native></native> <class>org.postgresql.Driver</class> </driver> <connection> <catalog>mbassale</catalog> <schema>public</schema> <url>jdbc:postgresql:mbassale</url> <username>mbassale</username> <password>12345</password> </connection> </jdbc> </input> </project>
Save the file as inputTest.xml
and type
the following command:
bash$
java -jar elgenerador.jar -ehello.xml
The option -e stands for extract. The
program will make the connection and read the metadata for you.
Then it will write a file called inputTest.xml.out
with the table and column definitions present in the data base.
This file can be edited and used to generate the data for those
tables.
You must supply a jdbc data source as input
specification. If the -e
switch is supplied, it will ignore the
metadata
and output
tags.
The JDBC data source is defined in two parts.
The first, driver
defines the location of the
.jar
files, native library directories
and the class name, necessary to load the
driver at runtime and make the connection.
The second, connection
defines the catalog (database name),
schema, url, username and password
to use to connect to the RDBMS.
If the password tag it is not supplied,
it will ask using the standard input.
The program will generate a file with the following contents:
Example 2.3. Input Result
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project name="inputTest"> <metadata create="false" name="Model@7b2be1bd"> <table name="table0_pkey"> <generator row-count="0" /> <column data-type="string" ds-type="varchar" name="col0" size="30"> <generator> <string length="30" /> </generator> </column> </table> <table name="table1_pkey"> <generator row-count="0" /> <column data-type="integer" ds-type="int4" name="col0" size="10"> <generator> <integer max="2147483647" min="-2147483648" /> </generator> </column> </table> <table name="table0"> <generator priority="1" row-count="0" /> <column data-type="string" ds-type="varchar" name="col0" size="30"> <generator> <string length="30" /> </generator> </column> <column data-type="integer" ds-type="int4" name="col1" size="10"> <generator> <integer max="2147483647" min="-2147483648" /> </generator> </column> <primary-key name="table0_pkey"> <column-ref column="col0" /> </primary-key> <foreign-key foreign-table="" name="table0_col1_fkey"> <column-ref foreign="col0" local="col1" /> </foreign-key> </table> <table name="table1"> <generator row-count="0" /> <column data-type="integer" ds-type="int4" name="col0" size="10"> <generator> <integer max="2147483647" min="-2147483648" /> </generator> </column> <column data-type="real" ds-type="float4" name="col1" size="8"> <generator> <real max="1.7976931348623157E308" min="4.9E-324" precision="-1.0" /> </generator> </column> <column data-type="string" ds-type="varchar" name="col2" size="25"> <generator> <string length="25" /> </generator> </column> <primary-key name="table1_pkey"> <column-ref column="col0" /> </primary-key> </table> </metadata> </project>
As you can see, this output must be edited to suit your needs. Also it lacks an output definition, necessary to tell the application were to store the data.