Package org.jboss.as.cmp.ejbql

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


    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


        return data;
    }

    public Object visit(ASTIsEmpty node, Object data) {
        ASTPath path = (ASTPath) node.jjtGetChild(0);
        if (!path.isCMRField()) {
            throw CmpMessages.MESSAGES.isEmptyCanOnlyBeAppliedToCmr();
        }

        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 CmpMessages.MESSAGES.memberMustBeOfCollectionType(memberEntity.getEntityName(), 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 CmpMessages.MESSAGES.shouldBeCollectionValuedPathExpression();
            }

            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 CmpMessages.MESSAGES.onlyLikeTypesCanBeCompared(fromCMPField.getFieldType().getName(), parameterType.getName());
            }

            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 CmpMessages.MESSAGES.onlyLikeTypesCanBeCompared(fromCMPField.getFieldType().getName(), toCMPField.getFieldType().getName());
            }
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 CmpMessages.MESSAGES.onlyLikeTypesCanBeCompared(fromEntity.getEntityName(), toEntity.getEntityName());
            }
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

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.