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
This project demonstrates CRUD (Create, Read, Update, Delete) operations on a simple Employee domain model class using JDX ORM, with a specific focus on contrasting two API styles for interacting with the database:
JDXSetup/JDXS(lower-level API) — the application checks out aJXResource, obtains aJDXShandle, performs operations directly, and checks the resource back in. This style gives more control and is closer to the underlying JDX ORM mechanics.JDXHelper(higher-level API) — a convenience wrapper that handles resource checkout/checkin automatically, providing a simpler and more concise coding style for common operations.
Both useJDXORM1() (uses JDXSetup/JDXS) and useJDXORM2() (uses JDXHelper) perform exactly the same sequence of operations, making it easy to compare the two styles side by side.
A notable feature demonstrated here is update2() — a JDX API call that updates specific attributes of multiple objects matching a predicate in a single call, without loading the objects into memory first.
- Java JDK 8 or higher installed and on the system PATH.
- JDX ORM SDK installed. Set the environment variable
JX_HOMEto the SDK's top-level installation directory. - A supported JDBC-compatible database (SQLite is pre-configured; a MySQL example is also included in the
.jdxfile).
JDX_Simple2Example/
├── config/
│ └── simple2_example.jdx # ORM mapping specification file
├── src/
│ └── com/softwaretree/jdxsimple2example/
│ ├── Simple2Example.java # Main application entry point
│ └── model/
│ └── Employee.java # Employee model class
├── bin/ # Compiled .class files (generated)
├── sources.txt # List of Java source files for compilation
├── compile.cmd # Windows: compile the Java source files
├── compile.sh # Mac/Linux: compile the Java source files
├── setEnvironment.bat # Windows: sets classpath environment variable
├── setEnvironment.sh # Mac/Linux: sets classpath environment variable
├── runJDXExample.bat # Windows: run the sample application
├── runJDXExample.sh # Mac/Linux: run the sample application
├── forward.bat # Windows: create/recreate the database schema
├── forward.sh # Mac/Linux: create/recreate the database schema
├── JDXDemo.bat # Windows: launch the JDXDemo GUI application
├── JDXDemo.sh # Mac/Linux: launch the JDXDemo GUI application
└── README.md # This file
| Field | Type | DB Column | Notes |
|---|---|---|---|
id |
int |
EmpId |
Primary key |
name |
String |
EmpName |
|
DOB |
Date |
DOB |
|
exempt |
boolean |
Exempt |
|
compensation |
float |
Salary |
Four fields have their Java names remapped to different database column names via SQLMAP. Note that Employee in this example uses the class name as the table name (no explicit TABLE directive in the mapping), so the table name defaults to Employee.
JDX_DATABASEandJDBC_DRIVER— pre-configured for SQLite; a commented-out MySQL example is also included.CLASS ... EmployeewithPRIMARY_KEY id.SQLMAPentries remapid→EmpId,name→EmpName,exempt→Exempt,compensation→Salary.
Refer to the JDX Database & JDBC Driver Specification Guide for configuring other databases.
Note: Update
JDX_DATABASEandJDBC_DRIVERto match your local database setup before running.
The application runs two phases that perform identical operations using different API styles:
Phase 1 — useJDXORM1() (lower-level JDXSetup/JDXS style):
- Check out a
JXResource; obtainJDXS jdxHandle. - Delete all existing employees; verify count with
getAggregate(AGGR_COUNT). - Insert
Mark(id=1) andBill(id=2). - Query all employees; query with predicate
compensation < 52000. update2(employeeClassName, "id < 5", newValues, 0)— updatescompensation=77777andexempt=truefor all employees withid < 5, without loading them into objects. Returns the count of updated rows.- Query employees with
id < 5to confirm the bulk update. getObjectByIdfor Bill (id=2); update hisexemptandcompensationindividually; re-retrieve to confirm.- Delete Bill; query remaining; delete remaining via
jdxHandle.delete(list, ...). - Check in the
JXResource.
Phase 2 — useJDXORM2() (higher-level JDXHelper style):
Performs the exact same sequence as Phase 1, but using JDXHelper convenience methods — jdxHelper.delete2(), jdxHelper.getObjectCount(), jdxHelper.insert(), jdxHelper.getObjects(), jdxHelper.update2(), jdxHelper.getObjectById(), jdxHelper.update(), jdxHelper.delete(). No explicit JXResource checkout/checkin is needed; JDXHelper handles that internally.
The key difference: useJDXORM1() requires manual resource lifecycle management; useJDXORM2() is more concise but provides less direct control.
Lists all .java source files to be compiled, one per line:
./src/com/softwaretree/jdxsimple2example/model/Employee.java
./src/com/softwaretree/jdxsimple2example/Simple2Example.java
This file is passed to javac using the @sources.txt argument syntax.
Compiles all Java source files listed in sources.txt and outputs .class files into the bin/ directory.
- Requires
JX_HOMEto be set to the JDX ORM SDK installation directory. - Links against
jxclasses.jar(JDX ORM library) andjson-20240303.jar(JSON support). compile.cmd— Windows batch script (supports JDK 8; a commented line supports JDK 9+).compile.sh— Mac/Linux shell script equivalent.
Windows:
compile.cmdMac/Linux:
chmod +x compile.sh # first time only
./compile.shSets the CLASSPATH environment variable to include the JDX ORM libraries and the appropriate JDBC driver JAR. Edit this file to point to the correct JDBC driver for your database before running the application.
setEnvironment.bat— Windows (uses;as classpath separator).setEnvironment.sh— Mac/Linux (uses:as classpath separator; sourced viasource ./setEnvironment.sh).
Invokes the environment setup script to configure the classpath, then runs the Simple2Example main class.
Windows:
runJDXExample.batMac/Linux:
chmod +x runJDXExample.sh # first time only
./runJDXExample.shCreates (or recreates) the database schema based on the ORM specification in the .jdx file, without running the application.
Windows:
forward -createMac/Linux:
chmod +x forward.sh # first time only
./forward.sh -createLaunches the JDXDemo desktop GUI application, which provides a graphical way to browse and interact with the database using the JDX ORM configuration.
Windows:
JDXDemo.batMac/Linux:
chmod +x JDXDemo.sh # first time only
./JDXDemo.sh-
Set
JX_HOMEto the root of your JDX ORM SDK installation. -
Configure the database by editing
config/simple2_example.jdx:- Update
JDX_DATABASEwith the correct connection URL and credentials. - Update
JDBC_DRIVERwith the appropriate JDBC driver class. - Update
setEnvironment.bat(Windows) orsetEnvironment.sh(Mac/Linux) to include the JDBC driver JAR on the classpath.
- Update
-
Compile the source files:
compile.cmd # Windows ./compile.sh # Mac/Linux
-
Run the sample application:
runJDXExample.bat # Windows ./runJDXExample.sh # Mac/Linux
The application will automatically create the database schema on first run (controlled by the
forceCreateSchemaflag inSimple2Example.java).
Mac/Linux tip: Run
chmod +x *.shonce in the project directory to make all shell scripts executable.
This project can be imported directly into the Eclipse IDE as an existing Java project using File → Import → Existing Projects into Workspace.
- JDX Database & JDBC Driver Specification Guide
- JDX ORM SDK documentation (included in your SDK installation under
JX_HOME)