Merged
Conversation
Immutable config holder with JVM-wide global (volatile static) and per-instance override support (builder.withDefaults(...)). Configures: - SQL dialect (default: STANDARD) - Default SELECT column expression (default: "*") - Default LIMIT / OFFSET (default: -1, i.e. none) - LIKE prefix / suffix (default: "%" / "%") Global is captured at builder construction time so behaviour is predictable across concurrent updates.
Three new fields propagated from QueryBuilderDefaults into the Query
data object at build() time so dialect-agnostic renderers can read them:
- defaultSelectColumns (fallback when selectColumns is empty)
- likePrefix (prepended to LIKE / NOT LIKE values)
- likeSuffix (appended to LIKE / NOT LIKE values)
All fields default to the existing hardcoded behaviour ("*", "%", "%")
so there is no change to query output without an explicit configuration.
AbstractSqlDialect now reads from the Query object instead of using hardcoded literals: - appendSelectColumns: uses query.getDefaultSelectColumns() instead of "*" - LIKE / NOT LIKE params: uses query.getLikePrefix()/getLikeSuffix() instead of hardcoded "%" + val + "%" appendConditionFragment gains a Query parameter to pass the hints through to appendNonComparisonFragment.
QueryBuilder, DeleteBuilder, and SelectBuilder each gain: - A queryBuilderDefaults field initialised from QueryBuilderDefaults.global() at construction time (snapshot semantics — not live). - A withDefaults(QueryBuilderDefaults) fluent method for per-instance override without touching the global. Behavioural changes when a non-default QueryBuilderDefaults is active: - Dialect: buildSql() / build() null-fallback now routes to the configured dialect instead of hardcoded SqlDialect.STANDARD. - Default columns: rendered when no explicit select() columns are set. - Default limit / offset: applied when builder sentinel (-1) is present and the defaults carry a non-negative value (explicit wins). - LIKE wrapping: SelectBuilder.whereLike() now honours likePrefix / likeSuffix (previously had no wrapping at all — aligned with AbstractSqlDialect behaviour).
…ping
QueryBuilderDefaultsTest (23 tests) covers:
- Canonical global defaults (STANDARD, "*", -1, -1, "%", "%")
- builder() and builder(source) factory methods
- setGlobal(null) NPE guard
- withDefaults(null) NPE guard on all three builders
- Global dialect applied to newly created QueryBuilder
- Per-instance withDefaults() overrides global for that instance only
- Explicit buildSql(table, dialect) parameter wins over configured default
- defaultColumns / explicit select() winner semantics
- defaultLimit / defaultOffset applied and overridden correctly
- Custom likePrefix / likeSuffix applied (QueryBuilder + SelectBuilder)
- DeleteBuilder dialect routing via withDefaults()
- SelectBuilder defaultColumns, defaultLimit, LIKE wrapping
SelectBuilderTest.testWhereLike: updated to pass the raw value ("bob")
instead of pre-wrapped "%bob%" now that SelectBuilder auto-wraps using
the configured likePrefix/likeSuffix (consistent with QueryBuilder).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New:
QueryBuilderDefaults— configure dialect and query defaults upfrontIntroduces an immutable
QueryBuilderDefaultsclass that centralises the defaultvalues applied by every builder. Configure once at application startup; all builders
constructed afterward pick it up automatically. Each builder also accepts a
per-instance override via
withDefaults()without touching the global.Configurable defaults
dialectSqlDialect.STANDARDbuildSql()/build()defaultColumns"*".select()columns are specifieddefaultLimit-1(none)LIMITapplied when no.limit()call is madedefaultOffset-1(none)OFFSETapplied when no.offset()call is madelikePrefix"%"LIKE/NOT LIKEconditionslikeSuffix"%"LIKE/NOT LIKEconditionsExplicit per-call values always win over configured defaults.
Builders updated
QueryBuilder— gainswithDefaults()and applies dialect/defaults inbuildSql()DeleteBuilder— gainswithDefaults()and applies dialect inbuild()SelectBuilder— gainswithDefaults()and applies all defaults inbuild()whereLike()now auto-wraps the value usinglikePrefix/likeSuffix,consistent with
QueryBuilderandAbstractSqlDialect. Previously no wrapping was applied.Breaking changes
SelectBuilder.whereLike(column, value)— pass the raw value (e.g."bob");%wrapping is now applied automatically. If your code was passing"%bob%"manually,remove the manual wrapping.
AbstractSqlDialect.appendConditionFragmentgains aQueryparameter.Custom subclasses that override this protected method must update their signature.