Search in sources :

Example 6 with CommonErrorNode

use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.

the class BaseJoinNode method identifyVariableEntity.

public void identifyVariableEntity(DomainModel model, Deque<QueryVariableContext> stack, List<ErrorRec> invalidNodes) {
    String variableName = getVariableName();
    if (variableName == null) {
        invalidNodes.add(new ErrorRec(this, "No variable name found"));
        return;
    }
    List children = getChildren();
    if (children == null || children.size() == 0) {
        invalidNodes.add(new ErrorRec(this, "No children found"));
        return;
    }
    CommonTree child0 = (CommonTree) children.get(0);
    if (child0 instanceof CommonErrorNode) {
        invalidNodes.add(new ErrorRec(this, "Child 0 is an error node"));
        return;
    }
    QueryVariableContext queryVC = stack.peekLast();
    if (child0 instanceof PathNode) {
        PathNode pathNode = (PathNode) child0;
        Pointer pointer = pathNode.resolvePointer(model, queryVC);
        if (pointer instanceof NoPointer) {
            invalidNodes.add(new ErrorRec(this, "Cannot resolve joined entity"));
        } else if (pointer instanceof SimpleAttributePointer) {
            invalidNodes.add(new ErrorRec(this, "Joined entity resolved to a non-entity attribute"));
        } else if (pointer instanceof EntityPointer) {
            queryVC.addEntityVariable(variableName, ((EntityPointer) pointer).getEntity());
        } else if (pointer instanceof CollectionPointer) {
            queryVC.addEntityVariable(variableName, ((CollectionPointer) pointer).getEntity());
        } else {
            invalidNodes.add(new ErrorRec(this, "Unexpected pointer variable type: " + pointer.getClass()));
        }
    } else {
        // this special case is for "join X on X.a = Y.b" query. Entity name would be just text in the child node
        try {
            queryVC.addEntityVariable(variableName, model.getEntityByName(child0.getText()));
        } catch (UnknownEntityNameException e) {
            invalidNodes.add(new ErrorRec(this, "Could not find entity for name " + child0.getText()));
        }
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode) UnknownEntityNameException(com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException) ErrorRec(com.haulmont.cuba.core.sys.jpql.ErrorRec) List(java.util.List) QueryVariableContext(com.haulmont.cuba.core.sys.jpql.QueryVariableContext)

Example 7 with CommonErrorNode

use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.

the class IdentificationVariableNode method identifyVariableEntity.

public void identifyVariableEntity(DomainModel model, Deque<QueryVariableContext> stack, List<ErrorRec> invalidIdVarNodes) {
    List children = getChildren();
    if (variableName == null) {
        invalidIdVarNodes.add(new ErrorRec(this, "No entity variable name"));
        return;
    }
    if (children == null) {
        invalidIdVarNodes.add(new ErrorRec(this, "Null children"));
        return;
    }
    if (children.size() != 1) {
        invalidIdVarNodes.add(new ErrorRec(this, "Number of children not equals 1"));
        return;
    }
    if (children.get(0) instanceof CommonErrorNode) {
        invalidIdVarNodes.add(new ErrorRec(this, "Child 0 is an error node"));
        return;
    }
    CommonTree child0 = (CommonTree) children.get(0);
    String variableName = getVariableName();
    if (child0 instanceof QueryNode) {
        QueryVariableContext queryVC;
        do {
            queryVC = stack.removeLast();
        } while (!queryVC.isPropagateVariablesUpstairs());
        deductFields(queryVC, child0, model);
        stack.peekLast().addEntityVariable(variableName, queryVC.getEntity());
    } else {
        if (variableName != null) {
            try {
                String entityName = child0.token.getText();
                JpqlEntityModel entity = model.getEntityByName(entityName);
                effectiveEntityName = entity.getName();
                stack.peekLast().addEntityVariable(variableName, entity);
            } catch (UnknownEntityNameException e) {
                stack.peekLast().addEntityVariable(variableName, NoJpqlEntityModel.getInstance());
            }
        }
    }
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) List(java.util.List) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode)

Example 8 with CommonErrorNode

use of org.antlr.runtime.tree.CommonErrorNode 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) && isInWhereSubquery(node)) {
        stack.peekLast().setPropagateVariablesUp(false);
        return t;
    }
    if (node instanceof IdentificationVariableNode) {
        IdentificationVariableNode vnode = (IdentificationVariableNode) node;
        vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
        return t;
    }
    if (node instanceof BaseJoinNode) {
        BaseJoinNode vnode = (BaseJoinNode) node;
        vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
        return t;
    }
    return t;
}
Also used : IdentificationVariableNode(com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode) BaseJoinNode(com.haulmont.cuba.core.sys.jpql.tree.BaseJoinNode) CommonTree(org.antlr.runtime.tree.CommonTree) QueryNode(com.haulmont.cuba.core.sys.jpql.tree.QueryNode) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode)

Aggregations

CommonErrorNode (org.antlr.runtime.tree.CommonErrorNode)8 CommonTree (org.antlr.runtime.tree.CommonTree)7 QueryNode (com.haulmont.cuba.core.sys.jpql.tree.QueryNode)3 List (java.util.List)3 QueryVariableContext (com.haulmont.cuba.core.sys.jpql.QueryVariableContext)2 IdentificationVariableNode (com.haulmont.cuba.core.sys.jpql.tree.IdentificationVariableNode)2 ErrorRec (com.haulmont.cuba.core.sys.jpql.ErrorRec)1 UnknownEntityNameException (com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException)1 BaseJoinNode (com.haulmont.cuba.core.sys.jpql.tree.BaseJoinNode)1 JoinVariableNode (com.haulmont.cuba.core.sys.jpql.tree.JoinVariableNode)1 TreeToQueryCapable (com.haulmont.cuba.core.sys.jpql.tree.TreeToQueryCapable)1 ArrayList (java.util.ArrayList)1 InvalidSelectException (org.alfresco.rest.framework.resource.parameters.InvalidSelectException)1 InvalidQueryException (org.alfresco.rest.framework.resource.parameters.where.InvalidQueryException)1 RecognitionException (org.antlr.runtime.RecognitionException)1 RewriteCardinalityException (org.antlr.runtime.tree.RewriteCardinalityException)1 Tree (org.antlr.runtime.tree.Tree)1 TreeVisitor (org.antlr.runtime.tree.TreeVisitor)1