borinquenkid opened a new pull request, #16823:
URL: https://github.com/apache/grails-core/pull/16823
Fixes #16808
Stacked on #16822 (chain: #16816, #16817, #16818, #16820, #16821, #16822).
`no ci` until the chain reaches 8.0.x.
## Problem
- `HibernateQuery` never read the query arguments map. A criteria query
dropped `readOnly`, `fetchSize`, `timeout` and `flushMode`, which the HQL path
applied: `Person.where { ... }.list(readOnly: true)` loaded modifiable entities
and `flushMode: 'MANUAL'` still flushed first. `withCriteria(args) { }` read
only `max`, `offset` and `sort`.
- The same map was read separately by `HqlQueryMethods` and by the criteria
code, so a setting could be honoured by one path and dropped by the other.
- The criteria closures of `GormEntity.where`, `whereLazy`, `whereAny` and
`findAll` had no `@DelegatesTo`, so `eq` and `gt` did not type-check under
`@CompileStatic`.
## Changes
- New `HibernateQuerySettings` record: reads `fetchSize`, `timeout`,
`readOnly` and `flushMode` from an arguments map once. A value that is not a
whole number throws `IllegalArgumentException` naming the argument and the
value.
- `HqlQueryMethods.populateQuerySettings` and the new
`HibernateQuery.setArguments` (it now implements `QueryArgumentsAware`) both go
through it. `CriteriaMethodInvoker` passes the whole map for
`withCriteria(args)`.
- `@DelegatesTo(DetachedCriteria)` on the five `GormEntity` methods.
- Upgrade guide section 26.15.
## Tests
- `QueryArgumentsPropagationSpec` (12): `readOnly` true/false through
`where().list`, `findAll(args) { }` and `withCriteria(args) { }`, a single
result, `flushMode` MANUAL vs ALWAYS with a pending change, parsing, a bad
value, absent arguments, and a later call keeping earlier settings. Red before
the fix (8 failures).
- `HibernateQuerySettingsSpec` (18).
- `SingleResultFirstRowSpec` (3): first row on ascending and descending
order, and `null` when nothing matches.
- `GormEntityCriteriaTypingSpec`: a `@CompileStatic` class calls all five
methods. It fails to compile without the annotation.
- Whole `grails-data-hibernate7-core` suite: 4444 tests, 0 failures.
`grails-datamapping-core`: 1813, 0 failures. `codeStyle`,
`validateRepositoryConventions` and `rat` pass.
- PITest (from #16819) on `HibernateQuerySettings`: 9 mutants, 9 killed.
## Not in this PR
- `singleResult` with several matching rows keeps returning the first row,
which is the Grails convention (`find` documents it).
`SingleResultFirstRowSpec` pins it for criteria `get`, and `where` `get` and
`find`.
- The duplicate argument constants in `HibernateQueryConstants` and
`GrailsHibernateUtil` are already deprecated and are left for removal in the
Java-to-Groovy chain.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]