From e85b1485bd6f644712bbab7a6f8a98fa3d51972f Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 07:11:35 +0900 Subject: [PATCH 01/15] Refactor subquery detection logic in JpqlQueryRenderer Signed-off-by: KNU-K --- .../repository/query/JpqlQueryRenderer.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 3e3c39fa19..5923846f68 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 @@ -47,15 +47,16 @@ class JpqlQueryRenderer extends JpqlBaseVisitor { */ static boolean isSubquery(ParserRuleContext ctx) { - if (ctx instanceof JpqlParser.SubqueryContext) { - return true; - } else if (ctx instanceof JpqlParser.Update_statementContext) { - return false; - } else if (ctx instanceof JpqlParser.Delete_statementContext) { - return false; - } else { - return ctx.getParent() != null && isSubquery(ctx.getParent()); - } + while (ctx != null) { + if (ctx instanceof JpqlParser.SubqueryContext) { + return true; + } + if (ctx instanceof JpqlParser.Update_statementContext || ctx instanceof JpqlParser.Delete_statementContext) { + return false; + } + ctx = ctx.getParent(); + } + return false; } /** From a5960e71c3362368b6a44a1175957c596cf70a39 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 07:13:38 +0900 Subject: [PATCH 02/15] Add author annotation to JpqlQueryRendererTests Signed-off-by: KNU-K --- .../data/jpa/repository/query/JpqlQueryRendererTests.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java index 707cbaf536..692b15658a 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java @@ -34,6 +34,7 @@ *
* IMPORTANT: Purely verifies the parser without any transformations. * + * @author polyglot-k * @author Greg Turnquist * @author Christoph Strobl * @author Mark Paluch From 3dd26315bfb0521f3a82982a828db7fd194fdd43 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 07:15:40 +0900 Subject: [PATCH 03/15] Add author annotation to JpqlQueryRenderer and remove from tests Signed-off-by: KNU-K --- .../data/jpa/repository/query/JpqlQueryRenderer.java | 1 + .../data/jpa/repository/query/JpqlQueryRendererTests.java | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) 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 5923846f68..a963775deb 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 @@ -32,6 +32,7 @@ /** * An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders a JPQL query without making any changes. * + * @author polyglot-k * @author Greg Turnquist * @author Christoph Strobl * @author Mark Paluch diff --git a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java index 692b15658a..707cbaf536 100644 --- a/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java +++ b/spring-data-jpa/src/test/java/org/springframework/data/jpa/repository/query/JpqlQueryRendererTests.java @@ -34,7 +34,6 @@ *
* IMPORTANT: Purely verifies the parser without any transformations. * - * @author polyglot-k * @author Greg Turnquist * @author Christoph Strobl * @author Mark Paluch From 59dc33b766c8546cdfe496d9e05f026aaca547dd Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:20:52 +0900 Subject: [PATCH 04/15] Add author annotation to EqlQueryRenderer and refactor subquery detection logic Signed-off-by: KNU-K --- .../repository/query/EqlQueryRenderer.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java index 230da53fed..e48d077479 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java @@ -32,6 +32,7 @@ /** * An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders an EQL query without making any changes. * + * @author TaeHyun Kang(polyglot-k) * @author Greg Turnquist * @author Christoph Strobl * @author Mark Paluch @@ -47,15 +48,16 @@ class EqlQueryRenderer extends EqlBaseVisitor { */ static boolean isSubquery(ParserRuleContext ctx) { - if (ctx instanceof EqlParser.SubqueryContext) { - return true; - } else if (ctx instanceof EqlParser.Update_statementContext) { - return false; - } else if (ctx instanceof EqlParser.Delete_statementContext) { - return false; - } else { - return ctx.getParent() != null && isSubquery(ctx.getParent()); - } + while (ctx != null) { + if (ctx instanceof EqlParser.SubqueryContext) { + return true; + } + if (ctx instanceof EqlParser.Update_statementContext || ctx instanceof EqlParser.Delete_statementContext) { + return false; + } + ctx = ctx.getParent(); + } + return false; } /** @@ -65,11 +67,13 @@ static boolean isSubquery(ParserRuleContext ctx) { */ static boolean isSetQuery(ParserRuleContext ctx) { - if (ctx instanceof EqlParser.Set_fuctionContext) { - return true; - } - - return ctx.getParent() != null && isSetQuery(ctx.getParent()); + while (ctx != null) { + if (ctx instanceof EqlParser.Set_fuctionContext) { + return true; + } + ctx = ctx.getParent(); + } + return false; } @Override From ea1dc95f005ef491532c074aa5f294208b7706c1 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:21:39 +0900 Subject: [PATCH 05/15] Add author annotation to HqlQueryRenderer and refactor subquery and set query detection logic Signed-off-by: KNU-K --- .../repository/query/HqlQueryRenderer.java | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) 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 15522f0263..36894ed421 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 @@ -32,6 +32,7 @@ /** * An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders an HQL query without making any changes. * + * @author TaeHyun Kang(polyglot-k) * @author Greg Turnquist * @author Christoph Strobl * @author Oscar Fanchin @@ -48,19 +49,20 @@ class HqlQueryRenderer extends HqlBaseVisitor { */ static boolean isSubquery(ParserRuleContext ctx) { - if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) { - return true; - } else if (ctx instanceof HqlParser.SelectStatementContext) { - return false; - } else if (ctx instanceof HqlParser.InsertStatementContext) { - return false; - } else if (ctx instanceof HqlParser.DeleteStatementContext) { - return false; - } else if (ctx instanceof HqlParser.UpdateStatementContext) { - return false; - } else { - return ctx.getParent() != null && isSubquery(ctx.getParent()); - } + while (ctx != null) { + if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) { + return true; + } + if (ctx instanceof HqlParser.SelectStatementContext || + ctx instanceof HqlParser.InsertStatementContext || + ctx instanceof HqlParser.DeleteStatementContext || + ctx instanceof HqlParser.UpdateStatementContext + ) { + return false; + } + ctx = ctx.getParent(); + } + return false; } /** @@ -68,17 +70,21 @@ static boolean isSubquery(ParserRuleContext ctx) { * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { - - if (ctx instanceof HqlParser.OrderedQueryContext - && ctx.getParent() instanceof HqlParser.QueryExpressionContext qec) { - if (qec.orderedQuery().indexOf(ctx) != 0) { - return true; - } - } - - return ctx.getParent() != null && isSetQuery(ctx.getParent()); - } + static boolean isSetQuery(ParserRuleContext ctx) { + while (ctx != null) { + ParserRuleContext parent = ctx.getParent(); + + if (ctx instanceof HqlParser.OrderedQueryContext + && parent instanceof HqlParser.QueryExpressionContext qec) { + if (qec.orderedQuery().indexOf(ctx) != 0) { + return true; + } + } + + ctx = parent; + } + return false; + } @Override public QueryTokenStream visitStart(HqlParser.StartContext ctx) { From 17f7ce92dc99cce44909d18a7af316d83a5262c7 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:21:47 +0900 Subject: [PATCH 06/15] Update author annotation in JpqlQueryRenderer and refactor isSetQuery method for improved readability Signed-off-by: KNU-K --- .../jpa/repository/query/JpqlQueryRenderer.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 a963775deb..d15717108c 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 @@ -32,7 +32,7 @@ /** * An ANTLR {@link org.antlr.v4.runtime.tree.ParseTreeVisitor} that renders a JPQL query without making any changes. * - * @author polyglot-k + * @author TaeHyun Kang(polyglot-k) * @author Greg Turnquist * @author Christoph Strobl * @author Mark Paluch @@ -67,11 +67,13 @@ static boolean isSubquery(ParserRuleContext ctx) { */ static boolean isSetQuery(ParserRuleContext ctx) { - if (ctx instanceof JpqlParser.Set_fuctionContext) { - return true; - } - - return ctx.getParent() != null && isSetQuery(ctx.getParent()); + while (ctx != null) { + if (ctx instanceof JpqlParser.Set_fuctionContext) { + return true; + } + ctx = ctx.getParent(); + } + return false; } @Override From 7e9cb507dfc0ddf348505adfb630aca3775215ae Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:54:04 +0900 Subject: [PATCH 07/15] Refactor isSetQuery method in EqlQueryRenderer, HqlQueryRenderer, and JpqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/EqlQueryRenderer.java | 1 + .../data/jpa/repository/query/JpqlQueryRenderer.java | 1 + 2 files changed, 2 insertions(+) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java index e48d077479..fd0d24966e 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java @@ -71,6 +71,7 @@ static boolean isSetQuery(ParserRuleContext ctx) { if (ctx instanceof EqlParser.Set_fuctionContext) { return true; } + ctx = ctx.getParent(); } return false; 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 d15717108c..71bf7e5b93 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 @@ -71,6 +71,7 @@ static boolean isSetQuery(ParserRuleContext ctx) { if (ctx instanceof JpqlParser.Set_fuctionContext) { return true; } + ctx = ctx.getParent(); } return false; From 42325000b5357eba634e5a05e9e2ab8715efcf98 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:57:22 +0900 Subject: [PATCH 08/15] Refactor isSetQuery method in HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/HqlQueryRenderer.java | 1 - 1 file changed, 1 deletion(-) 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 36894ed421..edf71032d2 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 @@ -80,7 +80,6 @@ static boolean isSetQuery(ParserRuleContext ctx) { return true; } } - ctx = parent; } return false; From 3a92ca811f19c02c4248853efdbb79e2a12ae8ea Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:58:06 +0900 Subject: [PATCH 09/15] Refactor isSetQuery method in HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/HqlQueryRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 edf71032d2..513b13d5ef 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 @@ -73,7 +73,7 @@ static boolean isSubquery(ParserRuleContext ctx) { static boolean isSetQuery(ParserRuleContext ctx) { while (ctx != null) { ParserRuleContext parent = ctx.getParent(); - + if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { if (qec.orderedQuery().indexOf(ctx) != 0) { From a42045fd2498099bd2aebc70e24c7570167d40f3 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 18:58:13 +0900 Subject: [PATCH 10/15] Refactor isSetQuery method in HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/HqlQueryRenderer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 513b13d5ef..edf71032d2 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 @@ -73,7 +73,7 @@ static boolean isSubquery(ParserRuleContext ctx) { static boolean isSetQuery(ParserRuleContext ctx) { while (ctx != null) { ParserRuleContext parent = ctx.getParent(); - + if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { if (qec.orderedQuery().indexOf(ctx) != 0) { From a58181c3ac9b90f637485ecf20aae288e259aac0 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 19:01:26 +0900 Subject: [PATCH 11/15] Refactor isSetQuery method in HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/HqlQueryRenderer.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 edf71032d2..c150a3ddd3 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 @@ -54,9 +54,9 @@ static boolean isSubquery(ParserRuleContext ctx) { return true; } if (ctx instanceof HqlParser.SelectStatementContext || - ctx instanceof HqlParser.InsertStatementContext || - ctx instanceof HqlParser.DeleteStatementContext || - ctx instanceof HqlParser.UpdateStatementContext + ctx instanceof HqlParser.InsertStatementContext || + ctx instanceof HqlParser.DeleteStatementContext || + ctx instanceof HqlParser.UpdateStatementContext ) { return false; } @@ -73,9 +73,7 @@ static boolean isSubquery(ParserRuleContext ctx) { static boolean isSetQuery(ParserRuleContext ctx) { while (ctx != null) { ParserRuleContext parent = ctx.getParent(); - - if (ctx instanceof HqlParser.OrderedQueryContext - && parent instanceof HqlParser.QueryExpressionContext qec) { + if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { if (qec.orderedQuery().indexOf(ctx) != 0) { return true; } From 41002228756e26f70f46b3c8a3e21c8a779ac954 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 19:13:39 +0900 Subject: [PATCH 12/15] Refactor isSubquery and isSetQuery methods in EqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/EqlQueryRenderer.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java index fd0d24966e..b8696c604f 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java @@ -46,7 +46,7 @@ class EqlQueryRenderer extends EqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { + static boolean isSubquery(ParserRuleContext ctx) { while (ctx != null) { if (ctx instanceof EqlParser.SubqueryContext) { @@ -58,24 +58,23 @@ static boolean isSubquery(ParserRuleContext ctx) { ctx = ctx.getParent(); } return false; - } + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { + static boolean isSetQuery(ParserRuleContext ctx) { while (ctx != null) { if (ctx instanceof EqlParser.Set_fuctionContext) { return true; } - ctx = ctx.getParent(); } return false; - } + } @Override public QueryTokenStream visitStart(EqlParser.StartContext ctx) { From 9a6b0dae47b04ce59025f9f893399d3f04264989 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 19:14:33 +0900 Subject: [PATCH 13/15] Refactor isSubquery and isSetQuery methods in HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/HqlQueryRenderer.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 c150a3ddd3..1573acfe98 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 @@ -47,7 +47,7 @@ class HqlQueryRenderer extends HqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { + static boolean isSubquery(ParserRuleContext ctx) { while (ctx != null) { if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) { @@ -63,7 +63,7 @@ static boolean isSubquery(ParserRuleContext ctx) { ctx = ctx.getParent(); } return false; - } + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? @@ -71,6 +71,7 @@ static boolean isSubquery(ParserRuleContext ctx) { * @return boolean */ static boolean isSetQuery(ParserRuleContext ctx) { + while (ctx != null) { ParserRuleContext parent = ctx.getParent(); if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { From 68468a01ac1f47d2ede7cee28c4bde950504d9f0 Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 19:15:15 +0900 Subject: [PATCH 14/15] Refactor isSubquery and isSetQuery methods in JpqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../data/jpa/repository/query/JpqlQueryRenderer.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 71bf7e5b93..ba99398ec5 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 @@ -46,7 +46,7 @@ class JpqlQueryRenderer extends JpqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { + static boolean isSubquery(ParserRuleContext ctx) { while (ctx != null) { if (ctx instanceof JpqlParser.SubqueryContext) { @@ -58,24 +58,23 @@ static boolean isSubquery(ParserRuleContext ctx) { ctx = ctx.getParent(); } return false; - } + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { + static boolean isSetQuery(ParserRuleContext ctx) { while (ctx != null) { if (ctx instanceof JpqlParser.Set_fuctionContext) { return true; } - ctx = ctx.getParent(); } return false; - } + } @Override public QueryTokenStream visitStart(JpqlParser.StartContext ctx) { From 8a6094b542306c653e4011dc489ad77861a0ed8a Mon Sep 17 00:00:00 2001 From: KNU-K Date: Fri, 26 Sep 2025 19:19:50 +0900 Subject: [PATCH 15/15] Refactor isSubquery and isSetQuery methods in EqlQueryRenderer and HqlQueryRenderer for improved readability Signed-off-by: KNU-K --- .../repository/query/EqlQueryRenderer.java | 48 +++++++------- .../repository/query/HqlQueryRenderer.java | 62 +++++++++---------- .../repository/query/JpqlQueryRenderer.java | 48 +++++++------- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java index b8696c604f..2a19abc3c5 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/EqlQueryRenderer.java @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,35 +46,35 @@ class EqlQueryRenderer extends EqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { - - while (ctx != null) { - if (ctx instanceof EqlParser.SubqueryContext) { - return true; - } - if (ctx instanceof EqlParser.Update_statementContext || ctx instanceof EqlParser.Delete_statementContext) { - return false; - } - ctx = ctx.getParent(); - } - return false; - } + static boolean isSubquery(ParserRuleContext ctx) { + + while (ctx != null) { + if (ctx instanceof EqlParser.SubqueryContext) { + return true; + } + if (ctx instanceof EqlParser.Update_statementContext || ctx instanceof EqlParser.Delete_statementContext) { + return false; + } + ctx = ctx.getParent(); + } + return false; + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { - - while (ctx != null) { - if (ctx instanceof EqlParser.Set_fuctionContext) { - return true; - } - ctx = ctx.getParent(); - } - return false; - } + static boolean isSetQuery(ParserRuleContext ctx) { + + while (ctx != null) { + if (ctx instanceof EqlParser.Set_fuctionContext) { + return true; + } + ctx = ctx.getParent(); + } + return false; + } @Override public QueryTokenStream visitStart(EqlParser.StartContext ctx) { 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 1573acfe98..e93f34e584 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 @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -47,42 +47,42 @@ class HqlQueryRenderer extends HqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { - - while (ctx != null) { - if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) { - return true; - } - if (ctx instanceof HqlParser.SelectStatementContext || - ctx instanceof HqlParser.InsertStatementContext || - ctx instanceof HqlParser.DeleteStatementContext || - ctx instanceof HqlParser.UpdateStatementContext - ) { - return false; - } - ctx = ctx.getParent(); - } - return false; - } + static boolean isSubquery(ParserRuleContext ctx) { + + while (ctx != null) { + if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) { + return true; + } + if (ctx instanceof HqlParser.SelectStatementContext || + ctx instanceof HqlParser.InsertStatementContext || + ctx instanceof HqlParser.DeleteStatementContext || + ctx instanceof HqlParser.UpdateStatementContext + ) { + return false; + } + ctx = ctx.getParent(); + } + return false; + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { - - while (ctx != null) { - ParserRuleContext parent = ctx.getParent(); - if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { - if (qec.orderedQuery().indexOf(ctx) != 0) { - return true; - } - } - ctx = parent; - } - return false; - } + static boolean isSetQuery(ParserRuleContext ctx) { + + while (ctx != null) { + ParserRuleContext parent = ctx.getParent(); + if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) { + if (qec.orderedQuery().indexOf(ctx) != 0) { + return true; + } + } + ctx = parent; + } + return false; + } @Override public QueryTokenStream visitStart(HqlParser.StartContext ctx) { 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 ba99398ec5..e768260fc5 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 @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * https://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -46,35 +46,35 @@ class JpqlQueryRenderer extends JpqlBaseVisitor { * * @return boolean */ - static boolean isSubquery(ParserRuleContext ctx) { - - while (ctx != null) { - if (ctx instanceof JpqlParser.SubqueryContext) { - return true; - } - if (ctx instanceof JpqlParser.Update_statementContext || ctx instanceof JpqlParser.Delete_statementContext) { - return false; - } - ctx = ctx.getParent(); - } - return false; - } + static boolean isSubquery(ParserRuleContext ctx) { + + while (ctx != null) { + if (ctx instanceof JpqlParser.SubqueryContext) { + return true; + } + if (ctx instanceof JpqlParser.Update_statementContext || ctx instanceof JpqlParser.Delete_statementContext) { + return false; + } + ctx = ctx.getParent(); + } + return false; + } /** * Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}? * * @return boolean */ - static boolean isSetQuery(ParserRuleContext ctx) { - - while (ctx != null) { - if (ctx instanceof JpqlParser.Set_fuctionContext) { - return true; - } - ctx = ctx.getParent(); - } - return false; - } + static boolean isSetQuery(ParserRuleContext ctx) { + + while (ctx != null) { + if (ctx instanceof JpqlParser.Set_fuctionContext) { + return true; + } + ctx = ctx.getParent(); + } + return false; + } @Override public QueryTokenStream visitStart(JpqlParser.StartContext ctx) {