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.
This commit is contained in:
Greg L. Turnquist
2023-03-22 10:01:04 -05:00
parent c91839ecb1
commit 0ac0ee4b7d
4 changed files with 1 additions and 108 deletions

View File

@@ -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
;

View File

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

View File

@@ -2222,8 +2222,6 @@ class HqlQueryRenderer extends HqlBaseVisitor<List<JpaQueryParsingToken>> {
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 @@ class HqlQueryRenderer extends HqlBaseVisitor<List<JpaQueryParsingToken>> {
if (ctx.reservedWord() != null) {
return visit(ctx.reservedWord());
} else if (ctx.spelExpression() != null) {
return visit(ctx.spelExpression());
} else {
return List.of();
}
}
@Override
public List<JpaQueryParsingToken> visitSpelExpression(HqlParser.SpelExpressionContext ctx) {
List<JpaQueryParsingToken> 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<JpaQueryParsingToken> visitCharacter(HqlParser.CharacterContext ctx) {
return List.of(new JpaQueryParsingToken(ctx.CHARACTER()));

View File

@@ -2124,8 +2124,6 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
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 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<List<JpaQueryParsingToken>> {
return visit(ctx.string_literal());
}
@Override
public List<JpaQueryParsingToken> visitSpel_expression(JpqlParser.Spel_expressionContext ctx) {
List<JpaQueryParsingToken> 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<JpaQueryParsingToken> visitCharacter_valued_input_parameter(
JpqlParser.Character_valued_input_parameterContext ctx) {