Documentation » Reverse Engineering Download

Database Reverse Engineering

Empire-db codegen allows you to generate your data model definition from an existing database.

This instruction will show you two possibilities by using the codegen project of Empire-db.

1. Generating with an IDE

  1. First you have to check out the latest version of Empire-db from the following svn repository: http://svn.apache.org/repos/asf/empire-db/trunk.
  2. Create a new workspace (e.g. with Eclipse) and import the Empire-db projects to your workspace.
  3. As next point you have to configure the config.xml which you will found in the empire-db-codegen project. The single properties of the config.xml will be explained at the end of the page.
  4. After configuring the config.xml you can start the DDL generation by executing the CodeGenerator.java Class in the empire-db-codegen project.

2. Generating with Maven

  1. First you have to create a config.xml where the connection and generation options must be set. To configure your config.xml use the properties from the table at the end of this page.
    The following code will show you an example configuration:
    <?xml version="1.0" encoding="UTF-8"?>
    <config>
        <properties>
            <jdbcClass>oracle.jdbc.driver.OracleDriver</jdbcClass>
            <jdbcURL>jdbc:oracle:thin:@//localhost:1433</jdbcURL>
            <jdbcUser>USER</jdbcUser>
            <jdbcPwd>PASSWORD</jdbcPwd>
            
            <!-- Schema options -->
            <dbCatalog></dbCatalog>
            <dbSchema>USER_DB</dbSchema>
            <dbTablePattern>R%</dbTablePattern>
            <timestampColumn>UPDATE_TIMESTAMP</timestampColumn>
                
            <!-- generation options -->
            <targetFolder>src/main/java</targetFolder>
            <packageName>model</packageName>
            <tablePackageName>model.tables</tablePackageName>
            <viewPackageName>model.views</viewPackageName>
            <recordPackageName>model.records</recordPackageName>
            <dbClassName>DB</dbClassName>
            <tableBaseName>DBTable</tableBaseName>
            <viewBaseName>DBView</viewBaseName>
            <recordBaseName>DBRecord</recordBaseName>
            <tableNamePrefix></tableNamePrefix>
            <tableClassPrefix>T_</tableClassPrefix>
            <tableClassSuffix></tableClassSuffix>
            <viewNamePrefix></viewNamePrefix>
            <viewClassPrefix>V_</viewClassPrefix>
            <viewClassSuffix></viewClassSuffix>
            <columnNamePrefix></columnNamePrefix>
            <nestTables>true</nestTables>
            <nestViews>false</nestViews>
            <createRecordProperties>true</createRecordProperties>
            <preserverCharacterCase>false</preserverCharacterCase>
            <preserveRelationNames>true</preserveRelationNames>
        </properties>    
    </config>
  2. Next you have to customize your pom.xml. As first step you have to add a dependency to the empire-db codegen.
    For example:
    <dependency>
        <groupId>org.apache.empire-db</groupId>
        <artifactId>empire-db-codegen</artifactId>
        <version>2.4.2</version>
    </dependency>
    After adding the dependency you have to add the plugin empire-db-maven-plugin.
    This could look like this:
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.empire-db</groupId>
                <artifactId>empire-db-maven-plugin</artifactId>
                <version>2.4.2</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>codegen</goal>
                        </goals>
                        <configuration>
                            <configFile>src/main/config.xml</configFile>
                        </configuration>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>com.oracle</groupId>
                        <artifactId>ojdbc</artifactId>
                        <version>14</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    In the configuration node you specify the path to your <configFile>. Alternatively, instead of a config file you can specify your config properties directly in the configuration section such as <jdbcClass> and <jdbcURL> etc.
  3. After customizing your pom.xml you can start the DDL generation. Open your command line and go to the root directory of your project. Start the generation by executing the following command: mvn generate-sources.

Property Explanation

Property Explanation
jdbcClass The JDBC class. For example: "oracle.jdbc.driver.OracleDriver".
jdbcURL The URL to the database, e.g. "jdbc:oracle:thin:@192.168.0.2:1521:ora10".
jdbcUser Setting the username.
jdbcPwd Setting the password.
dbCatalog
dbSchema Setting the schema of the database.
dbTablePattern Pattern for the table and view names. Setting dbTablePattern to "%RI%" will generate only the tables and views which containing "RI" in their names.
timestampColumn The name of the timestamp column. For example "UPDATE_TIMESTAMP".
targetFolder The folder where the generated files get saved.
packageName Name of the package.
tablePackageName Package name for the tables.
viewPackageName Package name for the views.
recordPackageName Package name for the records.
dbClassName Database class name.
tableBaseName Class name for the base table (super class of all tables).
viewBaseName Class name for the base view (super class of all views).
recordBaseName Class name for the base record (super class of all records).
tableNamePrefix Sets a prefix for the table names. Example for the table "User" with the prefix "Tbl": The selected table name for the table "User" would be "TblUSER". In the Database class it would be like: "User TblUSER = new User()".
tableClassPrefix Sets a prefix for the table classes. For example the prefix "T_": The name of every table class will start with "T_".
tableClassSuffix Sets a suffix for the table classes. Similar to the property tableClassPrefix.
viewNamePrefix Sets a prefix for the view names.
viewClassPrefix Sets a prefix for the view classes.
viewClassSuffix Sets a suffix for the view classes.
columnNamePrefix Sets a prefix for the column names.
nestTables When setting nestTable to "true", every table will be generated as a nested class (inner class) in the database class.
nestViews Similar to nestTables but with views.
createRecordProperties Setting createRecordProperties to "true", will generating the getter and setter methods for every column in the associated table.
preserverCharacterCase Setting this property to "true" – The names for the tables and views will be kept.
Setting to "false" – Class names will be in camel case.
preserveRelationNames Setting this property to "true" – The names of the relations that were setting in the database will be preserved.
Setting to "false" – The relations will be unnamed.