From 5150f3199d130f72ac4b891a1bacee3bf6993106 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Wed, 22 Mar 2023 09:56:17 -0500 Subject: [PATCH 1/2] New issue. --- pom.xml | 2 +- spring-data-envers/pom.xml | 4 ++-- spring-data-jpa-distribution/pom.xml | 2 +- spring-data-jpa/pom.xml | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c77686453f..c2f7f51254 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-jpa-parent - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT pom Spring Data JPA Parent diff --git a/spring-data-envers/pom.xml b/spring-data-envers/pom.xml index db915d7c3b..94167dc766 100755 --- a/spring-data-envers/pom.xml +++ b/spring-data-envers/pom.xml @@ -5,12 +5,12 @@ org.springframework.data spring-data-envers - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT org.springframework.data spring-data-jpa-parent - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa-distribution/pom.xml b/spring-data-jpa-distribution/pom.xml index a5cb2f09b5..b56b1026e1 100644 --- a/spring-data-jpa-distribution/pom.xml +++ b/spring-data-jpa-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-jpa-parent - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT ../pom.xml diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index 27313e9e3c..c4fc632126 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -6,7 +6,7 @@ org.springframework.data spring-data-jpa - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT Spring Data JPA Spring Data module for JPA repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-jpa-parent - 3.1.0-SNAPSHOT + 3.1.0-gh-2881-SNAPSHOT ../pom.xml From b7aab64f1e292b372f15567d07c10c373fb03b64 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Wed, 22 Mar 2023 10:01:04 -0500 Subject: [PATCH 2/2] Drop support for SpEL expressions in the query parsers. By delaying the creation of count queries beyond the point where SpEL evaluation is carried out, there is no longer a need to handle SpEL expressions in the query parsers. Resolves #2881. --- .../data/jpa/repository/query/Hql.g4 | 10 +--- .../data/jpa/repository/query/Jpql.g4 | 7 --- .../repository/query/HqlQueryRenderer.java | 48 ------------------- .../repository/query/JpqlQueryRenderer.java | 44 ----------------- 4 files changed, 1 insertion(+), 108 deletions(-) diff --git a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 index 253caafc11..568f5a2355 100644 --- a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 +++ b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4 @@ -620,7 +620,7 @@ variable parameter : prefix=':' identifier - | prefix='?' (INTEGER_LITERAL | spelExpression)? + | prefix='?' INTEGER_LITERAL? ; entityName @@ -629,16 +629,8 @@ entityName identifier : reservedWord - | spelExpression ; -spelExpression - : prefix='#{#' identificationVariable ('.' identificationVariable)* '}' // #{#entityName} - | prefix='#{#[' INTEGER_LITERAL ']}' // #{[0]} - | prefix='#{' identificationVariable '(' ( stringLiteral | '[' INTEGER_LITERAL ']' )? ')}' // #{escape([0])} | #{escapeCharacter()} - ; - - character : CHARACTER ; diff --git a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 index dc96a6ea46..2b5cc7ca44 100644 --- a/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 +++ b/spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4 @@ -599,7 +599,6 @@ identification_variable | ORDER // Gap in the spec requires supporting 'Order' as an entity name | COUNT // Gap in the spec requires supporting 'count' as a possible name | KEY // Gap in the sepc requires supported 'key' as a possible name - | spel_expression // we use various SpEL expressions in our queries ; constructor_name @@ -704,12 +703,6 @@ function_name : string_literal ; -spel_expression - : prefix='#{#' identification_variable ('.' identification_variable)* '}' // #{#entityName} - | prefix='#{#[' INTLITERAL ']}' // #{[0]} - | prefix='#{' identification_variable '(' ( string_literal | '[' INTLITERAL ']' )? ')}' // #{escape([0])} | #{escapeCharacter()} - ; - character_valued_input_parameter : CHARACTER | input_parameter diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java index c7930c3dcd..f613352d6f 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/HqlQueryRenderer.java @@ -2222,8 +2222,6 @@ public List visitParameter(HqlParser.ParameterContext ctx) if (ctx.INTEGER_LITERAL() != null) { tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL())); - } else if (ctx.spelExpression() != null) { - tokens.addAll(visit(ctx.spelExpression())); } } @@ -2251,57 +2249,11 @@ public List visitIdentifier(HqlParser.IdentifierContext ct if (ctx.reservedWord() != null) { return visit(ctx.reservedWord()); - } else if (ctx.spelExpression() != null) { - return visit(ctx.spelExpression()); } else { return List.of(); } } - @Override - public List visitSpelExpression(HqlParser.SpelExpressionContext ctx) { - - List tokens = new ArrayList<>(); - - if (ctx.prefix.equals("#{#")) { // #{#entityName} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - - ctx.identificationVariable().forEach(identificationVariableContext -> { - tokens.addAll(visit(identificationVariableContext)); - tokens.add(TOKEN_DOT); - }); - CLIP(tokens); - - tokens.add(TOKEN_CLOSE_BRACE); - - } else if (ctx.prefix.equals("#{#[")) { // #{[0]} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL())); - tokens.add(TOKEN_CLOSE_SQUARE_BRACKET_BRACE); - - } else if (ctx.prefix.equals("#{")) {// #{escape([0])} or #{escape('foo')} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - tokens.addAll(visit(ctx.identificationVariable(0))); - tokens.add(TOKEN_OPEN_PAREN); - - if (ctx.stringLiteral() != null) { - tokens.addAll(visit(ctx.stringLiteral())); - } else if (ctx.INTEGER_LITERAL() != null) { - - tokens.add(TOKEN_OPEN_SQUARE_BRACKET); - tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL())); - tokens.add(TOKEN_CLOSE_SQUARE_BRACKET); - } - - tokens.add(TOKEN_CLOSE_PAREN_BRACE); - } - - return tokens; - } - @Override public List visitCharacter(HqlParser.CharacterContext ctx) { return List.of(new JpaQueryParsingToken(ctx.CHARACTER())); diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java index e433713319..0598e7029f 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/JpqlQueryRenderer.java @@ -2124,8 +2124,6 @@ public List visitIdentification_variable(JpqlParser.Identi return List.of(new JpaQueryParsingToken(ctx.ORDER())); } else if (ctx.KEY() != null) { return List.of(new JpaQueryParsingToken(ctx.KEY())); - } else if (ctx.spel_expression() != null) { - return visit(ctx.spel_expression()); } else { return List.of(); } @@ -2322,48 +2320,6 @@ public List visitFunction_name(JpqlParser.Function_nameCon return visit(ctx.string_literal()); } - @Override - public List visitSpel_expression(JpqlParser.Spel_expressionContext ctx) { - - List tokens = new ArrayList<>(); - - if (ctx.prefix.equals("#{#")) { // #{#entityName} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - ctx.identification_variable().forEach(identificationVariableContext -> { - tokens.addAll(visit(identificationVariableContext)); - tokens.add(TOKEN_DOT); - }); - CLIP(tokens); - tokens.add(TOKEN_CLOSE_BRACE); - - } else if (ctx.prefix.equals("#{#[")) { // #{[0]} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL())); - tokens.add(TOKEN_CLOSE_SQUARE_BRACKET_BRACE); - - } else if (ctx.prefix.equals("#{")) {// #{escape([0])} or #{escape('foo')} - - tokens.add(new JpaQueryParsingToken(ctx.prefix)); - tokens.addAll(visit(ctx.identification_variable(0))); - tokens.add(TOKEN_OPEN_PAREN); - - if (ctx.string_literal() != null) { - tokens.addAll(visit(ctx.string_literal())); - } else if (ctx.INTLITERAL() != null) { - - tokens.add(TOKEN_OPEN_SQUARE_BRACKET); - tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL())); - tokens.add(TOKEN_CLOSE_SQUARE_BRACKET); - } - - tokens.add(TOKEN_CLOSE_PAREN_BRACE); - } - - return tokens; - } - @Override public List visitCharacter_valued_input_parameter( JpqlParser.Character_valued_input_parameterContext ctx) {