Chapter 2. Tutorial

Table of Contents

Hello World.
Hello World! Explanation.
I don't want to type.
Explanation.
Input Result.

In this tutorial we will explain how to use this tool with some examples.

Hello World.

Lets say that you want to generate just one table with the following diagram:

You have to create the following XML file:

Example 2.1. Hello World XML file.

				
<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloProject">
	<metadata create="true">
		<table name="HelloWorld">
			<generator row-count="1000" />
			<column name="id" data-type="integer">
				<generator>
					<integer min="0" />
				</generator>
			</column>
			<column name="message" data-type="string" size="15">
				<generator>
					<script language="javascript">
						value = "Hello World!";
					</script>
				</generator>
			</column>
			<column name="some_integer" ds-type="INT">
				<generator>
					<integer min="-24" max="45" />
				</generator>
			</column>
			<column name="some_real" data-type="real">
				<generator>
					<real min="-1" max="8" precision="3" />
				</generator>
			</column>
			<column name="some_date" data-type="DATE">
				<generator>
					<date min="01/01/01" max="01/01/10" />
				</generator>
			</column>
			<column name="some_time" data-type="TiMe">
				<generator>
					<time min="1:20 AM" max="6:30 PM" />
				</generator>
			</column>
			<column name="some_phone" ds-type="varchar" size="20">
				<generator>
					<phone template="+56-32-XXXXXXX" />
				</generator>
			</column>
			<column name="some_string" data-type="STRING" size="10">
				<generator>
					<printf format="%d-%s">
						<integer min="1" max="4" />
						<string length="4" />
					</printf>
				</generator>
			</column>
			<primary-key>
				<column-ref column="id" />
			</primary-key>
		</table>
	</metadata>
	<output>
		<csv header="true" prefix="table" suffix=".csv" />
	</output>
</project>
				
                    

Save the file as hello.xml. To generate the data run the following command:

bash$ java -jar elgenerador.jarhello.xml
                

You will see how the program generates the data and creates in the working directory a file named tableHelloWorld.csv that contains the generated comma separated values.

Hello World! Explanation.

  1. The XML file always must start with a project tag. Optionally you can specify a name for this project. You can specify a random-seed attribute, that will be user as a numeric seed for the generators, so if you supply the same seed, the generated data will be identical.

  2. Then you can specify the metadata that defines the generated tables with its columns and data types. If the create attribute is true the tables will be re-created in the output data source.

  3. Define one or several table tags. They must have at least a name attribute defined, and is preferrable to define the generator tag and set as attribute the row-count that will define the number of rows to generate. If this tag is not included, the program will not generate the table.

  4. Define one or several column tags. They must have at least a name and a data-type or ds-type tags defined. The tag data-type stands for the application generic data type, there are several generic data types available. The tag ds-type stands for data-source data type, this type can be any type that the underliying RDBMS supports. Data types are case insensitive. If you select any string or byte string data type you must supply the size, if it is not supplied, the application will take 32 characters or bytes of length.

  5. Define a generator tag. That will contain the selected column generator. If a generator is not supplied, the program will pick one compatible with the data type with a default configuration.

  6. Define the concrete generator to use, the program will not check for compatibility, for now you can put a string generator for a integer column, but it will raise an error at the data insertion moment.

  7. Define, if it is necessary, one or more contraints like, primary keys or foreign keys. In this example, id is the primary key column, but the program supports multiple columns as primary keys.

  8. Define an output tag that will specify the data source used for data output.

  9. In this case, a csv data source was chosen, with a prefix for its tables and a suffix to be used. If the table is called HelloWorld, with this configuration, the CSV file will be tableHelloWorld.csv.