use of com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode in project cuba by cuba-platform.
the class QueryTransformerAstBased method addJoinAsIs.
@Override
public void addJoinAsIs(String join) {
String[] strings = join.split(",");
join = strings[0];
try {
List<JoinVariableNode> joinVariableNodes = Parser.parseJoinClause(join);
for (JoinVariableNode joinVariableNode : joinVariableNodes) {
getQueryTransformer().mixinJoinIntoTree(joinVariableNode, new EntityNameEntityReference(getMainEntityName()), false);
}
for (int i = 1; i < strings.length; i++) {
CommonTree selectionSource = Parser.parseSelectionSource(strings[i]);
getQueryTransformer().addSelectionSource(selectionSource);
}
} catch (RecognitionException e) {
throw new RuntimeException(e);
}
}
use of com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode in project cuba by cuba-platform.
the class QueryTransformerAstBased method addJoinAndWhere.
@Override
public void addJoinAndWhere(String join, String where) {
EntityReferenceInferer inferer = new EntityReferenceInferer(getMainEntityName());
EntityReference ref = inferer.infer(getQueryTransformer());
if (where.contains("{E}")) {
where = ref.replaceEntries(where, "\\{E\\}");
}
if (join.contains("{E}")) {
join = ref.replaceEntries(join, "\\{E\\}");
}
String[] strings = join.split(",");
join = strings[0];
try {
if (StringUtils.isNotBlank(join)) {
List<JoinVariableNode> joinVariableNodes = Parser.parseJoinClause(join);
boolean firstJoin = true;
for (JoinVariableNode joinVariableNode : joinVariableNodes) {
getQueryTransformer().mixinJoinIntoTree(joinVariableNode, ref, firstJoin);
firstJoin = false;
}
}
for (int i = 1; i < strings.length; i++) {
CommonTree selectionSource = Parser.parseSelectionSource(strings[i]);
getQueryTransformer().addSelectionSource(selectionSource);
}
CommonTree whereTree = Parser.parseWhereClause("where " + where);
addWhere(whereTree, ref, false);
} catch (RecognitionException e) {
throw new RuntimeException(e);
}
}
use of com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode in project cuba by cuba-platform.
the class IdVarSelector method post.
@Override
public Object post(Object t) {
if (!(t instanceof CommonTree))
return t;
if (t instanceof CommonErrorNode) {
return t;
}
CommonTree node = (CommonTree) t;
if (node.token == null)
return t;
if ((node instanceof QueryNode) && node.getParent() != null && "T_CONDITION".equals(((CommonTree) node.getParent()).token.getText())) {
stack.peekLast().setPropagateVariablesUp(false);
return t;
}
if (node instanceof IdentificationVariableNode) {
IdentificationVariableNode vnode = (IdentificationVariableNode) node;
vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
return t;
}
if (node instanceof JoinVariableNode) {
JoinVariableNode vnode = (JoinVariableNode) node;
vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
return t;
}
return t;
}
use of com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode in project cuba by cuba-platform.
the class JPATreeNodes method createLeftJoinByPath.
public static JoinVariableNode createLeftJoinByPath(String joinVariable, PathNode pathNode) {
JoinVariableNode joinVariableNode = new JoinVariableNode(JPA2Lexer.T_JOIN_VAR, "left join", joinVariable);
joinVariableNode.addChild(pathNode);
return joinVariableNode;
}
use of com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode in project cuba by cuba-platform.
the class Parser method parseJoinClause.
public static List<JoinVariableNode> parseJoinClause(String join) throws RecognitionException {
JPA2Parser parser = createParser(join);
JPA2Parser.join_section_return aReturn = parser.join_section();
CommonTree tree = (CommonTree) aReturn.getTree();
if (tree == null) {
parser = createParser("join " + join);
aReturn = parser.join_section();
tree = (CommonTree) aReturn.getTree();
}
if (tree instanceof JoinVariableNode) {
checkTreeForExceptions(join, tree);
return Collections.singletonList((JoinVariableNode) tree);
} else {
List<JoinVariableNode> joins = tree.getChildren().stream().filter(node -> node instanceof JoinVariableNode).map(JoinVariableNode.class::cast).collect(Collectors.toList());
checkTreeForExceptions(join, tree);
return joins;
}
}
Aggregations