use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryTransformerAstBased method addWhere.
private void addWhere(CommonTree whereTree, EntityReference ref, boolean replaceVariableName) {
TreeVisitor visitor = new TreeVisitor();
VariableManipulator variableManip = new VariableManipulator();
visitor.visit(whereTree, variableManip);
if (replaceVariableName) {
Set<String> variables = variableManip.getUsedVariableNames();
if (variables.size() > 1) {
// we assume that adding where that use only one variable and does not add its own variables
throw new IllegalStateException("Multiple variables used in condition");
}
String assumedEntityVariableInWhere = variableManip.getVariableNameInUse(0);
variableManip.renameVariable(assumedEntityVariableInWhere, ref);
}
ParameterCounter parameterCounter = new ParameterCounter(true);
visitor.visit(whereTree, parameterCounter);
addedParams.addAll(parameterCounter.getParameterNames());
getQueryTransformer().mixinWhereConditionsIntoTree(whereTree);
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryTransformerAstBased method getResult.
@Override
public String getResult() {
CommonTree tree = getQueryTransformer().getTree();
TreeVisitor visitor = new TreeVisitor();
TreeToQuery treeToQuery = new TreeToQuery();
visitor.visit(tree, treeToQuery);
return treeToQuery.getQueryString().trim();
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class JoinVariableNode method toQuery.
protected String toQuery(Tree tree) {
TreeVisitor visitor = new TreeVisitor();
TreeToQuery treeToQuery = new TreeToQuery();
visitor.visit(tree, treeToQuery);
return treeToQuery.getQueryString().trim();
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryTreeAnalyzer method hasJoins.
public boolean hasJoins() {
CommonTree sourceNode = (CommonTree) tree.getFirstChildWithType(JPA2Lexer.T_SOURCES);
List<SelectionSourceNode> selectionSourceNodes = getChildrenByClass(sourceNode, SelectionSourceNode.class);
if (selectionSourceNodes.size() > 1) {
return true;
} else if (selectionSourceNodes.size() == 1) {
NodesFinder<JoinVariableNode> nodesFinder = new NodesFinder<>(JoinVariableNode.class);
TreeVisitor treeVisitor = new TreeVisitor();
treeVisitor.visit(tree, nodesFinder);
return !nodesFinder.getFoundNodes().isEmpty();
} else {
return false;
}
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryParserAstBased method getQueryPaths.
@Override
public List<QueryPath> getQueryPaths() {
List<QueryPath> queryPaths = new ArrayList<>();
QueryVariableContext context = getQueryAnalyzer().getRootQueryVariableContext();
TreeVisitor visitor = new TreeVisitor();
PathNodeFinder finder = new PathNodeFinder();
visitor.visit(getQueryAnalyzer().getTree(), finder);
for (PathNode node : finder.getSelectedPathNodes()) {
JpqlEntityModel model = context.getEntityByVariableNameHierarchically(node.getEntityVariableName());
QueryPath queryPath = new QueryPath(model.getName(), node.getEntityVariableName(), node.asPathString(), true);
queryPaths.add(queryPath);
}
for (PathNode node : finder.getOtherPathNodes()) {
JpqlEntityModel model = context.getEntityByVariableNameHierarchically(node.getEntityVariableName());
QueryPath queryPath = new QueryPath(model.getName(), node.getEntityVariableName(), node.asPathString(), false);
queryPaths.add(queryPath);
}
return queryPaths;
}
Aggregations