Package org.jboss.as.cmp.ejbql

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


    }

    public Object visit(ASTSelect select, Object data) {
        StringBuffer sql = (StringBuffer) data;

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

            if (path.isCMPField()) {
                // set the select object
                JDBCFieldBridge selectField = (JDBCFieldBridge) path.getCMPField();
                selectManager = selectField.getManager();
                selectObject = selectField;
                setTypeFactory(selectManager.getJDBCTypeFactory());

                // todo inner or left?
                //addLeftJoinPath(path);
                addInnerJoinPath(path);

                String alias = aliasManager.getAlias(path.getPath(path.size() - 2));
                SQLUtil.getColumnNamesClause(selectField, alias, sql);
            } else {
                JDBCAbstractEntityBridge selectEntity = (JDBCAbstractEntityBridge) path.getEntity();
                selectManager = selectEntity.getManager();
                selectObject = selectEntity;
                setTypeFactory(selectEntity.getManager().getJDBCTypeFactory());

                final String alias = aliasManager.getAlias(path.getPath());
                if (select.distinct) {
                    SQLUtil.getSearchableColumnNamesClause(selectEntity.getTableFields(), alias, sql);
                } else {
                    SQLUtil.getColumnNamesClause(selectEntity.getTableFields(), alias, sql);
                }

                /*
                if(readAhead.isOnFind())
                {
                   String eagerLoadGroupName = readAhead.getEagerLoadGroup();
                   boolean[] loadGroupMask = selectEntity.getLoadGroupMask(eagerLoadGroupName);
                   SQLUtil.appendColumnNamesClause(
                      selectEntity.getTableFields(),
                      loadGroupMask,
                      alias,
                      sql
                   );
                }
                */

                addLeftJoinPath(path);
            }
        } else {
            // the function should take a path expresion as a parameter
            path = getPathFromChildren(child0);

            if (path == null) {
                throw new IllegalStateException("The function in SELECT clause does not contain a path expression.");
            }

            if (path.isCMPField()) {
                JDBCFieldBridge selectField = (JDBCFieldBridge) path.getCMPField();
                selectManager = selectField.getManager();
                setTypeFactory(selectManager.getJDBCTypeFactory());
                if (selectField.getJDBCType().hasMapper())
                    this.functionJDBCType = selectField.getJDBCType();
            } else if (path.isCMRField()) {
                JDBCFieldBridge cmrField = (JDBCFieldBridge) path.getCMRField();
                selectManager = cmrField.getManager();
                setTypeFactory(selectManager.getJDBCTypeFactory());
                addLeftJoinPath(path);
            } else {
                final JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge) path.getEntity();
                selectManager = entity.getManager();
                setTypeFactory(selectManager.getJDBCTypeFactory());
                addLeftJoinPath(path);
            }

            selectObject = child0;
            child0.jjtAccept(this, data);
        }

        return data;
    }
View Full Code Here


    }

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

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

            JDBCFieldBridge field = (JDBCFieldBridge) path.getField();
View Full Code Here

        return data;
    }

    public Object visit(ASTMemberOf node, Object data) {
        Node member = node.jjtGetChild(0);
        ASTPath colPath = (ASTPath) node.jjtGetChild(1);
        JDBCAbstractEntityBridge colEntity = (JDBCAbstractEntityBridge) colPath.getEntity();

        StringBuffer sql = (StringBuffer) data;
View Full Code Here

        ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
        addInnerJoinPath(fromPath);
        String fromAlias = aliasManager.getAlias(fromPath.getPath(fromPath.size() - 2));
        CMPFieldBridge fromCMPField = (CMPFieldBridge) 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

        return (not ? buf.append(')') : buf).append(')');
    }

    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

     * @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

        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 expresion as a parameter
            path = getPathFromChildren(child0);

            if (path == null) {
                throw new IllegalStateException("The function in SELECT clause does not contain a path expression.");
            }

            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

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.