Package org.jboss.as.cmp.ejbql

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


    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();
                if (cmrField.getRelationMetaData().isTableMappingStyle()) {
                    existsClause(path, buf, !node.not);
                    return buf;
                }
            }

            String alias = aliasManager.getAlias(path.getPath(path.size() - 2));
            JDBCFieldBridge field = (JDBCFieldBridge) path.getField();

            // if jdbc type is null then it should be a cmr field in
            // a one-to-one mapping that isn't a foreign key.
            // handle it the way the IS EMPTY on the one side of one-to-many
            // relationship is handled
View Full Code Here


        return buf;
    }

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

        existsClause(path, buf, !node.not);
        return buf;
    }
View Full Code Here

     */
    public Object visit(ASTMemberOf node, Object data) {
        StringBuffer buf = (StringBuffer) data;

        // setup compare to vars first, so we can compre types in from vars
        ASTPath toPath = (ASTPath) node.jjtGetChild(1);

        JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

        JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

        String pathStr = toPath.getPath(toPath.size() - 2);
        String toParentAlias = aliasManager.getAlias(pathStr);
        String toChildAlias = aliasManager.getAlias(toPath.getPath());
        String relationTableAlias = null;
        if (toCMRField.getRelationMetaData().isTableMappingStyle()) {
            relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
        }

        // setup from variables
        String fromAlias = null;
        int fromParamNumber = -1;
        if (node.jjtGetChild(0) instanceof ASTParameter) {
            ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

            // can only compare like kind entities
            verifyParameterEntityType(fromParam.number, toChildEntity);

            fromParamNumber = fromParam.number;
        } else {
            ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
            addJoinPath(fromPath);

            JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
            fromAlias = aliasManager.getAlias(fromPath.getPath());

            // can only compare like kind entities
            if (!fromEntity.equals(toChildEntity)) {
                throw new IllegalStateException("Only like types can be " +
                        "compared: from entity=" +
View Full Code Here

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

        // setup the from path
        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);
            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;
            addJoinPath(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

    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, new NodeStringWrapper(cntPath)};
        } else {
            JDBCEntityBridge entity = (JDBCEntityBridge) cntPath.getEntity();
            final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
            if (pkFields.length > 1) {
                countCompositePk = true;
                forceDistinct = node.distinct.length() > 0;
                selectEntity(cntPath, forceDistinct, 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

                    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

        return buf;
    }

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

        existsClause(path, buf, !node.not);
        return buf;
    }
View Full Code Here

     */
    public Object visit(ASTMemberOf node, Object data) {
        StringBuffer buf = (StringBuffer) data;

        // setup compare to vars first, so we can compare types in from vars
        ASTPath toPath = (ASTPath) node.jjtGetChild(1);

        JDBCCMRFieldBridge toCMRField = (JDBCCMRFieldBridge) toPath.getCMRField();

        JDBCEntityBridge toChildEntity = (JDBCEntityBridge) toPath.getEntity();

        String pathStr = toPath.getPath(toPath.size() - 2);
        String toParentAlias = aliasManager.getAlias(pathStr);
        String toChildAlias = aliasManager.getAlias(toPath.getPath());
        String relationTableAlias = null;
        if (toCMRField.getRelationMetaData().isTableMappingStyle()) {
            relationTableAlias = aliasManager.getRelationTableAlias(toPath.getPath());
        }

        // setup from variables
        String fromAlias = null;
        int fromParamNumber = -1;
        if (node.jjtGetChild(0) instanceof ASTParameter) {
            ASTParameter fromParam = (ASTParameter) node.jjtGetChild(0);

            // can only compare like kind entities
            verifyParameterEntityType(fromParam.number, toChildEntity);

            fromParamNumber = fromParam.number;
        } else {
            ASTPath fromPath = (ASTPath) node.jjtGetChild(0);
            addJoinPath(fromPath);

            JDBCEntityBridge fromEntity = (JDBCEntityBridge) fromPath.getEntity();
            fromAlias = aliasManager.getAlias(fromPath.getPath());

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

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

        // setup the from path
        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);
            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;
            addJoinPath(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, new NodeStringWrapper(cntPath)};
        } else {
            JDBCEntityBridge entity = (JDBCEntityBridge) cntPath.getEntity();
            final JDBCFieldBridge[] pkFields = entity.getPrimaryKeyFields();
            if (pkFields.length > 1) {
                countCompositePk = true;
                forceDistinct = node.distinct.length() > 0;
                selectEntity(cntPath, forceDistinct, 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

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.