Search in sources :

Example 1 with JoinVariableNode

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);
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode) RecognitionException(org.antlr.runtime.RecognitionException) JPA2RecognitionException(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2RecognitionException)

Example 2 with JoinVariableNode

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);
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode) RecognitionException(org.antlr.runtime.RecognitionException) JPA2RecognitionException(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2RecognitionException)

Example 3 with JoinVariableNode

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;
}
Also used : IdentificationVariableNode(com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode) CommonTree(org.antlr.runtime.tree.CommonTree) QueryNode(com.haulmont.cuba.core.sys.jpql.tree.QueryNode) JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode)

Example 4 with JoinVariableNode

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;
}
Also used : JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)

Example 5 with 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;
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) JPA2Parser(com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser) JoinVariableNode(com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)

Aggregations

JoinVariableNode (com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)5 CommonTree (org.antlr.runtime.tree.CommonTree)4 JPA2RecognitionException (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2RecognitionException)2 RecognitionException (org.antlr.runtime.RecognitionException)2 JPA2Parser (com.haulmont.cuba.core.sys.jpql.antlr2.JPA2Parser)1 IdentificationVariableNode (com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode)1 QueryNode (com.haulmont.cuba.core.sys.jpql.tree.QueryNode)1 CommonErrorNode (org.antlr.runtime.tree.CommonErrorNode)1