Package org.rhq.core.domain.util

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


        final int distroPageSize = 10;

        Map<Repo, Map<String, Distribution>> reposDistros = new HashMap<Repo, Map<String, Distribution>>();

        RepoManagerLocal repoMgr = LookupUtil.getRepoManagerLocal();
        PageControl repoPC = new PageControl(0, repoPageSize);
        int totalReposProcessed = 0;
        while (true) {
            PageList<Repo> repoPage = repoMgr.findRepos(LookupUtil.getSubjectManager().getOverlord(), repoPC);

            if (repoPage.size() <= 0) {
                break;
            }

            for (Repo repoPageItem : repoPage) {
                if (!repoPageItem.isCandidate()) {
                    Map<String, Distribution> distrosMap = reposDistros.get(repoPageItem);
                    if (distrosMap == null) {
                        distrosMap = new HashMap<String, Distribution>();
                        reposDistros.put(repoPageItem, distrosMap);
                    }

                    PageControl distroPC = new PageControl(0, distroPageSize);
                    int totalDistrosProcessed = 0;
                    while (true) {
                        PageList<Distribution> distroPage = repoMgr.findAssociatedDistributions(LookupUtil
                            .getSubjectManager().getOverlord(), repoPageItem.getId(), distroPC);
                        if (distroPage.size() <= 0) {
                            break;
                        }
                        for (Distribution distroPageItem : distroPage) {
                            distrosMap.put(distroPageItem.getLabel(), distroPageItem);
                        }
                        totalDistrosProcessed += distroPage.size();
                        if (totalDistrosProcessed >= distroPage.getTotalSize()) {
                            break; // the previous page that was processed was the last one
                        }

                        distroPC.setPageNumber(distroPC.getPageNumber() + 1); // advance to the next distro page
                    }
                }
            }

            totalReposProcessed += repoPage.size();
View Full Code Here


        assertEquals(actual, expected, "Failed to iterate over query results with a single page");
    }

    @Test
    public void executeQueryThatReturnsMultiplePagesOfResults() {
        PageControl pc = new PageControl(0, 2);

        List<FakeEntity> expected = asList(new FakeEntity(1), new FakeEntity(2), new FakeEntity(3), new FakeEntity(4));

        FakeCriteriaQueryExecutor queryExecutor = new FakeCriteriaQueryExecutor(4, pc);
        queryExecutor.addPage(expected.subList(0, 2));
        queryExecutor.addPage(expected.subList(2, 4));

        FakeEntityCriteria criteria = new FakeEntityCriteria();
        //spinder 2-20-13: DO NOT use criteria.setPageControl(pc) here as it causes ignore of pageNumber/pageSize
        criteria.setPaging(pc.getPageNumber(), pc.getPageSize());

        CriteriaQuery<FakeEntity, FakeEntityCriteria> query = new CriteriaQuery<FakeEntity, FakeEntityCriteria>(
            criteria, queryExecutor);

        List<FakeEntity> actual = new ArrayList<FakeEntity>();
View Full Code Here

     */
    @Test
    public void executeQueryThatReturnsTotalPagesOfResults() {
        //create page control to browse entries 100 at a time and start at page 0
        int pageSize = 100;
        PageControl pc = new PageControl(0, pageSize);

        //Total size of result set is 500.
        int totalSize = 500;

        //Create list and populate with all entries.
        List<FakeEntity> total = new ArrayList<FakeEntity>();
        for (int i = 0; i < totalSize; i++) {
            total.add(new FakeEntity(i));
        }

        //build executor to parse a given list with using PageControl passed in
        FakeCriteriaQueryExecutor queryExecutor = new FakeCriteriaQueryExecutor(totalSize, pc);

        //add pages of results to simulate PageList results as returned by db queries
        //todo: spinder, modify to support fractional results below and add last page.
        int bucketCount = totalSize / pageSize;//number of full pages to list
        int start = 0;
        int end = pageSize;
        //add bucketCount pages of data to read from.
        for (int i = 0; i < bucketCount; i++) {
            //Ex. first two pages (0, 100), (100,200), etc.
            queryExecutor.addPage(total.subList(start, end));
            start += pageSize;
            end += pageSize;
        }

        //build criteria and attach pageControl
        FakeEntityCriteria criteria = new FakeEntityCriteria();
        //spinder 2-20-13:DO NOT use criteria.setPageControl(pc) here as it causes ignore of pageNumber/pageSize
        criteria.setPaging(pc.getPageNumber(), pc.getPageSize());

        //?? So which pageControl has the right details? Criteria.pageControl? OR PageControl passed into the QueryExecutor.

        //Start off the initial query to page through the items in chunks defined by the pageControl instance
        CriteriaQuery<FakeEntity, FakeEntityCriteria> query = new CriteriaQuery<FakeEntity, FakeEntityCriteria>(
View Full Code Here

        }
    }

    @Test
    public void testIteratingOverQueryWithInconsistentResults_fewResultsOnLastPage() {
        PageControl pc = new PageControl(0, 100);
        int realResults = 490;
        FakeCriteriaQueryExecutor executor = prepareExecutor(realResults, 500, pc);

        FakeEntityCriteria criteria = new FakeEntityCriteria();

        criteria.setPaging(pc.getPageNumber(), pc.getPageSize());

        CriteriaQuery<FakeEntity, FakeEntityCriteria> query = new CriteriaQuery<FakeEntity, FakeEntityCriteria>(
            criteria, executor);

        //Now iterate over the list and make sure that iteration happens in order as expected
View Full Code Here

        assertEquals(num, realResults, "Unexpected number for results returned");
    }

    @Test
    public void testIteratingOVerQueryWithInconsistentResults_emptyLastPage() {
        PageControl pc = new PageControl(0, 100);
        int realResults = 400;
        FakeCriteriaQueryExecutor executor = prepareExecutor(realResults, 500, pc);

        FakeEntityCriteria criteria = new FakeEntityCriteria();

        criteria.setPaging(pc.getPageNumber(), pc.getPageSize());

        CriteriaQuery<FakeEntity, FakeEntityCriteria> query = new CriteriaQuery<FakeEntity, FakeEntityCriteria>(
            criteria, executor);

        //Now iterate over the list and make sure that iteration happens in order as expected
View Full Code Here

        assertEquals(num, realResults, "Unexpected number for results returned");
    }

    @Test
    public void testIteratingOverQueryWithInconsistentResults_tooManyResults() {
        PageControl pc = new PageControl(0, 100);
        int realResults = 551;
        FakeCriteriaQueryExecutor executor = prepareExecutor(realResults, 520, pc);

        FakeEntityCriteria criteria = new FakeEntityCriteria();

        criteria.setPaging(pc.getPageNumber(), pc.getPageSize());

        CriteriaQuery<FakeEntity, FakeEntityCriteria> query = new CriteriaQuery<FakeEntity, FakeEntityCriteria>(
            criteria, executor);

        //Now iterate over the list and make sure that iteration happens in order as expected
View Full Code Here

        }

        public void addPage(List<FakeEntity> entities) {
            int pageNumber = pages.size();
            pages
                .add(new PageList<FakeEntity>(entities, totalSize, new PageControl(pageNumber, this.pc.getPageSize())));
        }
View Full Code Here

        }

        @Override
        public PageList<FakeEntity> execute(FakeEntityCriteria criteria) {
            int page = criteria.getPageNumber();
            return pages.size() > page ? pages.get(page) : new PageList<FakeEntity>(new PageControl(page, pc.getPageSize()));
        }
View Full Code Here

    }

    public void dataFetchPerformsMaxAttemptsOnInconsistentResults() {
        numberOfInconsistentResults = QueryUtility.DEFAULT_PHANTOM_READ_MAX_ATTEMPTS;

        PageControl pc = PageControl.getUnlimitedInstance();

        PageList<Object> result = QueryUtility.fetchPagedDataAndCount(dataQuery, countQuery, pc, null);

        assertEquals(result, Collections.emptyList(), "The result should be empty");
        assertEquals(result.getTotalSize(), 1, "Unexpected total size");
View Full Code Here

    }

    public void dataFetchReturnsConsistentResultsWhenDetected() {
        numberOfInconsistentResults = 2;

        PageControl pc = PageControl.getUnlimitedInstance();

        PageList<Object> result = QueryUtility.fetchPagedDataAndCount(dataQuery, countQuery, pc, null);

        assertEquals(result.size(), 1, "The result should have 1 element");
        assertEquals(result.getTotalSize(), 1, "Unexpected total size");
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.