Skip to content

Commit 6a372ed

Browse files
polyglot-kmp911de
authored andcommitted
Replace recursion in QueryRenderer.isSubquery(…) with loop.
Signed-off-by: KNU-K <[email protected]> Closes #4025
1 parent 42506df commit 6a372ed

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
/**
3030
* An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders an HQL query without making any changes.
3131
*
32+
* @author TaeHyun Kang(polyglot-k)
3233
* @author Greg Turnquist
3334
* @author Christoph Strobl
3435
* @since 3.1
@@ -43,19 +44,20 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
4344
*/
4445
static boolean isSubquery(ParserRuleContext ctx) {
4546

46-
if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) {
47-
return true;
48-
} else if (ctx instanceof HqlParser.SelectStatementContext) {
49-
return false;
50-
} else if (ctx instanceof HqlParser.InsertStatementContext) {
51-
return false;
52-
} else if (ctx instanceof HqlParser.DeleteStatementContext) {
53-
return false;
54-
} else if (ctx instanceof HqlParser.UpdateStatementContext) {
55-
return false;
56-
} else {
57-
return ctx.getParent() != null && isSubquery(ctx.getParent());
47+
while (ctx != null) {
48+
if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) {
49+
return true;
50+
}
51+
if (ctx instanceof HqlParser.SelectStatementContext ||
52+
ctx instanceof HqlParser.InsertStatementContext ||
53+
ctx instanceof HqlParser.DeleteStatementContext ||
54+
ctx instanceof HqlParser.UpdateStatementContext
55+
) {
56+
return false;
57+
}
58+
ctx = ctx.getParent();
5859
}
60+
return false;
5961
}
6062

6163
@Override

0 commit comments

Comments
 (0)