Package org.jboss.as.cmp.ejbql

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


        return data;
    }

    public Object visit(ASTIsEmpty node, Object data) {
        ASTPath path = (ASTPath) node.jjtGetChild(0);
        if (!path.isCMRField()) {
            throw new IllegalStateException("IS EMPTY can be applied only to collection valued CMR field.");
        }

        addLeftJoinPath(path);

        StringBuffer sql = (StringBuffer) data;
        JDBCAbstractCMRFieldBridge cmrField = (JDBCAbstractCMRFieldBridge) path.getCMRField();
        JDBCAbstractEntityBridge relatedEntity = (JDBCAbstractEntityBridge) cmrField.getRelatedEntity();
        String alias = aliasManager.getAlias(path.getPath());
        SQLUtil.getIsNullClause(node.not, relatedEntity.getPrimaryKeyFields(), alias, sql);

        return data;
    }
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;

        if (node.not) {
            sql.append(SQLUtil.NOT);
        }

        sql.append(SQLUtil.EXISTS).append('(').append(SQLUtil.SELECT);

        if (member instanceof ASTParameter) {
            ASTParameter toParam = (ASTParameter) member;
            verifyParameterEntityType(toParam.number, colEntity);
            inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, colEntity));

            String parentAlias = aliasManager.getAlias(colPath.getPath(0));
            String localParentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
            JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
            SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), localParentAlias, sql);
            sql.append(SQLUtil.FROM)
                    .append(parentEntity.getQualifiedTableName()).append(' ').append(localParentAlias);
            innerJoinPath(colPath, sql);

            sql.append(SQLUtil.WHERE);

            JDBCAbstractEntityBridge col0 = (JDBCAbstractEntityBridge) colPath.getEntity(0);
            SQLUtil.getSelfCompareWhereClause(col0.getPrimaryKeyFields(), parentAlias, localParentAlias, sql);
            sql.append(SQLUtil.AND);

            String localColAlias = aliasManager.getAlias(colPath.getPath() + "_local");
            SQLUtil.getWhereClause(colEntity.getPrimaryKeyFields(), localColAlias, sql);
        } else {
            ASTPath memberPath = (ASTPath) member;
            JDBCAbstractEntityBridge memberEntity = (JDBCAbstractEntityBridge) memberPath.getEntity();

            if (!memberEntity.equals(colEntity)) {
                throw new IllegalStateException("Member must be if the same type as the collection, got: member="
                        +
                        memberEntity.getEntityName()
                        + ", collection=" + colEntity.getEntityName());
            }

            String memberAlias = aliasManager.getAlias(memberPath.getPath());

            if (memberPath.size() > 1) {
                String parentAlias = aliasManager.getAlias(memberPath.getPath(0) + "_local");
                JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) memberPath.getEntity(0);
                SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
                sql.append(SQLUtil.FROM)
                        .append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
                innerJoinPath(memberPath, sql);
                innerJoinPath(colPath, sql);
            } else if (colPath.size() > 1) {
                String parentAlias = aliasManager.getAlias(colPath.getPath(0) + "_local");
                JDBCAbstractEntityBridge parentEntity = (JDBCAbstractEntityBridge) colPath.getEntity(0);
                SQLUtil.getColumnNamesClause(parentEntity.getPrimaryKeyFields(), parentAlias, sql);
                sql.append(SQLUtil.FROM)
                        .append(parentEntity.getQualifiedTableName()).append(' ').append(parentAlias);
                innerJoinPath(colPath, sql);
            } else {
                throw new IllegalStateException(
                        "There should be collection valued path expression, not identification variable.");
            }

            sql.append(SQLUtil.WHERE);

            JDBCAbstractEntityBridge member0 = (JDBCAbstractEntityBridge) memberPath.getEntity(0);
            String colAliasLocal = aliasManager.getAlias(colPath.getPath() + "_local");
            if (memberPath.size() > 1) {
                String memberAliasLocal = aliasManager.getAlias(memberPath.getPath() + "_local");
                SQLUtil.getSelfCompareWhereClause(colEntity.getPrimaryKeyFields(),
                        memberAliasLocal,
                        colAliasLocal,
                        sql);

                sql.append(SQLUtil.AND);

                String member0Alias = aliasManager.getAlias(memberPath.getPath(0));
                String member0AliasLocal = aliasManager.getAlias(memberPath.getPath(0) + "_local");
                SQLUtil.getSelfCompareWhereClause(member0.getPrimaryKeyFields(),
                        member0Alias,
                        member0AliasLocal,
                        sql);
            } else {
View Full Code Here

            buf.append(SQLUtil.NOT).append('(');
            comparison = "=";
        }

        // setup the from path
        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);
            if (!(fromCMPField.getFieldType().equals(parameterType))) {
                throw new IllegalStateException("Only like types can be " +
                        "compared: from CMP field=" +
                        fromCMPField.getFieldType() +
                        " to parameter=" + parameterType);
            }

            inputParameters.addAll(QueryParameter.createParameters(toParam.number - 1, fromCMPField));
            SQLUtil.getWhereClause(fromCMPField.getJDBCType(), fromAlias, comparison, buf);
        } else {
            ASTPath toPath = (ASTPath) toNode;
            addInnerJoinPath(toPath);
            String toAlias = aliasManager.getAlias(toPath.getPath(toPath.size() - 2));
            JDBCCMPFieldBridge toCMPField = (JDBCCMPFieldBridge) toPath.getCMPField();

            // can only compare like kind entities
            if (!(fromCMPField.getFieldType().equals(toCMPField.getFieldType()))) {
                throw new IllegalStateException("Only like types can be " +
                        "compared: from CMP field=" +
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 new IllegalStateException("Only like types can be " +
                        "compared: from entity=" +
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

        }

        // add all the additional path tables
        if (!allJoinPaths.isEmpty()) {
            for (Iterator iter = allJoinPaths.iterator(); iter.hasNext(); ) {
                ASTPath path = (ASTPath) iter.next();
                for (int i = 0; i < path.size(); i++) {
                    declareTables(path, i, buf);
                }
            }
        }

        // add all parent paths for collection member join paths
        if (!allCollectionMemberJoinPaths.isEmpty()) {
            for (Iterator iter = allCollectionMemberJoinPaths.values().iterator(); iter.hasNext(); ) {
                ASTPath path = (ASTPath) iter.next();
                // don't declare the last one as the first path was left joined
                for (int i = 0; i < path.size() - 1; i++) {
                    declareTables(path, i, buf);
                }
            }
        }

        // get all the left joined paths
        if (!allLeftJoinPaths.isEmpty()) {
            Set allLeftJoins = new HashSet();
            for (Iterator iter = allLeftJoinPaths.values().iterator(); iter.hasNext(); ) {
                allLeftJoins.addAll((Set) iter.next());
            }

            // add all parent paths for left joins
            for (Iterator iter = allLeftJoins.iterator(); iter.hasNext(); ) {
                ASTPath path = (ASTPath) iter.next();
                // don't declare the last one as the first path was left joined
                for (int i = 0; i < path.size() - 1; i++) {
                    declareTables(path, i, buf);
                }
            }
        }
View Full Code Here

        if (subquerySupported || paths == null) {
            return;
        }

        for (Iterator iter = paths.iterator(); iter.hasNext(); ) {
            ASTPath path = (ASTPath) iter.next();

            JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
            String parentAlias = aliasManager.getAlias(parentPath);

            if (cmrField.getRelationMetaData().isForeignKeyMappingStyle()) {
                JDBCEntityBridge childEntity = (JDBCEntityBridge) cmrField.getRelatedEntity();
                String childAlias = aliasManager.getAlias(path.getPath());

                buf.append(SQLUtil.LEFT_JOIN)
                        .append(childEntity.getQualifiedTableName())
                        .append(' ')
                        .append(childAlias)
                        .append(SQLUtil.ON);
                SQLUtil.getJoinClause(cmrField, parentAlias, childAlias, buf);
            } else {
                String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
                buf.append(SQLUtil.LEFT_JOIN)
                        .append(cmrField.getQualifiedTableName())
                        .append(' ')
                        .append(relationTableAlias)
                        .append(SQLUtil.ON);
View Full Code Here

    private void createThetaJoin(StringBuffer buf) {
        Set joinedAliases = new HashSet();
        // add all the additional path tables
        if (!ctermJoinPaths.isEmpty()) {
            for (Iterator iter = ctermJoinPaths.iterator(); iter.hasNext(); ) {
                ASTPath path = (ASTPath) iter.next();
                for (int i = 0; i < path.size(); i++) {
                    createThetaJoin(path, i, joinedAliases, buf);
                }
            }
        }

        // add all the collection member path tables
        if (!ctermCollectionMemberJoinPaths.isEmpty()) {
            for (Iterator iter = ctermCollectionMemberJoinPaths.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                String childAlias = (String) entry.getKey();
                ASTPath path = (ASTPath) entry.getValue();

                // join the memeber path
                createThetaJoin(path, path.size() - 1, joinedAliases, childAlias, buf);

                // join the memeber path parents
                for (int i = 0; i < path.size() - 1; i++) {
                    createThetaJoin(path, i, joinedAliases, buf);
                }
            }
        }

        // get all the left joined paths
        if (!ctermLeftJoinPaths.isEmpty()) {
            Set allLeftJoins = new HashSet();
            for (Iterator iter = ctermLeftJoinPaths.values().iterator(); iter.hasNext(); ) {
                allLeftJoins.addAll((Set) iter.next());
            }

            // add all parent paths for left joins
            for (Iterator iter = allLeftJoins.iterator(); iter.hasNext(); ) {
                ASTPath path = (ASTPath) iter.next();
                // don't declare the last one as the first path was left joined
                for (int i = 0; i < path.size() - 1; i++) {
                    createThetaJoin(path, i, joinedAliases, buf);
                }
            }
        }
    }
View Full Code Here

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

        // first arg is a collection valued path
        ASTPath path = (ASTPath) node.jjtGetChild(0);

        // add this path to the list of declared paths
        declaredPaths.add(path.getPath());

        // get the entity at the end of this path
        JDBCEntityBridge entity = (JDBCEntityBridge) path.getEntity();

        // second arg is the identifier
        ASTIdentifier id = (ASTIdentifier) node.jjtGetChild(1);

        // get the alias
        String alias = aliasManager.getAlias(id.identifier);

        // add this path to the list of join paths so parent paths will be joined
        addCollectionMemberJoinPath(alias, path);

        // declare the alias mapping
        aliasManager.addAlias(path.getPath(), alias);

        buf.append(entity.getQualifiedTableName());
        buf.append(' ');
        buf.append(alias);
        leftJoins(path.getPath(), buf);

        if (onFindCMRJoin != null && alias.equals(selectAlias)) {
            buf.append(onFindCMRJoin);
            onFindCMRJoin = null;
        }

        // add the relation-table
        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) path.getCMRField();
        if (cmrField.getRelationMetaData().isTableMappingStyle()) {
            String relationTableAlias = aliasManager.getRelationTableAlias(path.getPath());
            buf.append(SQLUtil.COMMA)
                    .append(cmrField.getQualifiedTableName())
                    .append(' ')
                    .append(relationTableAlias);
        }
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());
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.