Skip to content

Commit 0ac0ee4

Browse files
committed
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. Original pull request: #2882.
1 parent c91839e commit 0ac0ee4

File tree

4 files changed

+1
-108
lines changed

4 files changed

+1
-108
lines changed

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Hql.g4

+1-9
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ variable
620620

621621
parameter
622622
: prefix=':' identifier
623-
| prefix='?' (INTEGER_LITERAL | spelExpression)?
623+
| prefix='?' INTEGER_LITERAL?
624624
;
625625

626626
entityName
@@ -629,16 +629,8 @@ entityName
629629

630630
identifier
631631
: reservedWord
632-
| spelExpression
633632
;
634633

635-
spelExpression
636-
: prefix='#{#' identificationVariable ('.' identificationVariable)* '}' // #{#entityName}
637-
| prefix='#{#[' INTEGER_LITERAL ']}' // #{[0]}
638-
| prefix='#{' identificationVariable '(' ( stringLiteral | '[' INTEGER_LITERAL ']' )? ')}' // #{escape([0])} | #{escapeCharacter()}
639-
;
640-
641-
642634
character
643635
: CHARACTER
644636
;

spring-data-jpa/src/main/antlr4/org/springframework/data/jpa/repository/query/Jpql.g4

-7
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ identification_variable
599599
| ORDER // Gap in the spec requires supporting 'Order' as an entity name
600600
| COUNT // Gap in the spec requires supporting 'count' as a possible name
601601
| KEY // Gap in the sepc requires supported 'key' as a possible name
602-
| spel_expression // we use various SpEL expressions in our queries
603602
;
604603

605604
constructor_name
@@ -704,12 +703,6 @@ function_name
704703
: string_literal
705704
;
706705

707-
spel_expression
708-
: prefix='#{#' identification_variable ('.' identification_variable)* '}' // #{#entityName}
709-
| prefix='#{#[' INTLITERAL ']}' // #{[0]}
710-
| prefix='#{' identification_variable '(' ( string_literal | '[' INTLITERAL ']' )? ')}' // #{escape([0])} | #{escapeCharacter()}
711-
;
712-
713706
character_valued_input_parameter
714707
: CHARACTER
715708
| input_parameter

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

-48
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,6 @@ public List<JpaQueryParsingToken> visitParameter(HqlParser.ParameterContext ctx)
22222222

22232223
if (ctx.INTEGER_LITERAL() != null) {
22242224
tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL()));
2225-
} else if (ctx.spelExpression() != null) {
2226-
tokens.addAll(visit(ctx.spelExpression()));
22272225
}
22282226
}
22292227

@@ -2251,57 +2249,11 @@ public List<JpaQueryParsingToken> visitIdentifier(HqlParser.IdentifierContext ct
22512249

22522250
if (ctx.reservedWord() != null) {
22532251
return visit(ctx.reservedWord());
2254-
} else if (ctx.spelExpression() != null) {
2255-
return visit(ctx.spelExpression());
22562252
} else {
22572253
return List.of();
22582254
}
22592255
}
22602256

