Package org.gatein.api.common

Examples of org.gatein.api.common.Pagination


    @Override
    public List<Site> findSites(SiteQuery query) {
        Parameters.requireNonNull(query, "query");

        Pagination pagination = query.getPagination();
        if (pagination != null && query.getSiteTypes().size() > 1) {
            pagination = null; // set it to null so the internal DataStorage doesn't use it, and we manually page later
            log.warn("Pagination is not supported internally for SiteQuery's with multiple site types. Therefore this query has the possibility to perform poorly.");
        }
        boolean includeAll = query.isIncludeEmptySites();

        List<Site> sites = new ArrayList<Site>();
        for (SiteType type : query.getSiteTypes()) {
            List<Site> sitesFound;
            switch (type) {
                case SITE:
                    sitesFound = findSites(pagination, SITES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case SPACE:
                    sitesFound = findSites(pagination, SPACES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case DASHBOARD:
                    sitesFound = findSites(pagination, DASHBOARDS, Comparators.site(query.getSorting()), includeAll);
                    break;
                default:
                    throw new AssertionError();
            }

            sites.addAll(sitesFound);

            // No reason to fetch anymore
            if (pagination != null && sites.size() >= pagination.getLimit()) {
                break;
            }
        }

        filter(sites, query.getFilter());
View Full Code Here


        return p;
    }

    @Override
    public List<Page> findPages(PageQuery query) {
        Pagination pagination = query.getPagination();
        Iterator<PageContext> iterator;
        if (pagination == null) {
            if (query.getSiteType() == null || query.getSiteName() == null)
                throw new IllegalArgumentException("Pagination is required when site type or site name is null.");

            SiteKey siteKey = Util.from(new SiteId(query.getSiteType(), query.getSiteName()));
            if (pageService instanceof PageServiceImpl) {
                iterator = ((PageServiceImpl) pageService).loadPages(siteKey).iterator();
            } else if (pageService instanceof PageServiceWrapper) {
                iterator = ((PageServiceWrapper) pageService).loadPages(siteKey).iterator();
            } else {
                throw new RuntimeException("Unable to retrieve all pages for " + siteKey);
            }
        } else {
            QueryResult<PageContext> result = pageService.findPages(pagination.getOffset(), pagination.getLimit(),
                Util.from(query.getSiteType()), query.getSiteName(), null, query.getDisplayName());

            iterator = result.iterator();
        }
View Full Code Here

         * @param offset the offset of the pagination
         * @param limit the limit of the pagination
         * @return this builder
         */
        public Builder withPagination(int offset, int limit) {
            return withPagination(new Pagination(offset, limit));
        }
View Full Code Here

         * @param offset the offset of the pagination
         * @param limit the limit of the pagination
         * @return this builder
         */
        public Builder withPagination(int offset, int limit) {
            return withPagination(new Pagination(offset, limit));
        }
View Full Code Here

    @Override
    public List<Site> findSites(SiteQuery query) {
        Parameters.requireNonNull(query, "query");

        Pagination pagination = query.getPagination();
        if (pagination != null && query.getSiteTypes().size() > 1) {
            pagination = null; // set it to null so the internal DataStorage doesn't use it, and we manually page later
            log.warn("Pagination is not supported internally for SiteQuery's with multiple site types. Therefore this query has the possibility to perform poorly.");
        }
View Full Code Here

                int offset = pagination.getOffset();
                int limit = pagination.getLimit();
                if (offset >= size) {
                    return Collections.emptyList();
                } else if (offset + limit > size) {
                    pagination = new Pagination(offset, size-offset);
                }

                T[] loaded = access.load(0, pagination.getOffset() + pagination.getLimit());
                return Arrays.asList(loaded).subList(pagination.getOffset(), pagination.getOffset() + pagination.getLimit());
            } else {
View Full Code Here

        return p;
    }

    @Override
    public List<Page> findPages(PageQuery query) {
        Pagination pagination = query.getPagination();
        Iterator<PageContext> iterator;
        if (pagination == null) {
            if (query.getSiteType() == null || query.getSiteName() == null)
                throw new IllegalArgumentException("Pagination is required when site type or site name is null.");

            SiteKey siteKey = Util.from(new SiteId(query.getSiteType(), query.getSiteName()));
            if (pageService instanceof PageServiceImpl) {
                iterator = ((PageServiceImpl) pageService).loadPages(siteKey).iterator();
            } else if (pageService instanceof PageServiceWrapper) {
                iterator = ((PageServiceWrapper) pageService).loadPages(siteKey).iterator();
            } else {
                throw new RuntimeException("Unable to retrieve all pages for " + siteKey);
            }
        } else {
            QueryResult<PageContext> result = pageService.findPages(pagination.getOffset(), pagination.getLimit(),
                Util.from(query.getSiteType()), query.getSiteName(), null, query.getDisplayName());

            iterator = result.iterator();
        }
View Full Code Here

    @Override
    public List<Site> findSites(SiteQuery query) {
        Parameters.requireNonNull(query, "query");

        Pagination pagination = query.getPagination();
        if (pagination != null && query.getSiteTypes().size() > 1) {
            pagination = null; // set it to null so the internal DataStorage doesn't use it, and we manually page later
            log.warn("Pagination is not supported internally for SiteQuery's with multiple site types. Therefore this query has the possibility to perform poorly.");
        }
        boolean includeAll = query.isIncludeEmptySites();

        List<Site> sites = new ArrayList<Site>();
        for (SiteType type : query.getSiteTypes()) {
            List<Site> sitesFound;
            switch (type) {
                case SITE:
                    sitesFound = findSites(pagination, SITES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case SPACE:
                    sitesFound = findSites(pagination, SPACES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case DASHBOARD:
                    sitesFound = findSites(pagination, DASHBOARDS, Comparators.site(query.getSorting()), includeAll);
                    break;
                default:
                    throw new AssertionError();
            }

            sites.addAll(sitesFound);

            // No reason to fetch anymore
            if (pagination != null && sites.size() >= pagination.getLimit()) {
                break;
            }
        }

        filter(sites, query.getFilter());
View Full Code Here

        return p;
    }

    @Override
    public List<Page> findPages(PageQuery query) {
        Pagination pagination = query.getPagination();
        Iterator<PageContext> iterator;
        if (pagination == null) {
            if (query.getSiteType() == null || query.getSiteName() == null)
                throw new IllegalArgumentException("Pagination is required when site type or site name is null.");

            SiteKey siteKey = Util.from(new SiteId(query.getSiteType(), query.getSiteName()));
            if (pageService instanceof PageServiceImpl) {
                iterator = ((PageServiceImpl) pageService).loadPages(siteKey).iterator();
            } else if (pageService instanceof PageServiceWrapper) {
                iterator = ((PageServiceWrapper) pageService).loadPages(siteKey).iterator();
            } else {
                throw new RuntimeException("Unable to retrieve all pages for " + siteKey);
            }
        } else {
            QueryResult<PageContext> result = pageService.findPages(pagination.getOffset(), pagination.getLimit(),
                Util.from(query.getSiteType()), query.getSiteName(), null, query.getDisplayName());

            iterator = result.iterator();
        }
View Full Code Here

    @Override
    public List<Site> findSites(SiteQuery query) {
        Parameters.requireNonNull(query, "query");

        Pagination pagination = query.getPagination();
        if (pagination != null && query.getSiteTypes().size() > 1) {
            pagination = null; // set it to null so the internal DataStorage doesn't use it, and we manually page later
            log.warn("Pagination is not supported internally for SiteQuery's with multiple site types. Therefore this query has the possibility to perform poorly.");
        }
        boolean includeAll = query.isIncludeEmptySites();

        List<Site> sites = new ArrayList<Site>();
        for (SiteType type : query.getSiteTypes()) {
            List<Site> sitesFound;
            switch (type) {
                case SITE:
                    sitesFound = findSites(pagination, SITES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case SPACE:
                    sitesFound = findSites(pagination, SPACES, Comparators.site(query.getSorting()), includeAll);
                    break;
                case DASHBOARD:
                    sitesFound = findSites(pagination, DASHBOARDS, Comparators.site(query.getSorting()), includeAll);
                    break;
                default:
                    throw new AssertionError();
            }

            sites.addAll(sitesFound);

            // No reason to fetch anymore
            if (pagination != null && sites.size() >= pagination.getLimit()) {
                break;
            }
        }

        filter(sites, query.getFilter());
View Full Code Here

TOP

Related Classes of org.gatein.api.common.Pagination

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.