Package org.rhq.core.domain.util

Examples of org.rhq.core.domain.util.PageControl


        return LookupUtil.getConfigurationManager().findResourceConfigurationUpdates(subject, resourceId, null, null,
            true, lastFive);
    }

    private List<Tuple<EventSeverity, Integer>> getEventCounts(Subject subject, int resourceId) {
        PageControl unlimited = PageControl.getUnlimitedInstance();
        unlimited.initDefaultOrderingField("ev.timestamp", PageOrdering.DESC);

        long now = System.currentTimeMillis();
        long nowMinus24Hours = now - (24 * 60 * 60 * 1000);
        Map<EventSeverity, Integer> eventCounts = LookupUtil.getEventManager().getEventCountsBySeverity(subject,
            resourceId, nowMinus24Hours, now);
View Full Code Here


        }
        return results;
    }

    private List<InstalledPackageHistory> getPackageHistory(Subject subject, int resourceId, int count) {
        PageControl lastFive = new PageControl(0, count);
        lastFive.initDefaultOrderingField("iph.timestamp", PageOrdering.DESC);
        return LookupUtil.getContentUIManager().getInstalledPackageHistoryForResource(resourceId, lastFive);
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public PageList<T> execute() {
        PageList<T> results;
        PageControl pageControl = CriteriaQueryGenerator.getPageControl(criteria);

        Restriction criteriaRestriction = criteria.getRestriction();
        if (criteriaRestriction == null) {
            try {
                results = QueryUtility.fetchPagedDataAndCount(queryGenerator.getQuery(entityManager),
View Full Code Here

    @SuppressWarnings("unchecked")
    public PageList<PackageVersionComposite> getPackageVersionCompositesByFilter(Subject user, int resourceId,
        String filter, PageControl pc) {
        pc.initDefaultOrderingField("pv.generalPackage.name", PageOrdering.ASC);
        PageControl unlimitedpc = PageControl.getUnlimitedInstance();

        Query queryInstalled = PersistenceUtility.createQueryWithOrderBy(entityManager,
            InstalledPackage.QUERY_FIND_PACKAGE_LIST_ITEM_COMPOSITE, unlimitedpc);

        queryInstalled.setParameter("resourceId", resourceId);
View Full Code Here

    @SuppressWarnings("unchecked")
    public PageList<PackageVersionComposite> getUpdatePackageVersionCompositesByFilter(Subject user, int resourceId,
        String filter, PageControl pc) {
        pc.initDefaultOrderingField("pv.generalPackage.name", PageOrdering.ASC);
        PageControl unlimitedpc = PageControl.getUnlimitedInstance();

        Query queryInstalled = PersistenceUtility.createQueryWithOrderBy(entityManager,
            InstalledPackage.QUERY_FIND_PACKAGE_LIST_ITEM_COMPOSITE, unlimitedpc);

        queryInstalled.setParameter("resourceId", resourceId);
View Full Code Here

    }

    public String getQueryString(boolean countQuery) {
        StringBuilder results = new StringBuilder();

        PageControl pc = getPageControl(criteria);

        results.append("SELECT ");

        List<String> fetchFields = getFetchFields(criteria);
        boolean useJoinFetch = projection == null && pc.isUnlimited() && !fetchFields.isEmpty();

        if (countQuery) {
            if (countProjection != null) {
                //just use whatever we are told
                results.append(countProjection).append(NL);
            } else if (groupByClause == null) { // non-grouped method
                // use count(*) instead of count(alias) due to https://bugzilla.redhat.com/show_bug.cgi?id=699842
                results.append("COUNT(*)").append(NL);
            } else {
                // gets the count of the number of aggregate/grouped rows
                // NOTE: this only works when the groupBy is a single element, as opposed to a list of elements
                results.append("COUNT(DISTINCT ").append(groupByClause).append(")").append(NL);
            }
        } else {
            if (projection == null) {
                //we need to just return distinct results when using JOIN FETCH otherwise we might see duplicates
                //in the result set and create discrepancy between the data query and the count query (which doesn't
                //use the JOIN FETCH but only the WHERE clause).
                if (useJoinFetch) {
                    results.append("DISTINCT ");
                }
                results.append(alias).append(NL);
            } else {
                results.append(projection).append(NL);
            }
        }

        results.append("FROM ").append(className).append(' ').append(alias).append(NL);

        if (!countQuery) {
            /*
             * don't fetch in the count query to avoid: "query specified join fetching,
             * but the owner of the fetched association was not present in the select list"
             */
            for (String fetchField : fetchFields) {
                if (isPersistentBag(fetchField)) {
                    addPersistentBag(fetchField);
                } else {
                    if (this.projection == null) {
                        /*
                         * if not altering the projection, join fetching can be used
                         * to retrieve the associated instance in the same SELECT
                         *
                         * We further avoid a JOIN FETCH when executing queries with limits.
                         * Such execution has performance problems that we solve by initializing the fields
                         * "manually" in the CriteriaQueryRunner and by defining a default batch fetch size in the
                         * persistence.xml.
                         */
                        if (useJoinFetch) {
                            results.append("LEFT JOIN FETCH ").append(alias).append('.').append(fetchField).append(NL);
                        } else {
                            addJoinFetch(fetchField);
                        }
                    } else {
                        /*
                         * if the projection is altered (perhaps converting it into a constructor query), then all
                         * fields specified in the fetch must be in the explicit return list.  this is not possible
                         * today with constructor queries, so any altered projection will implicitly disable fetching.
                         * instead, we'll record which fields need to be explicitly fetched after the primary query
                         * returns the bulk of the data, and use a similar methodology at the SLSB layer to eagerly
                         * load those before returning the PageList back to the caller.
                         */
                        addJoinFetch(fetchField);
                    }
                }
            }
        }

        // figure out the 'LEFT JOIN's needed for 'ORDER BY' tokens
        List<String> orderingFieldRequiredJoins = new ArrayList<String>();
        List<String> orderingFieldTokens = new ArrayList<String>();

        for (OrderingField orderingField : pc.getOrderingFields()) {
            PageOrdering ordering = orderingField.getOrdering();
            String fieldName = orderingField.getField();
            String override = criteria.getJPQLSortOverride(fieldName);
            String suffix = (override == null) ? fieldName : override;

View Full Code Here

        CriteriaQueryGenerator generator = new CriteriaQueryGenerator(new Subject(), groupCriteria);
        System.out.println(generator.getQueryString(false));
        System.out.println(generator.getQueryString(true));

        PageControl customPC = new PageControl();
        customPC.addDefaultOrderingField("0", PageOrdering.DESC);
        customPC.addDefaultOrderingField("name", PageOrdering.DESC);
        customPC.addDefaultOrderingField("resourceType.name", PageOrdering.ASC);
        groupCriteria.setPageControl(customPC);

        System.out.println(generator.getQueryString(false));
        System.out.println(generator.getQueryString(true));
    }
View Full Code Here

        System.out.println(generator.getQueryString(false));
        System.out.println(generator.getQueryString(true));
    }

    public static PageControl getPageControl(Criteria criteria) {
        PageControl pc;

        if (criteria.getPageControlOverrides() != null) {
            pc = criteria.getPageControlOverrides();
        } else {
            if (criteria.getPageNumber() == null || criteria.getPageSize() == null) {
                pc = PageControl.getUnlimitedInstance();
            } else {
                pc = new PageControl(criteria.getPageNumber(), criteria.getPageSize());
            }

            for (String fieldName : criteria.getOrderingFieldNames()) {
                for (Field sortField : CriteriaUtil.getFields(criteria, Criteria.Type.SORT)) {
                    if (!sortField.getName().equals(fieldName)) {
                        continue;
                    }
                    Object sortFieldValue;
                    try {
                        sortField.setAccessible(true);
                        sortFieldValue = sortField.get(criteria);
                    } catch (IllegalAccessException iae) {
                        throw new RuntimeException(iae);
                    }
                    if (sortFieldValue != null) {
                        PageOrdering pageOrdering = (PageOrdering) sortFieldValue;
                        pc.addDefaultOrderingField(getCleansedFieldName(sortField, 4), pageOrdering);
                    }
                }
            }
        }

        // Unless paging is unlimited or it's not supported, add a sort on ID.  This ensures that when paging
        // we always have a consistent ordering. In other words, if the data set is unchanged between pages, there
        // will no overlap/repetition of rows. Note that this applies even if other sort fields have been
        // set, because they may still not have unique values. See https://bugzilla.redhat.com/show_bug.cgi?id=966665.
        if (!pc.isUnlimited() && criteria.isSupportsAddSortId()) {
            pc.addDefaultOrderingField("id");
        }

        return pc;
    }
View Full Code Here

    public SelectItem[] getProviderOptions() {
        if (providers == null) {
            providers = new ArrayList<OptionItem<Integer>>();
            Subject subject = EnterpriseFacesContextUtility.getSubject();
            ContentSourceManagerLocal manager = LookupUtil.getContentSourceManager();
            PageControl pc = new PageControl();
            PageList<ContentSource> results = manager.getAllContentSources(subject, pc);
            for (ContentSource p : results) {
                OptionItem<Integer> item = new OptionItem<Integer>(p.getId(), p.getName());
                providers.add(item);
            }
View Full Code Here

        if (!authzManager.canViewResource(subject, resourceId)) {
            throw new PermissionException("User [" + subject + "] can't view resource with id " + resourceId);
        }
       
        List<SubscribedRepo> list = new ArrayList<SubscribedRepo>();
        PageControl pc = new PageControl();
        for (RepoComposite repoComposite : findResourceSubscriptions(subject, resourceId, pc)) {
            Repo repo = repoComposite.getRepo();
            SubscribedRepo summary = new SubscribedRepo(repo.getId(), repo.getName());
            list.add(summary);
        }
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.util.PageControl

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.