databene

 
  • Increase font size
  • Default font size
  • Decrease font size

The most convenient way to use benerator is integrating it into an IDE with maven. Unfortunately, an absolute requirement is that you are familiar with maven - if you are not, create an IDE-based project without Maven support.

Choose or install an IDE

The procedure is described here for Eclipse, but works similarly for other IDEs.

If you do not yet have an IDE installed and would like to use Eclipse, download and install an Eclipse distribution with an XML editor, e.g. Eclipse IDE for Java Developers from the Eclipse web site.

If your Eclipse installation does not support maven (like the Eclipse IDE for Java), further work is necessary:

Make the IDE support Maven

Install a maven plugin, e.g. m2eclipse.

Here's a step-by-step advisory for Eclipse-newbies:

  • Start Eclipse
  • Select Help - Software Updates - Find and Install from the main menu
  • Choose Search for new features to install and click Next
  • Click New Remote Site
  • In the Site dialog, set Name to m2eclipse, URL to http://m2eclipse.sonatype.org/update/ and click OK
  • Back in the main update dialog, assure that m2eclipse is checked and click Finish
  • In the Search Results dialog, choose at least m2eclipse - Maven Integration and click Next
  • Choose I accept the terms of the license agreement and click Next
  • Click Finish
  • Click Install All
  • Click Restart

Create a project

You can use a small but powerful wizard for creating a benerator project.

First make sure the necessary JDBC drivers are in the lib directory of the benerator sdistribution, then start the maven-project wizard:

sh maven-project-wizard.sh

or

maven-project-wizard.bat

This will open a GUI in which you can enter all project details:

 

 

If you do not want to import table (meta) data from an existing database, uncheck the 'Database Project' checkbox.

Otherwise configure your database and click 'Test Connection' to check if they are valid.

These are typical settings for different databases:

DatabaseURL
Driver Class
Jar
DB2
 dbc:db2://host:50000/database com.ibm.db2.jcc.DB2Driver db2jcc.jar
Derby
 jdbc:derby://host:1527/database org.apache.derby.jdbc.ClientDriver derbyclient.jar
Firebird jdbc:firebirdsql:host/3050:database org.firebirdsql.jdbc.FBDriver jaybird-full.jar
HSQL jdbc:hsqldb:hsql://host:9001/database org.hsqldb.jdbcDriver hsqldb.jar
HSQL (embedded)
 jdbc:hsqldb:database org.hsqldb.jdbcDriver

 hsqldb.jar

Jaybird
 jdbc:firebirdsql:host/3050:database org.firebirdsql.jdbc.FBDriver jaybird-full.jar
MySQL jdbc:mysql://host:3306/database com.mysql.jdbc.Driver mysql-connector-java.jar
Oracle jdbc:oracle:thin:@host:1521:XE oracle.jdbc.OracleDriver ojdbc6.jar
PostgreSQL jdbc:postgresql://host:5432/database org.postgresql.Driver postgresql-nn.jdbc3.jar
Sybase jdbc:jtds:sybase://host:7100/database net.sourceforge.jtds.jdbc.Driver jtds.jar

For a repeated experiments in a database population project you would generally want to have your database reset completely when starting each data generation. So you should additionally import a SQL file that drops all existing tables and one that recreates them.

Finally click 'Create'.

Benerator will then create a Maven project structure and if you have configured a database, it will connect to the specified database, read the table structures and, if you specified so, read table data and export it to a snapshot file.
               
This is what your project file structure will look like:

 

 

The generated pom.xml is the Maven project descriptor which might need modification:

On the one hand it aggregates all supported open source JDBC drivers, the Apache POI library and log4j. You can remove dependencies that you do not need.

On the other hand, some database drivers are not available on the public Maven repository:

  • Oracle
  • DB2
  • Jaybird (for Firebird DB)

If you need to use one of these you need to manually download and install their Jars in your Maven repository. Possibly they are available at your company's Maven repository, possibly with an unexpected groupId/artifactId.

 A typical configuration for Oracle would be for example

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>10.2.0.4.0</version>
</dependency>

You can download the Oracle driver from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html and put them into a repository on your own. In a local repository:

mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/path/to/file

or in a remote (e.g. company) repository:

mvn deploy:deploy-file -DgroupId=com.oracle -DartifactId=ojdbc6
                 -Dversion=10.2.0.4.0 -Dpackaging=jar -Dfile=/path/to/file
                 -Durl=[url] -DrepositoryId=[id]

 

Create IDE configurations for maven goals

  • Select Run - Open Run Dialog from the main menu.
  • The appearing dialog has a tree at left. Choose Maven Build there and click the New icon.
  • In the new right-hand-side panel, replace the name New_configuration with a suitable name, e.g. generate
  • Enter clean install benerator:generate in the goal field.
  • Click Apply and Close.

You can as well create a snapshot configuration for the goal benerator:dbsnapshot which can be used to create a database dump in DbUnit XML format.

Invoking a Maven goal

Select Run - Open Run Dialog from the main menu. Choose the configuration name defined above, e.g. generate click the Run icon.

Now benerator runs the generated descriptor files.

If you have defined a database project as defined above, benerator connects to your database, deletes the old content, recreates the tables and, if you created a snapshot recreate an identical copy of the original content. Now you are ready to edit the benerator descriptor and try out your generation customizations.

For your convenience the generated descriptor file contains templates for generation configuration of all tables, ordered by dependencies. You can uncomment and modify each attribute you want to generate differently. Originally the count is set to 0 so remember to set it to something higher before you worry;-)