Class SqlSearchCompiler
Filter tree into a SQL WHERE predicate for a SqlDialect.
This is the dialect-agnostic core of the shared JDBC engine. The terms are already parsed, allow-listed and type-checked. The compiler walks each tree and:
- combines the terms (one per column) with
AND; - combines a column's
$and/$or/$notsub-expressions itself; - delegates every leaf to the
SqlDialect(a built-in viaSqlDialect.builtinRenderer(String), a bare pattern viaSqlDialect.renderBare(java.lang.String, org.apache.juneau.commons.beanquery.SearchType, java.lang.Object, boolean)) or, for a custom operator, to that operator'sSearchSqlRenderer extension. - a
compile(Filter)caller gets the same per-leaf rendering across a resolved, cross-column tree.
The SQL result must match the in-memory result, so a built-in the dialect cannot faithfully express is rejected with a
BeanQuerySyntaxException whose code is BAD_VALUE rather than
rendered differently: an operator for which SqlDialect.builtinRenderer(String) returns $regex on a database without regex support), and a range/ordering operator ($gt, $gte,
$lt, $lte, $between) on a VERSION column when
SqlDialect.supportsVersionOrdering() is IllegalStateException.
Example:
ResolvedQuery
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionCompiles an already-resolvedFiltertree into a booleanWHEREpredicate.static SqlSearchCompilercreate(SqlDialect dialect, ColumnResolver columns) Creates a compiler for a dialect and column resolver.
-
Method Details
-
create
Creates a compiler for a dialect and column resolver.- Parameters:
dialect- The target dialect. Must not benull .columns- Maps validated column names to quoted SQL references.- Returns:
- A new compiler.
-
compile
Compiles an already-resolvedFiltertree into a booleanWHEREpredicate.Renders the full cross-column
Filter.And/Filter.Or/Filter.Nottree, so a top-level$oracross different columns (for example DataTables' global search) compiles correctly.Filter.And/Filter.Orwith no items render as always-true/always-false (1=1/1=0) per their own contract — seeSqlBeanQueryContext.appendWhere, which special-cases an empty top-level filter so an unfiltered query'sWHEREclause does not pick up a spurious(1=1).Example:
SqlFragment
where = SqlSearchCompiler.create (dialect ,columns ) .compile(filter );- Parameters:
filter- The resolved filter, ornull for no predicate.- Returns:
- The predicate fragment, or
null iffilterisnull . - Throws:
BeanQuerySyntaxException- (BAD_VALUE) If a built-in leaf is not supported by the dialect.IllegalStateException- If a custom-operator leaf cannot be rendered for the dialect.
-