|
|
|
|
@ -32,11 +32,11 @@ import org.springframework.util.CollectionUtils;
@@ -32,11 +32,11 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* @author Mark Paluch |
|
|
|
|
* @author TaeHyun Kang |
|
|
|
|
* @since 3.1 |
|
|
|
|
*/ |
|
|
|
|
@SuppressWarnings({ "ConstantConditions", "DuplicatedCode", "UnreachableCode" }) |
|
|
|
|
@ -45,42 +45,48 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
@@ -45,42 +45,48 @@ class HqlQueryRenderer extends HqlBaseVisitor<QueryTokenStream> {
|
|
|
|
|
/** |
|
|
|
|
* Is this AST tree a {@literal subquery}? |
|
|
|
|
* |
|
|
|
|
* @return boolean |
|
|
|
|
* @return {@literal true} is the query is a subquery; {@literal false} otherwise. |
|
|
|
|
*/ |
|
|
|
|
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 |
|
|
|
|
) { |
|
|
|
|
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 |
|
|
|
|
* @return {@literal true} is the query is a set query; {@literal false} otherwise. |
|
|
|
|
*/ |
|
|
|
|
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 |
|
|
|
|
&& ctx.getParent() instanceof HqlParser.QueryExpressionContext qec) { |
|
|
|
|
if (qec.orderedQuery().indexOf(ctx) != 0) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ctx = parent; |
|
|
|
|
|
|
|
|
|
ctx = ctx.getParent(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|