Search in sources :

Example 1 with QueryVariableContext

use of com.haulmont.cuba.core.sys.jpql.QueryVariableContext in project cuba by cuba-platform.

the class IdVarSelector method pre.

@Override
public Object pre(Object t) {
    if (!(t instanceof CommonTree))
        return t;
    if (t instanceof CommonErrorNode) {
        return t;
    }
    CommonTree node = (CommonTree) t;
    if (node instanceof QueryNode) {
        QueryVariableContext newCurrent = new QueryVariableContext(model, (QueryNode) node);
        if (root == null) {
            root = newCurrent;
        }
        QueryVariableContext last = stack.peekLast();
        if (last != null) {
            last.addChild(newCurrent);
        }
        stack.addLast(newCurrent);
    }
    return t;
}
Also used : CommonTree(org.antlr.runtime.tree.CommonTree) QueryNode(com.haulmont.cuba.core.sys.jpql.tree.QueryNode) QueryVariableContext(com.haulmont.cuba.core.sys.jpql.QueryVariableContext) CommonErrorNode(org.antlr.runtime.tree.CommonErrorNode)

Example 2 with QueryVariableContext

use of com.haulmont.cuba.core.sys.jpql.QueryVariableContext 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)

Aggregations

QueryVariableContext (com.haulmont.cuba.core.sys.jpql.QueryVariableContext)2 CommonErrorNode (org.antlr.runtime.tree.CommonErrorNode)2 CommonTree (org.antlr.runtime.tree.CommonTree)2 ErrorRec (com.haulmont.cuba.core.sys.jpql.ErrorRec)1 UnknownEntityNameException (com.haulmont.cuba.core.sys.jpql.UnknownEntityNameException)1 QueryNode (com.haulmont.cuba.core.sys.jpql.tree.QueryNode)1 List (java.util.List)1