Skip to content

Commit 87b700b

Browse files
committed
Polishing.
Remove method overloads accepting pure strings. Use switch-expressions. Correctly navigate nested joins. Introduce PathExpression interface, refine naming.
1 parent 423b8b0 commit 87b700b

File tree

9 files changed

+465
-469
lines changed

9 files changed

+465
-469
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpaQueryCreator.java

+8-12
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
*/
1616
package org.springframework.data.jpa.repository.query;
1717

18-
import static org.springframework.data.repository.query.parser.Part.Type.IS_NOT_EMPTY;
19-
import static org.springframework.data.repository.query.parser.Part.Type.NOT_CONTAINING;
20-
import static org.springframework.data.repository.query.parser.Part.Type.NOT_LIKE;
21-
import static org.springframework.data.repository.query.parser.Part.Type.SIMPLE_PROPERTY;
18+
import static org.springframework.data.repository.query.parser.Part.Type.*;
2219

2320
import jakarta.persistence.EntityManager;
2421
import jakarta.persistence.criteria.CriteriaQuery;
@@ -39,7 +36,6 @@
3936
import org.springframework.data.domain.Sort;
4037
import org.springframework.data.jpa.domain.JpaSort;
4138
import org.springframework.data.jpa.repository.query.JpqlQueryBuilder.ParameterPlaceholder;
42-
import org.springframework.data.jpa.repository.query.JpqlQueryBuilder.PathAndOrigin;
4339
import org.springframework.data.jpa.repository.query.ParameterBinding.PartTreeParameterBinding;
4440
import org.springframework.data.jpa.repository.support.JpqlQueryTemplates;
4541
import org.springframework.data.mapping.PropertyPath;
@@ -182,8 +178,8 @@ protected JpqlQueryBuilder.Select buildQuery(Sort sort) {
182178
QueryUtils.checkSortExpression(order);
183179

184180
try {
185-
expression = JpqlQueryBuilder.expression(JpqlUtils.toExpressionRecursively(metamodel, entity, entityType,
186-
PropertyPath.from(order.getProperty(), entityType.getJavaType())));
181+
expression = JpqlUtils.toExpressionRecursively(metamodel, entity, entityType,
182+
PropertyPath.from(order.getProperty(), entityType.getJavaType()));
187183
} catch (PropertyReferenceException e) {
188184

189185
if (order instanceof JpaSort.JpaOrder jpaOrder && jpaOrder.isUnsafe()) {
@@ -226,7 +222,7 @@ private JpqlQueryBuilder.Select doSelect(Sort sort) {
226222
requiredSelection = getRequiredSelection(sort, returnedType);
227223
}
228224

229-
List<PathAndOrigin> paths = new ArrayList<>(requiredSelection.size());
225+
List<JpqlQueryBuilder.PathExpression> paths = new ArrayList<>(requiredSelection.size());
230226
for (String selection : requiredSelection) {
231227
paths.add(JpqlUtils.toExpressionRecursively(metamodel, entity, entityType,
232228
PropertyPath.from(selection, returnedType.getDomainType()), true));
@@ -250,7 +246,7 @@ private JpqlQueryBuilder.Select doSelect(Sort sort) {
250246

251247
} else {
252248

253-
List<PathAndOrigin> paths = entityType.getIdClassAttributes().stream()//
249+
List<JpqlQueryBuilder.PathExpression> paths = entityType.getIdClassAttributes().stream()//
254250
.map(it -> JpqlUtils.toExpressionRecursively(metamodel, entity, entityType,
255251
PropertyPath.from(it.getName(), returnedType.getDomainType()), true))
256252
.toList();
@@ -319,7 +315,7 @@ public JpqlQueryBuilder.Predicate build() {
319315
PropertyPath property = part.getProperty();
320316
Type type = part.getType();
321317

322-
PathAndOrigin pas = JpqlUtils.toExpressionRecursively(metamodel, entity, entityType, property);
318+
JpqlQueryBuilder.PathExpression pas = JpqlUtils.toExpressionRecursively(metamodel, entity, entityType, property);
323319
JpqlQueryBuilder.WhereStep where = JpqlQueryBuilder.where(pas);
324320
JpqlQueryBuilder.WhereStep whereIgnoreCase = JpqlQueryBuilder.where(potentiallyIgnoreCase(pas));
325321

@@ -419,8 +415,8 @@ private <T> JpqlQueryBuilder.Expression potentiallyIgnoreCase(JpqlQueryBuilder.O
419415
* @param path must not be {@literal null}.
420416
* @return
421417
*/
422-
private <T> JpqlQueryBuilder.Expression potentiallyIgnoreCase(PathAndOrigin path) {
423-
return potentiallyIgnoreCase(path.path(), JpqlQueryBuilder.expression(path));
418+
private <T> JpqlQueryBuilder.Expression potentiallyIgnoreCase(JpqlQueryBuilder.PathExpression path) {
419+
return potentiallyIgnoreCase(path.getPropertyPath(), path);
424420
}
425421

426422
/**

0 commit comments

Comments
 (0)