Package org.jboss.as.cmp.ejbql

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


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

        return selected;
View Full Code Here


            buf.append(SQLUtil.NOT).append('(');
        }

        String fromAlias;
        JDBCEntityBridge fromEntity;
        ASTPath fromPath = (ASTPath) fromNode;
        addJoinPath(fromPath);
        fromAlias = aliasManager.getAlias(fromPath.getPath());
        fromEntity = (JDBCEntityBridge) fromPath.getEntity();

        if (toNode instanceof ASTParameter) {
            ASTParameter toParam = (ASTParameter) toNode;

            // can only compare like kind entities
            verifyParameterEntityType(toParam.number, fromEntity);

            inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromEntity));

            SQLUtil.getWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, buf);
        } else {
            String toAlias;
            JDBCEntityBridge toEntity;
            ASTPath toPath = (ASTPath) toNode;
            addJoinPath(toPath);
            toAlias = aliasManager.getAlias(toPath.getPath());
            toEntity = (JDBCEntityBridge) toPath.getEntity();

            // can only compare like kind entities
            if (!fromEntity.equals(toEntity)) {
                throw CmpMessages.MESSAGES.onlyLikeTypesCanBeCompared(fromEntity.getEntityName(), toEntity.getEntityName());
            }
View Full Code Here

            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);
                }
            }
        }

        if (limitNode != null) {
View Full Code Here

    public Object visit(ASTCount node, Object data) {
        StringBuffer buf = (StringBuffer) data;
        node.setResultType(returnType);

        Object[] args;
        final ASTPath cntPath = (ASTPath) node.jjtGetChild(0);
        if (cntPath.isCMPField()) {
            args = new Object[]{node.distinct, node.jjtGetChild(0).jjtAccept(this, new StringBuffer()).toString()};
        } else {
            JDBCAbstractEntityBridge entity = (JDBCAbstractEntityBridge) cntPath.getEntity();
            final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
            if (pkFields.length > 1) {
                countCompositePk = true;
                forceDistinct = node.distinct.length() > 0;

                addLeftJoinPath(cntPath);

                String alias = aliasManager.getAlias(cntPath.getPath());
                SQLUtil.getColumnNamesClause(entity.getPrimaryKeyFields(),
                        alias,
                        buf);

                return buf;
            } else {
                final String alias = aliasManager.getAlias(cntPath.getPath());
                StringBuffer keyColumn = new StringBuffer(20);
                SQLUtil.getColumnNamesClause(pkFields[0], alias, keyColumn);
                args = new Object[]{node.distinct, keyColumn.toString()};
            }
        }
View Full Code Here

        return data;
    }

    public Object visit(ASTCollectionMemberDeclaration node, Object data) {
        ASTPath path = (ASTPath) node.jjtGetChild(0);

        // assign the same alias for path and identifier
        ASTIdentifier id = (ASTIdentifier) node.jjtGetChild(1);
        String alias = aliasManager.getAlias(id.identifier);
        aliasManager.addAlias(path.getPath(), alias);

        addInnerJoinPath(path);

        return data;
    }
View Full Code Here

        buf.append('(');
        if (not) {
            buf.append(SQLUtil.NOT).append('(');
        }

        ASTPath fromPath = (ASTPath) fromNode;
        addLeftJoinPath(fromPath);
        String fromAlias = aliasManager.getAlias(fromPath.getPath());
        JDBCAbstractEntityBridge fromEntity = (JDBCAbstractEntityBridge) fromPath.getEntity();

        if (toNode instanceof ASTParameter) {
            ASTParameter toParam = (ASTParameter) toNode;

            // can only compare like kind entities
            verifyParameterEntityType(toParam.number, fromEntity);

            inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromEntity));

            SQLUtil.getWhereClause(fromEntity.getPrimaryKeyFields(), fromAlias, buf);
        } else {
            ASTPath toPath = (ASTPath) toNode;
            addLeftJoinPath(toPath);
            String toAlias = aliasManager.getAlias(toPath.getPath());
            JDBCAbstractEntityBridge toEntity = (JDBCAbstractEntityBridge) toPath.getEntity();

            // can only compare like kind entities
            if (!fromEntity.equals(toEntity)) {
                throw new IllegalStateException("Only like types can be "
                        +
View Full Code Here

            return;
        }

        for (Iterator iter = paths.values().iterator(); iter.hasNext(); ) {
            String leftAlias = alias;
            ASTPath path = (ASTPath) iter.next();
            for (int i = 1; i < path.size(); ++i) {
                if (path.isCMRField(i)) {
                    final String curPath = path.getPath(i);
                    final String joinAlias = aliasManager.getAlias(curPath);

                    if (joinedAliases.add(joinAlias)) {
                        final JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField(i);
                        final JDBCAbstractEntityBridge joinEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();

                        JDBCRelationMetaData relation = cmrField.getMetaData().getRelationMetaData();

                        String join = (path.innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ");
View Full Code Here

            if (paths == null) {
                paths = new HashMap();
                joinPaths.put(alias, paths);
            }

            ASTPath oldPath = (ASTPath) paths.put(path, path);
            if (oldPath != null && oldPath.innerJoin) {
                path.innerJoin = true;
            }
        }
    }
View Full Code Here

    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);
            }

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();

            if (field instanceof JDBCAbstractCMRFieldBridge) {
                JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) field;
                final String alias;
                final JDBCFieldBridge[] keyFields;

                if (cmrField.hasForeignKey()) {
                    alias = aliasManager.getAlias(path.getPath(path.size() - 2));
                    keyFields = cmrField.getForeignKeyFields();
                } else {
                    alias = aliasManager.getAlias(path.getPath());
                    if (cmrField.getMetaData().getRelationMetaData().isTableMappingStyle()) {
                        keyFields = cmrField.getRelatedCMRField().getEntity().getPrimaryKeyFields();
                    } else {
                        keyFields = cmrField.getRelatedCMRField().getForeignKeyFields();
                    }
                }

                SQLUtil.getIsNullClause(node.not, keyFields, alias, sql);
            } else {
                String alias = aliasManager.getAlias(path.getPath(path.size() - 2));
                SQLUtil.getIsNullClause(node.not, field, alias, sql);
            }
        } else if (child0 instanceof ASTParameter) {
            ASTParameter param = (ASTParameter) child0;
            Class type = getParameterType(param.number);
View Full Code Here

TOP

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

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.