Using the Benerator Schema for code completion
<?xml version="1.0" encoding="iso-8859-1"?> |
Hello World
Descriptor:
<generate name="message" count="5" consumer="ConsoleExporter" > |
Output:
message[text=Hello World]
message[text=Hi World]
message[text=Hello Planet]
message[text=Hello Planet]
message[text=Howdy Earth]
Simple-Type Data Generation
Regular-Expression-based
<attribute name="wecomeMessage" type="string" pattern="(Hello|Hi|Howdy) (World|Earth|Planet)"/> |
List-based
<attribute name="rank" type="string" pattern="A,B,C"/> |
Script-based
<variable name="block" pattern="[A-Z]" /> |
Decisions in BeneratorScript
A common requirement is to have alternative ways to render some data, depending on context or necessary data conversion, e.g. for entities with multifield constraints or mapping of null values or booleans.
The simplest way to configure this is using a condition:
<attribute name="test" condition="x != 0" script="util.calculate(x)" /> |
An example that mixes data of two alternatives alt1 and alt2 (possibly taken from two different data sets) is:
<attribute name="test" script="x != 0 ? alt1 : alt2" /> |
Alternative decisions in FreeMarker
In FreeMarker, the decision betwwen alternatives alt1 and alt2 (possibly taken from two different data sets) is:
<attribute name="test" script="ftl:[#ftl][#if x != 0]${alt1}[#else]${alt2}[/#if]" /> |
Please note, that x can be a variable or property defined before and may not be wrapped with ${}!
Writing entities to a CSV file
<generate name="Person" count="5"> |
creates a file 'users.csv' in UTF-8 encoding with the columns id and name:
id,name |
Database related
Defining a database
<database id="db" url="jdbc:hsqldb:hsql://localhost" driver="org.hsqldb.jdbcDriver" user="sa" password="" schema="public" batch="false"/> |
Executing DDL
from a file
<execute uri="create-tables.sql" target="db" onError="fatal"/> |
inline
<execute target="db" type="sql" onError="warn"> |
Importing data from a from a DbUnit XML file
<iterate source="shop.dbunit.xml" consumer="db"/> |
Exporting generated data to a SQL file
You need to configure the SQLEntityExporter to usse a database dialect for SQL file generation:
<database id="db" ... /> |
Available dialects are
| dialect | database system |
| db2 | DB2 |
| derby | Derby |
| firebird | Firebird |
| hsql | HSQL |
| h2 | H2 |
| oracle | Oracle |
| postgres | PostgreSQL |
| sql_server | SQL Server |


