Example usage for org.springframework.data.domain Pageable getPageSize

List of usage examples for org.springframework.data.domain Pageable getPageSize

Introduction

In this page you can find the example usage for org.springframework.data.domain Pageable getPageSize.

Prototype

int getPageSize();

Source Link

Document

Returns the number of items to be returned.

Usage

From source file:com.frank.search.solr.core.ResultHelper.java

/**
 * @param query//from w  w w  .  ja  va 2  s  .co m
 * @param response
 * @return
 * @since 1.5
 */
static Map<Field, Page<FacetFieldEntry>> convertFacetQueryResponseToRangeFacetPageMap(FacetQuery query,
        QueryResponse response) {
    Assert.notNull(query, "Cannot convert response for 'null', query");

    if (!hasFacets(query, response) || isEmpty(response.getFacetRanges())) {
        return Collections.emptyMap();
    }
    Map<Field, Page<FacetFieldEntry>> facetResult = new HashMap<Field, Page<FacetFieldEntry>>();

    Pageable pageable = query.getFacetOptions().getPageable();
    int initalPageSize = pageable.getPageSize();
    for (RangeFacet<?, ?> rangeFacet : response.getFacetRanges()) {

        if (rangeFacet == null || !StringUtils.hasText(rangeFacet.getName())) {
            continue;
        }

        Field field = new SimpleField(rangeFacet.getName());

        List<FacetFieldEntry> entries;
        long total;
        if (isNotEmpty(rangeFacet.getCounts())) {
            entries = new ArrayList<FacetFieldEntry>(initalPageSize);
            for (RangeFacet.Count count : rangeFacet.getCounts()) {
                entries.add(new SimpleFacetFieldEntry(field, count.getValue(), count.getCount()));
            }
            total = rangeFacet.getCounts().size();
        } else {
            entries = Collections.<FacetFieldEntry>emptyList();
            total = 0;
        }

        facetResult.put(field, new SolrResultPage<FacetFieldEntry>(entries, pageable, total, null));

    }

    return facetResult;
}

From source file:com.wiiyaya.framework.provider.utils.PageableHelper.java

public static Pageable mappingAttr(Map<String, String> replaceAttr, Pageable pageRequest) {
    if (pageRequest.getSort() == null || replaceAttr == null || replaceAttr.size() == 0) {
        return pageRequest;
    }/*from www.  j  a v  a2s. co  m*/
    List<Order> orders = new ArrayList<Order>();

    for (Map.Entry<String, String> entry : replaceAttr.entrySet()) {
        Order ctOrd = pageRequest.getSort().getOrderFor(entry.getKey());
        if (ctOrd != null) {
            ctOrd = new Order(ctOrd.getDirection(), entry.getValue());
            orders.add(ctOrd);
        }
    }
    return new PageRequest(pageRequest.getPageNumber(), pageRequest.getPageSize(), new Sort(orders));
}

From source file:org.oncoblocks.centromere.web.controller.RequestUtils.java

/**
 * Uses annotated {@link Model} class definitions to remap any request attribute names in a 
 *   {@link Pageable} so that they match repository attribute names.
 *
 * @param pageable {@link Pageable}/*from w  w w  . j a v a2s  .  co  m*/
 * @return
 */
public static Pageable remapPageable(Pageable pageable, Class<? extends Model<?>> model) {
    logger.debug("Attempting to remap Pageable parameter names.");
    Sort sort = null;
    if (pageable.getSort() != null) {
        List<Sort.Order> orders = new ArrayList<>();
        for (Sort.Order order : pageable.getSort()) {
            orders.add(new Sort.Order(order.getDirection(), remapParameterName(order.getProperty(), model)));
        }
        sort = new Sort(orders);
    }
    return new PageRequest(pageable.getPageNumber(), pageable.getPageSize(), sort);
}

From source file:io.kahu.hawaii.util.call.sql.QueryEnhancer.java

default void addPaging(Map<String, Object> params, Pageable pageable) {
    params.put("start_index", pageable.getPageNumber() * pageable.getPageSize() + 1);
    params.put("end_index", (pageable.getPageNumber() + 1) * pageable.getPageSize());
}

From source file:com.pamarin.income.lazyload.TagLazy.java

@Override
public Page<Tag> loadPage(Pageable page) {
    PageRequest request = new PageRequest(page.getPageNumber(), page.getPageSize(), Sort.Direction.ASC, "name");

    return service.findByOwner(SecurityUtils.getUser(), request);
}

From source file:cz.jirutka.spring.data.jdbc.sql.LimitOffsetSqlGenerator.java

@Override
public String selectAll(TableDescription table, Pageable page) {
    return format("%s LIMIT %d OFFSET %d", selectAll(table, page.getSort()), page.getPageSize(),
            page.getOffset());/*  w ww .  j a v  a  2s .  com*/
}

From source file:net.eusashead.hateoas.response.impl.CustomerRepository.java

public Page<Customer> listCustomers(Pageable page) {
    List<Customer> orders = new ArrayList<Customer>();
    for (int i = 0; i < page.getPageSize(); i++) {
        orders.add(new Customer(i, BigDecimal.valueOf(Math.random() * 100),
                new Date(Math.round(123456789l * Math.random()))));
    }/*from  w ww  . j  a v  a2  s.c o m*/
    return new PageImpl<Customer>(orders, page, 95);
}

From source file:com.feedeo.shopify.service.web.product.ProductWebServiceImpl.java

@Override
public Page<Product> getAll(final Pageable page) {
    checkNotNull(page);/*from   ww  w  .  ja  va  2s .c om*/
    return _getAll(page.getPageNumber(), page.getPageSize(), null);
}

From source file:org.springframework.data.examples.repository.ContactRepositoryImpl.java

@Override
public Page<Contact> findAll(Pageable pageable) {
    long first = pageable.getOffset() + 1;
    long last = pageable.getOffset() + pageable.getPageSize();
    SelectResults<Contact> results = template.find("select * from /Contact where id >= $1 and id <= $2", first,
            last);/*from w ww .j a v a 2s . co  m*/

    List<Contact> contacts = results.asList();

    Collections.sort(contacts, new Comparator<Contact>() {

        @Override
        public int compare(Contact c0, Contact c1) {
            return (int) (c0.getId() - c1.getId());
        }

    });

    return results == null ? null : new PageImpl<Contact>(contacts, pageable, results.size());
}

From source file:com.epam.ta.reportportal.ws.resolver.PagingHandlerMethodArgumentResolver.java

@Override
public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
    Pageable pageable = super.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
    if (0 == pageable.getPageSize()) {
        return new PageRequest(pageable.getPageNumber(), DEFAULT_PAGE_SIZE, pageable.getSort());
    } else if (MAX_PAGE_SIZE < pageable.getPageSize()) {
        return new PageRequest(pageable.getPageNumber(), MAX_PAGE_SIZE, pageable.getSort());
    }//  w  w  w.  j  ava 2 s. c o m
    return pageable;
}