2261-
@Override
2262-
public List<JpaQueryParsingToken> visitSpelExpression(HqlParser.SpelExpressionContext ctx) {
2263-
2264-
List<JpaQueryParsingToken> tokens = new ArrayList<>();
2265-
2266-
if (ctx.prefix.equals("#{#")) { // #{#entityName}
2267-
2268-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2269-
2270-
ctx.identificationVariable().forEach(identificationVariableContext -> {
2271-
tokens.addAll(visit(identificationVariableContext));
2272-
tokens.add(TOKEN_DOT);
2273-
});
2274-
CLIP(tokens);
2275-
2276-
tokens.add(TOKEN_CLOSE_BRACE);
2277-
2278-
} else if (ctx.prefix.equals("#{#[")) { // #{[0]}
2279-
2280-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2281-
tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL()));
2282-
tokens.add(TOKEN_CLOSE_SQUARE_BRACKET_BRACE);
2283-
2284-
} else if (ctx.prefix.equals("#{")) {// #{escape([0])} or #{escape('foo')}
2285-
2286-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2287-
tokens.addAll(visit(ctx.identificationVariable(0)));
2288-
tokens.add(TOKEN_OPEN_PAREN);
2289-
2290-
if (ctx.stringLiteral() != null) {
2291-
tokens.addAll(visit(ctx.stringLiteral()));
2292-
} else if (ctx.INTEGER_LITERAL() != null) {
2293-
2294-
tokens.add(TOKEN_OPEN_SQUARE_BRACKET);
2295-
tokens.add(new JpaQueryParsingToken(ctx.INTEGER_LITERAL()));
2296-
tokens.add(TOKEN_CLOSE_SQUARE_BRACKET);
2297-
}
2298-
2299-
tokens.add(TOKEN_CLOSE_PAREN_BRACE);
2300-
}
2301-
2302-
return tokens;
2303-
}
2304-
23052257
@Override
23062258
public List<JpaQueryParsingToken> visitCharacter(HqlParser.CharacterContext ctx) {
23072259
return List.of(new JpaQueryParsingToken(ctx.CHARACTER()));

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

-44
Original file line numberDiff line numberDiff line change
@@ -2124,8 +2124,6 @@ public List<JpaQueryParsingToken> visitIdentification_variable(JpqlParser.Identi
21242124
return List.of(new JpaQueryParsingToken(ctx.ORDER()));
21252125
} else if (ctx.KEY() != null) {
21262126
return List.of(new JpaQueryParsingToken(ctx.KEY()));
2127-
} else if (ctx.spel_expression() != null) {
2128-
return visit(ctx.spel_expression());
21292127
} else {
21302128
return List.of();
21312129
}
@@ -2322,48 +2320,6 @@ public List<JpaQueryParsingToken> visitFunction_name(JpqlParser.Function_nameCon
23222320
return visit(ctx.string_literal());
23232321
}
23242322

2325-
@Override
2326-
public List<JpaQueryParsingToken> visitSpel_expression(JpqlParser.Spel_expressionContext ctx) {
2327-
2328-
List<JpaQueryParsingToken> tokens = new ArrayList<>();
2329-
2330-
if (ctx.prefix.equals("#{#")) { // #{#entityName}
2331-
2332-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2333-
ctx.identification_variable().forEach(identificationVariableContext -> {
2334-
tokens.addAll(visit(identificationVariableContext));
2335-
tokens.add(TOKEN_DOT);
2336-
});
2337-
CLIP(tokens);
2338-
tokens.add(TOKEN_CLOSE_BRACE);
2339-
2340-
} else if (ctx.prefix.equals("#{#[")) { // #{[0]}
2341-
2342-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2343-
tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL()));
2344-
tokens.add(TOKEN_CLOSE_SQUARE_BRACKET_BRACE);
2345-
2346-
} else if (ctx.prefix.equals("#{")) {// #{escape([0])} or #{escape('foo')}
2347-
2348-
tokens.add(new JpaQueryParsingToken(ctx.prefix));
2349-
tokens.addAll(visit(ctx.identification_variable(0)));
2350-
tokens.add(TOKEN_OPEN_PAREN);
2351-
2352-
if (ctx.string_literal() != null) {
2353-
tokens.addAll(visit(ctx.string_literal()));
2354-
} else if (ctx.INTLITERAL() != null) {
2355-
2356-
tokens.add(TOKEN_OPEN_SQUARE_BRACKET);
2357-
tokens.add(new JpaQueryParsingToken(ctx.INTLITERAL()));
2358-
tokens.add(TOKEN_CLOSE_SQUARE_BRACKET);
2359-
}
2360-
2361-
tokens.add(TOKEN_CLOSE_PAREN_BRACE);
2362-
}
2363-
2364-
return tokens;
2365-
}
2366-
23672323
@Override
23682324
public List<JpaQueryParsingToken> visitCharacter_valued_input_parameter(
23692325
JpqlParser.Character_valued_input_parameterContext ctx) {

0 commit comments

Comments
 (0)