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 object streaming in JDX ORM — the ability to retrieve query results iteratively, a few objects at a time, rather than loading all matching objects into memory at once. This is particularly useful when querying large result sets where loading everything in a single call would be memory-intensive or slow.
The streaming API works as follows:
- Open a stream — call
query()with theJDXS.QFLAG_STREAMflag and aninitialCountto retrieve the first batch of objects. The database cursor remains open. - Fetch subsequent batches — call
queryFetch(fetchCount, ...)in a loop to retrieve the nextfetchCountobjects from the open cursor. Continue untilqueryResults.size() < fetchCount, indicating no more objects remain. - Close the stream — call
queryClose()to close the database cursor.
Streaming queries must be performed within a transaction (tx_begin() / tx_commit()), as the database cursor must remain open across multiple fetch calls.
The example populates 15 Employee objects, then demonstrates two streaming scenarios:
- Stream all employees with an initial fetch of 5, followed by batches of 4.
- Stream a filtered, ordered subset (
name > 'Doug' ORDER BY DOB) with the same batch sizes.
- 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_StreamingExample/
├── config/
│ └── streaming_example.jdx # ORM mapping specification file
├── src/
│ └── com/softwaretree/jdxstreamingexample/
│ ├── StreamingExample.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 |
In thousands |
All four non-DOB fields have their Java names remapped to different database column names via SQLMAP.
JDX_DATABASEandJDBC_DRIVER— pre-configured for SQLite; a commented-out MySQL example is also included.CLASS ... Employee TABLE 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:
Phase 1 — populateDatabase(): Inserts 15 Employee objects using three different insertion strategies:
- Individual inserts — employees 1–9, each in its own implicit transaction.
- Batch with explicit transaction — employees 10–12 inserted one by one within a single
tx_begin()/tx_commit()scope. - Batch list insert — employees 13–15 inserted in a single
jdxHandle.insert(list, ...)call.
Verifies the total count using getAggregate(AGGR_COUNT) after population.
Phase 2 — useJDXORM(): Demonstrates streaming in two scenarios:
Stream 1 — all employees:
- Get total count with
getAggregate(AGGR_COUNT). tx_begin()— streaming requires an active transaction.query(..., initialCount=5, QFLAG_STREAM, ...)— opens the stream and retrieves the first 5 objects.- Loop:
queryFetch(fetchCount=4, ...)— fetches the next 4 objects per iteration until fewer thanfetchCountare returned. queryClose()thentx_commit()— closes the cursor and ends the transaction.
Stream 2 — filtered and ordered employees:
getAggregate(AGGR_COUNT, predicate="name > 'Doug'")— counts the qualifying subset.- Same
tx_begin()→query(..., "name > 'Doug' ORDER BY DOB", initialCount=5, QFLAG_STREAM)→ loopqueryFetch(4)→queryClose()→tx_commit()pattern as above, with results ordered byDOB.
Important: A streaming query must always be closed with
queryClose()before starting a new one. Failing to close an open stream will cause an error on the next streaming query.
Lists all .java source files to be compiled, one per line:
./src/com/softwaretree/jdxstreamingexample/model/Employee.java
./src/com/softwaretree/jdxstreamingexample/StreamingExample.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 StreamingExample 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/streaming_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 inStreamingExample.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)