borinquenkid commented on code in PR #16733: URL: https://github.com/apache/grails-core/pull/16733#discussion_r4361020581
########## grails-test-examples/hibernate7/criteria-extension/src/main/resources/META-INF/services/org.grails.orm.hibernate.query.PredicateGenerator$OrderHandlerProvider: ########## @@ -0,0 +1 @@ +example.query.PriceDistanceOrderHandlerProvider Review Comment: Done in 54a44543b2: the example's order provider file has the ASF header, as the test resource's has. ########## grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/QueryPathContext.java: ########## @@ -0,0 +1,49 @@ +/* + * Copyright 2024-2025 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.grails.orm.hibernate.query; + +import jakarta.persistence.criteria.Expression; +import jakarta.persistence.criteria.From; +import jakarta.persistence.criteria.Path; + +/** + * What a criterion or order handler sees of the query it converts for: the root of the query and the resolution + * of property paths the way the built-in criteria resolve them. {@code alias.property}, for an alias created with + * {@code createAlias}, or {@code association.property} becomes a path on the join GORM created for that + * association, so a custom criterion and a built-in one on the same association restrict the same row rather + * than each joining the association again. + * + * @since 8.1 + */ +public interface QueryPathContext { + + /** + * @return the root of the query or subquery the handler converts for + */ + From<?, ?> getRoot(); + + /** + * @param path a property path: {@code property}, {@code association.property} or {@code alias.property} + * @return the path, or {@code null} when the property path resolves to an expression that is not a path + */ + Path<?> getFullyQualifiedPath(String path); + + /** + * @param path a property path, or the alias of a projection Review Comment: Done in 54a44543b2, with one limit. `getFullyQualifiedExpression('total')` now returns the projection a `sqlProjection` alias stands for when no property resolves the path, and a handler that orders through it gets `order by 1 desc`, asserted next to the `getSelectionAlias` case. When a property has the alias's name the property wins, because `a restriction on a property is not resolved to a SQL projection with the same alias` is an existing behavior with its own specs; `getSelectionAlias` asks for the alias alone in that case. The javadoc says so. ########## grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/query/JpaQueryContext.java: ########## @@ -173,6 +175,7 @@ public Expression<?> getAliasedExpression(String alias) { return expr; } + @Override public Expression<?> getFullyQualifiedExpression(String path) { Review Comment: Same change as the thread above (54a44543b2): the path resolves to the recorded selection when no property has the name, and the order goes through `getFullyQualifiedExpression('total')` in a spec of its own. -- 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]
