Interface SqlDialect
- All Known Implementing Classes:
PostgresDialect
BeanQueryContext: it quotes identifiers, renders each built-in
$-operator into a dialect-correct predicate, and renders pagination.
The shared JDBC context (the juneau-beanquery-sql module) is dialect-agnostic plumbing: it walks a parsed
search tree, delegates every leaf to the dialect, and combines leaves with AND/OR/NOT itself.
All dialect-specific SQL text — identifier quoting, the built-in operator predicates, the LIMIT/
OFFSET clause — lives here. A custom operator instead carries its own SearchSqlRenderer
(attached with SearchOperator.Builder.extension); the
context calls that renderer, passing this dialect so it can branch on id().
Juneau ships exactly one dialect today (Postgres, in juneau-beanquery-postgres). A dialect returns
builtinRenderer(String) for any built-in it cannot express (for example $regex on a
database without regex support), and the context then rejects the query with
BAD_VALUE rather than emitting SQL that differs from the in-memory
result.
Example:
SqlDialect
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbuiltinRenderer(String operatorName) The renderer for a built-in leaf operator (for example"$eq"), ornull if this dialect cannot express it.id()The stable lowercase dialect id (for example"postgres").Quotes a column or table identifier for this dialect (for exampleage→"age").renderBare(String columnSql, SearchType type, Object value, boolean quoted) Renders a bare pattern term (design §5.1) — text with optional*/?wildcards, a version prefix, or an exact value for the other types — into a predicate.renderLimitOffset(Long limit, Long offset) Renders the pagination clause appended to aSELECT(for example" LIMIT 10 OFFSET 20").default booleanWhether this dialect ordersSearchType.VERSIONcolumns as dotted integer tuples, like the in-memory engine (so9.10is greater than9.9).
-
Method Details
-
id
The stable lowercase dialect id (for example"postgres").- Returns:
- The dialect id, never
null or blank.
-
quote
Quotes a column or table identifier for this dialect (for exampleage→"age").- Parameters:
identifier- The raw identifier. Must not benull .- Returns:
- The quoted identifier.
-
renderBare
Renders a bare pattern term (design §5.1) — text with optional*/?wildcards, a version prefix, or an exact value for the other types — into a predicate.- Parameters:
columnSql- The dialect-quoted column reference. Must not benull .type- The column's value type. Must not benull .value- The literal's already-typed value (SearchExpression.typedValue()): aBigDecimalforNUMERIC, aBooleanforBOOLEAN, anOffsetDateTime,LocalDateTimeorLocalDateforTIMESTAMP, and the already-$$-decodedStringforTEXT,ID,ENUMandVERSION. Must not benull .quoted- Whether the literal was quoted in the search string; a quoted literal is never given wildcard interpretation, even if it contains*or?.- Returns:
- The predicate fragment.
-
builtinRenderer
The renderer for a built-in leaf operator (for example"$eq"), ornull if this dialect cannot express it.The context calls this only for built-in leaves; it handles the
$and/$or/$notcombinators itself. Anull return makes the context fail with a clear error rather than emit wrong SQL.- Parameters:
operatorName- The built-in operator name, including the leading$. Must not benull .- Returns:
- The renderer, or
null if unsupported.
-
supportsVersionOrdering
Whether this dialect ordersSearchType.VERSIONcolumns as dotted integer tuples, like the in-memory engine (so9.10is greater than9.9).When
false (the default), a range or ordering operator ($gt,$gte,$lt,$lte,$between) on aVERSIONcolumn is rejected withBAD_VALUEinstead of silently comparing text (where9.10sorts before9.9). Equality,$in,$neand$prefixare not affected.Example:
// A dialect that compares versions as integer tuples opts in. @Override public boolean supportsVersionOrdering() {return true ; }- Returns:
true if version range comparisons match the in-memory semantics.
-
renderLimitOffset
Renders the pagination clause appended to aSELECT(for example" LIMIT 10 OFFSET 20").The limit/offset are inlined as integer literals (never bind values), so the returned text carries no placeholders.
- Parameters:
limit- The maximum row count, ornull for no limit.offset- The zero-based start offset, ornull /0for none.- Returns:
- The pagination clause (possibly empty, never
null ).
-