borinquenkid opened a new pull request, #16733:
URL: https://github.com/apache/grails-core/pull/16733

   ## Summary
   
   Resolves #16563 on 8.x. A plugin or an application can extend the Hibernate 
7 criteria builder with its own criteria and orders:
   
   - A criterion handler can take the query's `QueryPathContext` (a new small 
interface that `JpaQueryContext` implements: `getRoot()`, 
`getFullyQualifiedPath(String)`, `getFullyQualifiedExpression(String)`). 
Through it a handler resolves `alias.property` or `association.property` to the 
join GORM created for the association, so a custom criterion and a built-in one 
on the same association restrict the same row instead of each joining the 
association again. A four-argument handler keeps working; 
`ContextualCriterionHandler` is the five-argument form, and a closure with five 
parameters is coerced to it.
   - An `OrderHandler` turns a `Query.Order` subclass into a JPA order by any 
expression, in its place among the query's orders, registered in code or 
through a `META-INF/services` `OrderHandlerProvider`.
   - Handler discovery waits for the providers: `loadServiceProviders` loads 
under a lock and publishes its flag only after both `ServiceLoader` loops, so a 
query that arrives during the discovery no longer decides, with the handlers 
still unregistered, that an order has no handler. A handler registered in code 
stays ahead of a discovered one.
   - A count query leaves its orders out, handled ones too (the fix of #16731, 
included here as the same commit so this branch tests against it; the merge-up 
reconciles them).
   
   This is the 8.1.x version of #16696, which was reviewed on the 
Java-to-Groovy Hibernate 7 branch and answers that review: the interface 
instead of the context class, the discovery race, the count query, the 
reversed-order and `DetachedCriteria.list()` coverage, and the restored 
workflow triggers. #16696 becomes the merge-up of this pull request onto that 
branch.
   
   Documented in the GORM for Hibernate 7 guide (Extending the Criteria 
Builder) and the what's new of Grails 8; the `criteria-extension` example 
application exercises both handler kinds through providers.
   
   ## Verification
   
   - `HibernateCriteriaBuilderDirectSpec`: a contextual handler on an 
association path, before and after the association block; an order handler 
through the builder and through `DetachedCriteria.list()`; a `count()` with a 
handled order; a handler returning `null`.
   - `OrderHandlerDiscoverySpec`: one thread blocked inside a provider found 
through `META-INF/services`, a second lookup waits and receives the handler; 
fails with the previous flag.
   - `PredicateGeneratorSpec`, `JpaCriteriaQueryCreatorSpec`: the 
translator-level cases.
   - `:grails-data-hibernate7-core:test`, `checkstyleMain`, `codenarcTest`: see 
the CI run.
   


-- 
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]

Reply via email to