Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16

This is experimental functionality, and as such subject to change. Use at your own risk!

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.


Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The model API (Query Object Model or org.jooq.impl.QOM) is an auxiliary API implemented by each and every org.jooq.QueryPart allowing for users to get public access to jOOQ's internal query object model structure. For example:

// Create an expression using the DSL API:
Field<String> field = substring(BOOK.TITLE, 2, 4);

// Access the expression's internals using the model API
if (field instanceof QOM.Substring substring) {
    Field<String> string = substring.$string();
    Field<? extends Number> startingPosition = substring.$startingPosition();
    Field<? extends Number> length = substring.$length();

Every argument passed to the DSL API has a $ prefixed accessor method on the model API, exposing the wrapped argument. Using these accessor methods, users can traverse the expression tree manually or via the model API traversal API. More recent Java language features like pattern matching can be very helpful for such operations, especially as we're planning to seal the entire query object model API.

All of the model API is immutable, but new expressions can still be created using equivalent $ prefixed setter methods, which don't mutate the original expression but return a copy:

// Produces a substring(BOOK.TITLE, 2, 4) column expression
QOM.Substring substring = (QOM.Substring) substring(BOOK.TITLE, 2, 4);

// Produces a substring(BOOK.TITLE, 3, 5) column expression

These basic operations allow for powerful SQL transformations on expression trees created with the DSL API but also with the SQL parser.

References to this page


Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo