| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
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 how JDX ORM can persist and retrieve JSON-based domain objects directly to and from a relational database — without requiring traditional Java POJOs with explicit getter/setter fields.
Instead of a conventional Java class, the domain model is built on top of the JDX_JSONObject class, which serves as the foundational base class for handling persistence of domain-specific JSON objects. Application code defines a minimal subclass (e.g., JSON_Employee) with just two constructors.
The ORM mapping uses VIRTUAL_ATTRIB declarations to define the persistent JSON properties and their types declaratively, allowing JDX to bridge the dynamic JSON model to a fixed relational schema.
A JSON_Employee instance can be initialized in three convenient ways:
JDX_JSONExample/ ├── config/ │ └── json_example.jdx # ORM mapping specification file ├── src/ │ └── com/softwaretree/jdxjsonexample/ │ ├── JSONExample.java # Main application entry point │ └── model/ │ └── JSON_Employee.java # JSON-based 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
Unlike the other JDX examples that use traditional POJOs, JSON_Employee extends JDX_JSONObject and defines only two constructors. All attribute storage and retrieval is handled internally by the JSONObject key-value store.
The persistent properties of a JSON_Employee and how they map to the database are defined entirely in the .jdx mapping file using VIRTUAL_ATTRIB:
| JSON Property | Java Type | DB Column | Notes |
|---|---|---|---|
| id | int | id | Primary key |
| name | String | name | |
| exempt | boolean | exempt | |
| compensation | double | salary | Column name remapped via SQLMAP |
| DOB | long | DOB | Stored as milliseconds; mapped to SQL DATE |
This file is the central piece that makes the JSON-based model work with JDX ORM. Key elements:
Refer to the JDX Database & JDBC Driver Specification Guide for configuring other databases.
Note: Update JDX_DATABASE and JDBC_DRIVER to match your local database setup before running.
A minimal shell class that extends JDX_JSONObject. It defines only two constructors — a no-arg constructor and one that accepts a JSONObject — and inherits all persistence behavior from the superclass. No fields, getters, or setters are needed.
The entry point of the sample application. It initializes JDX ORM and demonstrates the following:
Lists all .java source files to be compiled, one per line:
./src/com/softwaretree/jdxjsonexample/model/JSON_Employee.java ./src/com/softwaretree/jdxjsonexample/JSONExample.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.
Windows:
compile.cmdMac/Linux:
chmod +x compile.sh # first time only
./compile.shSets the CLASSPATH environment variable to include the JDX ORM libraries, the org.json library, and the appropriate JDBC driver JAR. Edit this file to point to the correct JDBC driver for your database before running the application.
Note that json-20240303.jar is included here in addition to the other examples, as it is a runtime dependency for the JSON object model.
Invokes the environment setup script to configure the classpath, then runs the JSONExample 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.shSet JX_HOME to the root of your JDX ORM SDK installation.
Configure the database by editing config/json_example.jdx:
Compile the source files:
compile.cmd # Windows
./compile.sh # Mac/LinuxRun the sample application:
runJDXExample.bat # Windows
./runJDXExample.sh # Mac/LinuxThe application will automatically create the database schema on first run (controlled by the forceCreateSchema flag in JSONExample.java).
Mac/Linux tip: Run chmod +x *.sh once 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.
| Back | FazBrowse Home | New Git URL |