Skip to content

SoftwareTree/JDX_SimpleExample

Repository files navigation

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_SimpleExample

Overview

This project demonstrates simple CRUD (Create, Read, Update, Delete) operations on objects of a basic domain model class using the JDX ORM (Object Relational Mapping) library. It shows how JDX ORM API calls can transparently exchange Java object data with a relational database without manual SQL.

The example application creates, queries, updates, and deletes instances of ClassA — a simple model class with fields of several common Java types (int, String, Date, boolean, float).


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.
  • A supported JDBC-compatible database (SQLite is pre-configured; MySQL and PostgreSQL examples are also included in the .jdx file).

Project Structure

JDX_SimpleExample/
├── config/
│   └── simple_example.jdx       # ORM mapping specification file
├── src/
│   └── com/softwaretree/jdxsimpleexample/
│       ├── SimpleExample.java    # Main application entry point
│       └── model/
│           └── ClassA.java       # Domain 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

Key Components

config/simple_example.jdx — ORM Mapping File

This declarative file tells JDX ORM how to map Java classes to database tables. It specifies:

  • JDX_DATABASE — the JDBC connection URL, credentials, database type, and debug level.
  • JDBC_DRIVER — the JDBC driver class name.
  • CLASS / PRIMARY_KEY — the Java class(es) to be managed and their primary key field(s).

The file comes pre-configured for SQLite (no additional database setup required). Commented-out examples for MySQL and PostgreSQL are also included. Refer to the JDX Database & JDBC Driver Specification Guide for details on configuring other databases.

Note: Update JDX_DATABASE and JDBC_DRIVER to match your local database setup before running.


src/.../model/ClassA.java — Domain Model Class

A simple POJO (Plain Old Java Object) that JDX ORM maps to a database table. It has the following fields:

Field Type Description
aId int Primary key
aString String A text field
aDate Date A date field
aBoolean boolean A boolean flag
aFloat float A floating-point value

A no-arg default constructor is included as required by JDX ORM for object instantiation.


src/.../SimpleExample.java — Main Application

The entry point of the sample application. It:

  1. Initializes JDX ORM using the .jdx mapping file.
  2. Optionally creates the database schema automatically.
  3. Runs a sequence of CRUD operations via JDXHelper:
    • Delete all existing ClassA records.
    • Insert three new ClassA objects (A1, A2, A3).
    • Query all objects; query with ordering; query with filter conditions.
    • Update a specific object and re-query it.
    • Delete a specific object and query the remaining records.
  4. Cleans up the JDX ORM connection on exit.

sources.txt — Source File List

A plain-text file listing all .java source files to be compiled, one per line, in the format:

./src/com/softwaretree/jdxsimpleexample/model/ClassA.java
./src/com/softwaretree/jdxsimpleexample/SimpleExample.java

This file is passed to javac using the @sources.txt argument syntax.


compile.cmd / compile.sh — Compilation Scripts

Compiles all Java source files listed in sources.txt and outputs .class files into the bin/ directory.

  • Requires JX_HOME to be set to the JDX ORM SDK installation directory.
  • Links against jxclasses.jar (JDX ORM library) and json-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.cmd

Mac/Linux:

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

setEnvironment.bat / setEnvironment.sh — Environment Setup

Sets the CLASSPATH environment variable to include the JDX ORM libraries and the appropriate JDBC driver JAR for your database. 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 via source ./setEnvironment.sh)

runJDXExample.bat / runJDXExample.sh — Run Script

Invokes the environment setup script to configure the classpath, then runs the SimpleExample main class.

Windows:

runJDXExample.bat

Mac/Linux:

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

forward.bat / forward.sh — Schema Generation

Creates (or recreates) the database schema based on the ORM specification in the .jdx file, without running the application.

Windows:

forward -create

Mac/Linux:

chmod +x forward.sh   # first time only
./forward.sh -create

JDXDemo.bat / JDXDemo.sh — JDXDemo GUI

Launches the JDXDemo desktop GUI application, which provides a graphical way to browse and interact with the database using the JDX ORM configuration.

Windows:

JDXDemo.bat

Mac/Linux:

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

Getting Started

  1. Set JX_HOME to the root of your JDX ORM SDK installation.

  2. Configure the database by editing config/simple_example.jdx:

    • Update JDX_DATABASE with the correct connection URL and credentials.
    • Update JDBC_DRIVER with the appropriate JDBC driver class.
    • Update setEnvironment.bat (Windows) or setEnvironment.sh (Mac/Linux) to include the JDBC driver JAR on the classpath.
  3. Compile the source files:

    compile.cmd          # Windows
    ./compile.sh         # Mac/Linux
  4. 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 forceCreateSchema flag in SimpleExample.java).

Mac/Linux tip: Run chmod +x *.sh once in the project directory to make all shell scripts executable.


Importing into Eclipse

This project can be imported directly into the Eclipse IDE as an existing Java project using File → Import → Existing Projects into Workspace.


Additional Resources

About

Introductory JDX ORM example demonstrating CRUD operations on a basic Java domain class ClassA using SQLite or MySQL. Shows schema auto-creation, queries with filters and ordering, and the JDXHelper convenience API — no manual SQL required.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors