This version of the manual is outdated. For the latest version, follow this link: http://www.jooq.org/doc/3.0/manual.

The jOOQ User Manual. Multiple Pages : jOOQ classes and their usage : Extend jOOQ with custom typesprevious : next

# Write your own QueryPart implementations

If a SQL clause is too complex to express with jOOQ, you can extend either one of the following types for use directly in a jOOQ query:

public abstract class CustomField<T> extends AbstractField<T> {
  // [...]
}
public abstract class CustomCondition extends AbstractCondition {
  // [...]
}

These two classes are declared public and covered by integration tests. When you extend these classes, you will have to provide your own implementations for the QueryParts' bind(BindContext) and toSQL(RenderContext) methods:

// This method must produce valid SQL. If your QueryPart contains other QueryParts, you may delegate SQL code generation to them
// in the correct order, passing the render context.
//
// If context.inline() is true, you must inline all bind variables
// If context.inline() is false, you must generate ? for your bind variables
public void toSQL(RenderContext context);

// This method must bind all bind variables to a PreparedStatement. If your QueryPart contains other QueryParts, you may delegate
// variable binding to them in the correct order, passing the bind context.
//
// Every QueryPart must ensure, that it starts binding its variables at context.nextIndex().
public void bind(BindContext context) throws DataAccessException;

The above contract may be a bit tricky to understand at first. The best thing is to check out jOOQ source code and have a look at a couple of QueryParts, to see how it's done.

# Plain SQL as an alternative

If you don't need integration of rather complex QueryParts into jOOQ, then you might be safer using simple Plain SQL functionality, where you can provide jOOQ with a simple String representation of your embedded SQL.


The jOOQ User Manual. Multiple Pages : jOOQ classes and their usage : Extend jOOQ with custom typesprevious : next

The jOOQ Logo