Package org.jboss.as.cmp.ejbql

Examples of org.jboss.as.cmp.ejbql.Node


        buf.append(')');
    }

    public Object visit(ASTEJBQL node, Object data) {
        Node selectNode = node.jjtGetChild(0);
        Node fromNode = node.jjtGetChild(1);
        Node whereNode = null;
        Node orderByNode = null;
        Node limitNode = null;

        for (int childNode = 2; childNode < node.jjtGetNumChildren(); childNode++) {
            Node temp = node.jjtGetChild(childNode);
            if (temp instanceof ASTWhere) {
                whereNode = temp;
            } else if (temp instanceof ASTOrderBy) {
                orderByNode = temp;
            } else if (temp instanceof ASTLimitOffset) {
                limitNode = temp;
            }
        }

        // translate select and add it to the buffer
        StringBuffer select = new StringBuffer();
        selectNode.jjtAccept(this, select);

        // conditional term paths from the where clause are treated separately from those
        // in select, from and order by.
        // TODO come up with a nicer treatment implementation.
        Set selectJoinPaths = new HashSet(ctermJoinPaths);
        Map selectCollectionMemberJoinPaths = new HashMap(ctermCollectionMemberJoinPaths);
        Map selectLeftJoinPaths = new HashMap(ctermLeftJoinPaths);

        // translate where and save results to append later
        StringBuffer where = new StringBuffer();
        if (whereNode != null) {
            whereNode.jjtAccept(this, where);
        }

        // reassign conditional term paths and add paths from order by and from to select paths
        ctermJoinPaths = selectJoinPaths;
        ctermCollectionMemberJoinPaths = selectCollectionMemberJoinPaths;
        ctermLeftJoinPaths = selectLeftJoinPaths;

        // translate order by and save results to append later
        StringBuffer orderBy = new StringBuffer();
        if (orderByNode != null) {
            orderByNode.jjtAccept(this, orderBy);

            // hack alert - this should use the visitor approach
            for (int i = 0; i < orderByNode.jjtGetNumChildren(); i++) {
                Node orderByPath = orderByNode.jjtGetChild(i);
                ASTPath path = (ASTPath) orderByPath.jjtGetChild(0);
                if (!isSelected(path)) {
                    select.append(SQLUtil.COMMA);
                    path.jjtAccept(this, select);
                }
            }
View Full Code Here


    }

    public Object visit(ASTSelect node, Object data) {
        StringBuffer buf = (StringBuffer) data;

        Node child0 = node.jjtGetChild(0);
        ASTPath path;
        if (child0 instanceof ASTPath) {
            path = (ASTPath) child0;

            if (path.isCMPField()) {
                // set the select object
                JDBCCMPFieldBridge selectField = (JDBCCMPFieldBridge) path.getCMPField();
                selectManager = (JDBCStoreManager) selectField.getManager();
                selectObject = selectField;
                setTypeFactory(selectManager.getJDBCTypeFactory());
                addJoinPath(path);
                selectAlias = aliasManager.getAlias(path.getPath(path.size() - 2));
                SQLUtil.getColumnNamesClause(selectField, selectAlias, buf);
            } else {
                // set the select object
                JDBCEntityBridge selectEntity = (JDBCEntityBridge) path.getEntity();
                selectManager = (JDBCStoreManager) selectEntity.getManager();
                selectObject = selectEntity;
                setTypeFactory(selectManager.getJDBCTypeFactory());
                selectEntity(path, node.distinct, buf);
            }
        } else {
            // the function should take a path expression as a parameter
            path = getPathFromChildren(child0);

            if (path == null) {
                throw MESSAGES.functionInSelectNoPath();
            }

            if (path.isCMPField()) {
                JDBCCMPFieldBridge selectField = (JDBCCMPFieldBridge) path.getCMPField();
                selectManager = (JDBCStoreManager) selectField.getManager();
                if (selectField.getJDBCType().hasMapper())
                    this.functionJDBCType = selectField.getJDBCType();
            } else if (path.isCMRField()) {
                JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
                selectManager = (JDBCStoreManager) cmrField.getEntity().getManager();
                addJoinPath(path);
            } else {
                final JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity();
                selectManager = (JDBCStoreManager) entity.getManager();
                addJoinPath(path);
            }

            setTypeFactory(selectManager.getJDBCTypeFactory());
            selectObject = child0;
            child0.jjtAccept(this, buf);
        }

        return buf;
    }
View Full Code Here

    }

    public Object visit(ASTNullComparison node, Object data) {
        StringBuffer buf = (StringBuffer) data;

        final Node child0 = node.jjtGetChild(0);
        if (child0 instanceof ASTPath) {
            ASTPath path = (ASTPath) child0;

            if (path.isCMRField()) {
                JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
View Full Code Here

        ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
        addJoinPath(fromPath);
        String fromAlias = aliasManager.getAlias(fromPath.getPath(fromPath.size() - 2));
        JDBCCMPFieldBridge fromCMPField = (JDBCCMPFieldBridge) fromPath.getCMPField();

        Node toNode = node.jjtGetChild(1);
        if (toNode instanceof ASTParameter) {
            ASTParameter toParam = (ASTParameter) toNode;

            // can only compare like kind entities
            Class parameterType = getParameterType(toParam.number);
View Full Code Here

    /**
     * compareEntity(arg0, arg1)
     */
    public Object visit(ASTEntityComparison node, Object data) {
        StringBuffer buf = (StringBuffer) data;
        Node arg0 = node.jjtGetChild(0);
        Node arg1 = node.jjtGetChild(1);
        if (node.opp.equals(SQLUtil.NOT_EQUAL)) {
            compareEntity(true, arg0, arg1, buf);
        } else {
            compareEntity(false, arg0, arg1, buf);
        }
View Full Code Here

    }

    public Object visit(ASTLimitOffset node, Object data) {
        int child = 0;
        if (node.hasOffset) {
            Node offsetNode = node.jjtGetChild(child++);
            if (offsetNode instanceof ASTParameter) {
                ASTParameter param = (ASTParameter) offsetNode;
                Class parameterType = getParameterType(param.number);
                if (int.class != parameterType && Integer.class != parameterType) {
                    throw MESSAGES.offsetParameterMustBeInt();
                }
                offsetParam = param.number;
            } else {
                ASTExactNumericLiteral param = (ASTExactNumericLiteral) offsetNode;
                offsetValue = (int) param.value;
            }
        }
        if (node.hasLimit) {
            Node limitNode = node.jjtGetChild(child);
            if (limitNode instanceof ASTParameter) {
                ASTParameter param = (ASTParameter) limitNode;
                Class parameterType = getParameterType(param.number);
                if (int.class != parameterType && Integer.class != parameterType) {
                    throw MESSAGES.limitParameterMustBeInt();
View Full Code Here

     * @param selectFunction a node implements SelectFunction
     * @return ASTPath child or null if there was no child of type ASTPath
     */
    private ASTPath getPathFromChildren(Node selectFunction) {
        for (int childInd = 0; childInd < selectFunction.jjtGetNumChildren(); ++childInd) {
            Node child = selectFunction.jjtGetChild(childInd);
            if (child instanceof ASTPath) {
                return (ASTPath) child;
            } else if (child instanceof SelectFunction) {
                Node path = getPathFromChildren(child);
                if (path != null) {
                    return (ASTPath) path;
                }
            }
        }
View Full Code Here

                    selected = true;
                    break;
                }
            }
        } else if (selectObject instanceof SelectFunction) {
            Node funcNode = (Node) selectObject;
            ASTPath fieldPath = getPathFromChildren(funcNode);
            if (fieldPath.getCMPField() == cmpField) {
                selected = true;
            }
        }
View Full Code Here

        throw new RuntimeException("Internal error: Found unknown node type in " +
                "EJB-QL abstract syntax tree: node=" + node);
    }

    public Object visit(ASTEJBQL node, Object data) {
        Node selectNode = node.jjtGetChild(0);
        Node fromNode = node.jjtGetChild(1);

        // compile selectNode
        StringBuffer selectClause = new StringBuffer(50);
        selectNode.jjtAccept(this, selectClause);

        StringBuffer whereClause = null;
        StringBuffer orderByClause = null;
        for (int i = 2; i < node.jjtGetNumChildren(); ++i) {
            Node childNode = node.jjtGetChild(i);
            if (childNode instanceof ASTWhere) {
                whereClause = new StringBuffer(20);
                childNode.jjtAccept(this, whereClause);
            } else if (childNode instanceof ASTOrderBy) {
                orderByClause = new StringBuffer();
                childNode.jjtAccept(this, orderByClause);
            } else if (childNode instanceof ASTLimitOffset) {
                childNode.jjtAccept(this, null);
            }
        }

        // compile fromNode
        StringBuffer fromClause = new StringBuffer(30);
View Full Code Here

    }

    public Object visit(ASTLimitOffset node, Object data) {
        int child = 0;
        if (node.hasOffset) {
            Node offsetNode = node.jjtGetChild(child++);
            if (offsetNode instanceof ASTParameter) {
                ASTParameter param = (ASTParameter) offsetNode;
                Class parameterType = getParameterType(param.number);
                if (int.class != parameterType && Integer.class != parameterType) {
                    throw new IllegalStateException("OFFSET parameter must be an int");
                }
                offsetParam = param.number;
            } else {
                ASTExactNumericLiteral param = (ASTExactNumericLiteral) offsetNode;
                offsetValue = (int) param.value;
            }
        }

        if (node.hasLimit) {
            Node limitNode = node.jjtGetChild(child);
            if (limitNode instanceof ASTParameter) {
                ASTParameter param = (ASTParameter) limitNode;
                Class parameterType = getParameterType(param.number);
                if (int.class != parameterType && Integer.class != parameterType) {
                    throw new IllegalStateException("LIMIT parameter must be an int");
View Full Code Here

TOP

Related Classes of org.jboss.as.cmp.ejbql.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.