Skip to content

Latest commit

 

History

History
171 lines (118 loc) · 9.65 KB

File metadata and controls

171 lines (118 loc) · 9.65 KB

Note: This file is written in Markdown and is best viewed with a Markdown viewer (e.g., GitHub, GitLab, VS Code, or a dedicated Markdown reader). Viewing it in a plain text editor may not render the formatting as intended.

Copyright (c) 2026 Software Tree

JDX_ReverseEngineeringExample

Overview

This directory demonstrates the Reverse Engineering feature of JDX ORM. Given a template configuration file that identifies existing tables in a database, JDX can automatically generate:

  1. Java class source files — one per specified table, with typed fields and accessor methods (getters/setters) corresponding to the table columns.
  2. A reverse-engineered ORM mapping file (.revjdx) — containing the full CLASS, PRIMARY_KEY, RELATIONSHIP, COLLECTION_CLASS, and SQLMAP declarations inferred from the database schema, including detected relationships between tables based on foreign key constraints.

The example uses the MySQL Sakila sample database (a well-known demo database available from MySQL). Three tables are specified in the template: film, film_actor, and film_category. The reverse engineering tool inspects these tables, detects their columns and relationships, and generates everything needed to start using JDX ORM with them immediately.

After reverse engineering, the generated classes can be compiled and used with the JDXDemo GUI application to interactively browse and query the database.


Prerequisites

  • Java JDK 8 or higher installed and on the system PATH.
  • JDX ORM SDK installed. Set the environment variable JX_HOME to the SDK's top-level installation directory.
  • MySQL with the Sakila sample database installed. Update the JDX_DATABASE connection string and credentials in the template config file to match your local setup.
  • The MySQL JDBC driver JAR (mysql-connector-j-8.0.33.jar or compatible) available under JX_HOME/external_libs/.

Project Structure

JDX_ReverseEngineeringExample/
├── config/
│   ├── mysql_sakila_example_template.config   # Template file: input to the reverse engineering tool
│   ├── mysql_sakila_example_template_config.revjdx  # Generated ORM mapping file (output)
│   └── JDXDemo.config                         # Configuration for the JDXDemo GUI
├── Film.java                    # Generated Java class for the film table (output)
├── Film_Actor.java              # Generated Java class for the film_actor table (output)
├── Film_Category.java           # Generated Java class for the film_category table (output)
├── bin/                         # Compiled .class files (generated after compilation)
├── sources.txt                  # List of .java files for compilation (auto-generated by compile scripts)
├── compile.cmd                  # Windows: compile the generated Java source files
├── compile.sh                   # Mac/Linux: compile the generated Java source files
├── setEnvironment.bat           # Windows: sets classpath environment variable
├── setEnvironment.sh            # Mac/Linux: sets classpath environment variable
├── JDXReverseEngineer.bat       # Windows: run the reverse engineering tool
├── JDXReverseEngineer.sh        # Mac/Linux: run the reverse engineering tool
├── JDXDemo.bat                  # Windows: launch the JDXDemo GUI application
├── JDXDemo.sh                   # Mac/Linux: launch the JDXDemo GUI application
└── README.md                    # This file

Note: The .java source files and the .revjdx mapping file are outputs of the reverse engineering tool, not hand-authored inputs. They are regenerated each time JDXReverseEngineer is run.


Key Components

config/mysql_sakila_example_template.config — Template Configuration File

This is the input to the reverse engineering tool. It tells JDX ORM which database to connect to, which package to use for generated classes, and which tables to reverse engineer. Key elements:

  • JDX_DATABASE and JDBC_DRIVER — database connection and driver settings for the MySQL Sakila database. Update these to match your local setup before running.
  • JDX_OBJECT_MODEL_PACKAGE — the Java package for the generated classes (com.softwaretree.jdxmysqlsakilaexample.reversed.model).
  • JDX_GENERATE_ACCESSOR_METHODS TRUE — instructs the tool to generate getters and setters for all fields in the generated classes.
  • JDX_SUPERCLASS_NAME — commented out; can be uncommented to specify a superclass for all generated classes.
  • CLASS Film TABLE film, CLASS Film_Actor TABLE film_actor, CLASS Film_Category TABLE film_category — identifies the three tables to reverse engineer. No further mapping detail is needed here; the tool infers everything else from the database schema.

