Package org.rhq.enterprise.server.search.translation.jpql

Examples of org.rhq.enterprise.server.search.translation.jpql.SearchFragment


                        RHQLComparisonOperator.EQUALS, simpleTerm.getValue());
                } else {
                    advancedTerm = (RHQLAdvancedTerm) nextTerm;
                }

                SearchFragment searchFragment = translator.getSearchFragment(alias, advancedTerm);
                String jpqlFragment = searchFragment.getJPQLFragment();
                if (searchFragment.getType() == SearchFragment.Type.PRIMARY_KEY_SUBQUERY) {
                    jpqlFragment = " " + alias + ".id IN (" + jpqlFragment + ")";
                }

                builder.append(jpqlFragment);
            }
View Full Code Here


        String param = term.getParam();

        String filter = term.getValue();

        if (path.equals("availability")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForEnum(alias + ".currentAvailability.availabilityType", op, filter, AvailabilityType.class,
                    true));

        } else if (path.equals("category")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForEnum(alias + ".resourceType.category", op, filter, ResourceCategory.class, false));

        } else if (path.equals("type")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".resourceType.name", op, filter));

        } else if (path.equals("plugin")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".resourceType.plugin", op, filter));

        } else if (path.equals("name")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".name", op, filter));

        } else if (path.equals("version")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".version", op, filter));

        } else if (path.equals("alerts")) {
            return new SearchFragment( //
                SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
                    + "  FROM Resource res " //
                    + "  JOIN res.alertDefinitions alertDef " //
                    + "  JOIN alertDef.alerts alert " //
                    + " WHERE alert.ctime > "
                    + AlertSearchAssistParam.getLastTime(param) //
                    + (filter.equalsIgnoreCase("any") ? "" : "   and "
                        + getJPQLForEnum("alertDef.priority", op, filter, AlertPriority.class, false)) //
                    + " GROUP BY res.id " //
                    + "HAVING COUNT(alert) > 0 ");

        } else if (path.equals("trait")) {
            return new SearchFragment( //
                SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
                    + "  FROM Resource res, MeasurementDataTrait trait " //
                    + "  JOIN res.schedules schedule " //
                    + " WHERE trait.schedule = schedule " //
                    + "   AND schedule.definition.dataType = " + DataType.TRAIT.ordinal() //
                    + "   AND " + getJPQLForString("schedule.definition.name", RHQLComparisonOperator.EQUALS, param) //
                    + "   AND " + getJPQLForString("trait.value", op, filter));

        } else if (path.equals("connection")) {
            return new SearchFragment( //
                SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
                    + "  FROM Resource res, PropertySimple simple, PropertyDefinitionSimple simpleDefinition " //
                    + "  JOIN res.resourceType.pluginConfigurationDefinition.propertyDefinitions definition " //
                    + "  JOIN res.pluginConfiguration.properties property " //
                    + " WHERE simpleDefinition = definition " // only provide translations for simple properties
                    + "   AND simpleDefinition.type <> 'PASSWORD' " // do not allow searching by hidden/password fields
                    + "   AND property = simple " // join to simple for filter by 'stringValue' attribute
                    + "   AND " + getJPQLForString("definition.name", RHQLComparisonOperator.EQUALS, param) //
                    + "   AND " + getJPQLForString("simple.stringValue", op, filter));

        } else if (path.equals("configuration")) {
            return new SearchFragment( //
                SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
                    + "  FROM Resource res, PropertySimple simple, PropertyDefinitionSimple simpleDefinition " //
                    + "  JOIN res.resourceType.resourceConfigurationDefinition.propertyDefinitions definition " //
                    + "  JOIN res.resourceConfiguration.properties property " //
                    + " WHERE simpleDefinition = definition " // only provide translations for simple properties
View Full Code Here

        String filter = term.getValue();

        if (path.equals("availability")) {
            if (op == RHQLComparisonOperator.NOT_NULL || op == RHQLComparisonOperator.NULL) {
                return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, "true");
            }

            String comparator = null;
            if (op == RHQLComparisonOperator.EQUALS || op == RHQLComparisonOperator.EQUALS_STRICT) {
                comparator = " = ";
            } else {
                comparator = " != ";
            }

            String numericAvailType = null;
            if (filter.equalsIgnoreCase("up")) {
                numericAvailType = String.valueOf(AvailabilityType.UP.ordinal());
            } else if (filter.equalsIgnoreCase("down")) {
                numericAvailType = String.valueOf(AvailabilityType.DOWN.ordinal());
            } else if (filter.equalsIgnoreCase("disabled")) {
                numericAvailType = String.valueOf(AvailabilityType.DISABLED.ordinal());
            } else { // unknown
                numericAvailType = String.valueOf(AvailabilityType.UNKNOWN.ordinal());
            }

            return new SearchFragment( //
                SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT rg.id" //
                    + "  FROM ResourceGroup rg " //
                    + " WHERE " //
                    + "       ( SELECT COUNT(eavail.availabilityType) " //
                    + "           FROM rg.explicitResources eres " //
                    + "           JOIN eres.currentAvailability eavail " //
                    + "          WHERE eavail.availabilityType = '" + numericAvailType + "' ) " //
                    + comparator //
                    + "       ( SELECT COUNT(eres) FROM rg.explicitResources eres ) ");
        } else if (path.equals("category")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForEnum(alias + ".resourceType.category", op, filter, ResourceCategory.class, false));

        } else if (path.equals("groupCategory")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForEnum(alias + ".groupCategory", op, filter, GroupCategory.class, false));

        } else if (path.equals("type")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".resourceType.name", op, filter));

        } else if (path.equals("plugin")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".resourceType.plugin", op, filter));

        } else if (path.equals("name")) {
            return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
                getJPQLForString(alias + ".name", op, filter));

        } else {
            if (param == null) {
                throw new SearchExpressionException("No search fragment available for " + path);
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.search.translation.jpql.SearchFragment

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.