Skip to content

Commit 8a6094b

Browse files
committed
Refactor isSubquery and isSetQuery methods in EqlQueryRenderer and HqlQueryRenderer for improved readability
Signed-off-by: KNU-K <[email protected]>
1 parent 68468a0 commit 8a6094b

File tree

3 files changed

+79
-79
lines changed

3 files changed

+79
-79
lines changed

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -46,35 +46,35 @@ class EqlQueryRenderer extends EqlBaseVisitor<QueryTokenStream> {
4646
*
4747
* @return boolean
4848
*/
49-
static boolean isSubquery(ParserRuleContext ctx) {
50-
51-
while (ctx != null) {
52-
if (ctx instanceof EqlParser.SubqueryContext) {
53-
return true;
54-
}
55-
if (ctx instanceof EqlParser.Update_statementContext || ctx instanceof EqlParser.Delete_statementContext) {
56-
return false;
57-
}
58-
ctx = ctx.getParent();
59-
}
60-
return false;
61-
}
49+
static boolean isSubquery(ParserRuleContext ctx) {
50+
51+
while (ctx != null) {
52+
if (ctx instanceof EqlParser.SubqueryContext) {
53+
return true;
54+
}
55+
if (ctx instanceof EqlParser.Update_statementContext || ctx instanceof EqlParser.Delete_statementContext) {
56+
return false;
57+
}
58+
ctx = ctx.getParent();
59+
}
60+
return false;
61+
}
6262

6363
/**
6464
* Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}?
6565
*
6666
* @return boolean
6767
*/
68-
static boolean isSetQuery(ParserRuleContext ctx) {
69-
70-
while (ctx != null) {
71-
if (ctx instanceof EqlParser.Set_fuctionContext) {
72-
return true;
73-
}
74-
ctx = ctx.getParent();
75-
}
76-
return false;
77-
}
68+
static boolean isSetQuery(ParserRuleContext ctx) {
69+
70+
while (ctx != null) {
71+
if (ctx instanceof EqlParser.Set_fuctionContext) {
72+
return true;
73+
}
74+
ctx = ctx.getParent();
75+
}
76+
return false;
77+
}
7878

7979
@Override
8080
public QueryTokenStream visitStart(EqlParser.StartContext ctx) {

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -47,42 +47,42 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
4747
*
4848
* @return boolean
4949
*/
50-
static boolean isSubquery(ParserRuleContext ctx) {
51-
52-
while (ctx != null) {
53-
if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) {
54-
return true;
55-
}
56-
if (ctx instanceof HqlParser.SelectStatementContext ||
57-
ctx instanceof HqlParser.InsertStatementContext ||
58-
ctx instanceof HqlParser.DeleteStatementContext ||
59-
ctx instanceof HqlParser.UpdateStatementContext
60-
) {
61-
return false;
62-
}
63-
ctx = ctx.getParent();
64-
}
65-
return false;
66-
}
50+
static boolean isSubquery(ParserRuleContext ctx) {
51+
52+
while (ctx != null) {
53+
if (ctx instanceof HqlParser.SubqueryContext || ctx instanceof HqlParser.CteContext) {
54+
return true;
55+
}
56+
if (ctx instanceof HqlParser.SelectStatementContext ||
57+
ctx instanceof HqlParser.InsertStatementContext ||
58+
ctx instanceof HqlParser.DeleteStatementContext ||
59+
ctx instanceof HqlParser.UpdateStatementContext
60+
) {
61+
return false;
62+
}
63+
ctx = ctx.getParent();
64+
}
65+
return false;
66+
}
6767

6868
/**
6969
* Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}?
7070
*
7171
* @return boolean
7272
*/
73-
static boolean isSetQuery(ParserRuleContext ctx) {
74-
75-
while (ctx != null) {
76-
ParserRuleContext parent = ctx.getParent();
77-
if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) {
78-
if (qec.orderedQuery().indexOf(ctx) != 0) {
79-
return true;
80-
}
81-
}
82-
ctx = parent;
83-
}
84-
return false;
85-
}
73+
static boolean isSetQuery(ParserRuleContext ctx) {
74+
75+
while (ctx != null) {
76+
ParserRuleContext parent = ctx.getParent();
77+
if (ctx instanceof HqlParser.OrderedQueryContext && parent instanceof HqlParser.QueryExpressionContext qec) {
78+
if (qec.orderedQuery().indexOf(ctx) != 0) {
79+
return true;
80+
}
81+
}
82+
ctx = parent;
83+
}
84+
return false;
85+
}
8686

8787
@Override
8888
public QueryTokenStream visitStart(HqlParser.StartContext ctx) {

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -46,35 +46,35 @@ class JpqlQueryRenderer extends JpqlBaseVisitor<QueryTokenStream> {
4646
*
4747
* @return boolean
4848
*/
49-
static boolean isSubquery(ParserRuleContext ctx) {
50-
51-
while (ctx != null) {
52-
if (ctx instanceof JpqlParser.SubqueryContext) {
53-
return true;
54-
}
55-
if (ctx instanceof JpqlParser.Update_statementContext || ctx instanceof JpqlParser.Delete_statementContext) {
56-
return false;
57-
}
58-
ctx = ctx.getParent();
59-
}
60-
return false;
61-
}
49+
static boolean isSubquery(ParserRuleContext ctx) {
50+
51+
while (ctx != null) {
52+
if (ctx instanceof JpqlParser.SubqueryContext) {
53+
return true;
54+
}
55+
if (ctx instanceof JpqlParser.Update_statementContext || ctx instanceof JpqlParser.Delete_statementContext) {
56+
return false;
57+
}
58+
ctx = ctx.getParent();
59+
}
60+
return false;
61+
}
6262

6363
/**
6464
* Is this AST tree a {@literal set} query that has been added through {@literal UNION|INTERSECT|EXCEPT}?
6565
*
6666
* @return boolean
6767
*/
68-
static boolean isSetQuery(ParserRuleContext ctx) {
69-
70-
while (ctx != null) {
71-
if (ctx instanceof JpqlParser.Set_fuctionContext) {
72-
return true;
73-
}
74-
ctx = ctx.getParent();
75-
}
76-
return false;
77-
}
68+
static boolean isSetQuery(ParserRuleContext ctx) {
69+
70+
while (ctx != null) {
71+
if (ctx instanceof JpqlParser.Set_fuctionContext) {
72+
return true;
73+
}
74+
ctx = ctx.getParent();
75+
}
76+
return false;
77+
}
7878

7979
@Override
8080
public QueryTokenStream visitStart(JpqlParser.StartContext ctx) {

0 commit comments

Comments
 (0)