config/mysql_sakila_example_template_config.revjdx — Generated ORM Mapping File

This is the output of the reverse engineering tool — a fully populated JDX ORM mapping file generated from the Sakila database schema. It contains:

  • CLASS .Film TABLE film — with PRIMARY_KEY film_id, two RELATIONSHIP declarations (to ListFilm_Actor and ListFilm_Category), and SQLMAP NULLABLE entries for nullable columns (release_year, original_language_id, length, rating, description, special_features).
  • COLLECTION_CLASS .ListFilm_Actor and COLLECTION_CLASS .ListFilm_Category — auto-detected one-to-many relationships from film to film_actor and film_category respectively, both as JAVACOLLECTION types keyed by film_id.
  • CLASS .Film_Actor TABLE film_actor — with composite PRIMARY_KEY actor_id film_id.
  • CLASS .Film_Category TABLE film_category — with composite PRIMARY_KEY film_id category_id.

This file can be used directly with JDX ORM after updating the connection credentials, or manually refined as needed (e.g., to rename relationships, adjust collection types, or add QUERY_NAME entries).


Workflow

Step 1 — Configure the template

Edit config/mysql_sakila_example_template.config:

  • Update JDX_DATABASE with the correct MySQL connection URL, username, and password.
  • Update setEnvironment.bat (Windows) or setEnvironment.sh (Mac/Linux) if a different JDBC driver version is needed.

Step 2 — Run the reverse engineering tool

Windows:

JDXReverseEngineer.bat

Mac/Linux:

chmod +x JDXReverseEngineer.sh   # first time only
./JDXReverseEngineer.sh

This generates:

  • Film.java, Film_Actor.java, Film_Category.java in the project root directory.
  • config/mysql_sakila_example_template_config.revjdx — the reverse-engineered mapping file.

Step 3 — Compile the generated classes

Windows:

compile.cmd

Mac/Linux:

chmod +x compile.sh   # first time only
./compile.sh

Both scripts automatically discover all .java files in the project directory and write them to sources.txt before compiling. The .class files are placed in the bin/ directory.

Step 4 — Browse the database with JDXDemo

Windows:

JDXDemo.bat

Mac/Linux:

chmod +x JDXDemo.sh   # first time only
./JDXDemo.sh

The JDXDemo GUI allows you to interactively query and browse the Film, Film_Actor, and Film_Category objects using the generated mapping.


Customizing the Generated Output

The generated .java classes and .revjdx mapping file can be manually edited after generation:

  • Remove attributes — delete fields from the class and their corresponding SQLMAP or VIRTUAL_ATTRIB entries from the mapping file if certain columns are not needed.
  • Rename attributes — rename fields in the class and modify their corresponding SQLMAP or VIRTUAL_ATTRIB entries in the mapping file to map more meaningful names of the new fields with the names of the corresponding columns (for example, an 'eid' field name may be changed to empId in the .java file and adding a SQLMAP specification in the mapping file for empId using COLUMN_NAME eid).
  • Rename relationships — change the RELATIONSHIP names in the .revjdx file and the corresponding field names in the Java class.
  • Change collection types — switch from JAVACOLLECTION to ARRAY or other supported types.
  • Add named queries — append QUERY_NAME entries to any CLASS block.
  • Move classes to a subdirectory — update JDX_OBJECT_MODEL_PACKAGE and the file locations accordingly.

See the Reverse Engineering section of the JDX User Manual for full details on all available template options.


Additional Notes

  • The sources.txt file included in this directory contains absolute paths from the developer's machine and should not be used directly. The compile.cmd and compile.sh scripts regenerate sources.txt automatically by discovering .java files in the current directory.
  • The reverse engineering tool can be re-run at any time to regenerate the classes if the database schema changes. Manual customizations to the generated files will be overwritten, so keep a copy of any modifications.

Importing into Eclipse

After reverse engineering and compilation, this project can be imported into the Eclipse IDE as an existing Java project using File → Import → Existing Projects into Workspace.


Additional Resources