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:org.openlmis.fulfillment.repository.custom.impl.OrderRepositoryImpl.java

private Page<Order> search(OrderSearchParams params, Set<UUID> processingPeriodIds, Pageable pageable,
        Set<UUID> availableSupplyingFacilities, Set<UUID> availableRequestingFacilities) {
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();

    CriteriaQuery<Order> query = builder.createQuery(Order.class);
    query = prepareQuery(query, params, processingPeriodIds, pageable, false, availableSupplyingFacilities,
            availableRequestingFacilities);
    CriteriaQuery<Long> countQuery = builder.createQuery(Long.class);
    countQuery = prepareQuery(countQuery, params, processingPeriodIds, pageable, true,
            availableSupplyingFacilities, availableRequestingFacilities);

    Pageable page = null != pageable ? pageable : new PageRequest(0, Integer.MAX_VALUE);

    Long count = entityManager.createQuery(countQuery).getSingleResult();
    List<Order> result = entityManager.createQuery(query).setMaxResults(page.getPageSize())
            .setFirstResult(page.getPageSize() * page.getPageNumber()).getResultList();

    return new PageImpl<>(result, page, count);
}

From source file:com.frank.search.solr.core.query.SimpleQuery.java

@Override
public final <T extends Query> T setPageRequest(Pageable pageable) {
    Assert.notNull(pageable);/*from ww w  . jav  a2 s .  c om*/

    this.offset = pageable.getOffset();
    this.rows = pageable.getPageSize();
    return this.addSort(pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testMethodDefaultPageable() throws Exception {
    MethodParameter parameter = new MethodParameter(methodDefaultPageable, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);//from w  w w  .j  a v  a 2  s.  c o m

    assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
    assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());

    Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testParameterDefaultPageable() throws Exception {
    MethodParameter parameter = new MethodParameter(parameterDefaultPageable, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);//from w  w  w . j av a  2  s  . c o m

    assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
    assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.DESC, "id").and(new Sort(Sort.Direction.ASC, "name"));
    assertEquals(expectedSort, pageable.getSort());

}

From source file:org.oncoblocks.centromere.sql.sqlbuilder.SqlBuilder.java

public SqlBuilder limit(Pageable pageable) {
    limitClause = String.valueOf(pageable.getOffset()) + "," + String.valueOf(pageable.getPageSize());
    return this;
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testPageable() throws Exception {

    int pn = 1;/*  w  w w .  j a  v a  2  s . co m*/
    int pageSize = 10;
    request.setParameter("page.pn", String.valueOf(pn));
    request.setParameter("page.size", String.valueOf(pageSize));

    MethodParameter parameter = new MethodParameter(pageable, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    //-10
    assertEquals(pn - 1, pageable.getPageNumber());
    assertEquals(pageSize, pageable.getPageSize());
    assertEquals(null, pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testParameterDefaultPageableAndOverrideSort() throws Exception {

    request.setParameter("sort2.id", "desc");
    request.setParameter("sort1.baseInfo.realname", "asc");

    MethodParameter parameter = new MethodParameter(parameterDefaultPageable, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);//w w  w  . j  a  va 2 s . co  m

    assertEquals(Controller.DEFAULT_PAGENUMBER, pageable.getPageNumber());
    assertEquals(Controller.DEFAULT_PAGESIZE, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testCustomNamePrefixPageableAndSort() throws Exception {
    int pn = 1;/*from w w w .j  a  v a 2  s .c o m*/
    int pageSize = 10;
    request.setParameter("foo_page.pn", String.valueOf(pn));
    request.setParameter("foo_page.size", String.valueOf(pageSize));
    request.setParameter("foo_sort2.id", "desc");
    request.setParameter("foo_sort1.baseInfo.realname", "asc");

    MethodParameter parameter = new MethodParameter(customNamePrefixPageableAndSort, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    //-10
    assertEquals(pn - 1, pageable.getPageNumber());
    assertEquals(pageSize, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testPageableAndUnOrderedSort() throws Exception {

    int pn = 1;/* ww  w.  j a v a 2  s  .co  m*/
    int pageSize = 10;
    request.setParameter("page.pn", String.valueOf(pn));
    request.setParameter("page.size", String.valueOf(pageSize));
    request.setParameter("sort.id", "desc");
    request.setParameter("sort.baseInfo.realname", "asc");

    MethodParameter parameter = new MethodParameter(pageableAndSort, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    //-10
    assertEquals(pn - 1, pageable.getPageNumber());
    assertEquals(pageSize, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}

From source file:com.luna.common.web.bind.method.annotation.PageableMethodArgumentResolverTest.java

@Test
public void testPageableAndOrderedSort() throws Exception {

    int pn = 1;/*from w  ww  . j  a va 2  s .  c  om*/
    int pageSize = 10;
    request.setParameter("page.pn", String.valueOf(pn));
    request.setParameter("page.size", String.valueOf(pageSize));
    request.setParameter("sort1.baseInfo.realname", "asc");
    request.setParameter("sort2.id", "desc");

    MethodParameter parameter = new MethodParameter(pageableAndSort, 0);
    NativeWebRequest webRequest = new ServletWebRequest(request);
    Pageable pageable = (Pageable) new PageableMethodArgumentResolver().resolveArgument(parameter, null,
            webRequest, null);

    //-10
    assertEquals(pn - 1, pageable.getPageNumber());
    assertEquals(pageSize, pageable.getPageSize());
    Sort expectedSort = new Sort(Sort.Direction.ASC, "baseInfo.realname")
            .and(new Sort(Sort.Direction.DESC, "id"));
    assertEquals(expectedSort, pageable.getSort());
}