Package org.springframework.data.domain

Examples of org.springframework.data.domain.Pageable


  public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {

    assertPageableUniqueness(methodParameter);

    Pageable defaultOrFallback = getDefaultFromAnnotationOrFallback(methodParameter);

    String pageString = webRequest.getParameter(getParameterNameToUse(pageParameterName, methodParameter));
    String pageSizeString = webRequest.getParameter(getParameterNameToUse(sizeParameterName, methodParameter));

    boolean pageAndSizeGiven = StringUtils.hasText(pageString) && StringUtils.hasText(pageSizeString);

    if (!pageAndSizeGiven && defaultOrFallback == null) {
      return null;
    }

    int page = StringUtils.hasText(pageString) ? parseAndApplyBoundaries(pageString, 0, Integer.MAX_VALUE)
        - (oneIndexedParameters ? 1 : 0) : defaultOrFallback.getPageNumber();
    int pageSize = StringUtils.hasText(pageSizeString) ? parseAndApplyBoundaries(pageSizeString, 0, maxPageSize)
        : defaultOrFallback.getPageSize();

    // Limit lower bound
    pageSize = pageSize < 1 ? defaultOrFallback.getPageSize() : pageSize;
    // Limit upper bound
    pageSize = pageSize > maxPageSize ? maxPageSize : pageSize;

    Sort sort = sortResolver.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
    return new PageRequest(page, pageSize, sort == null ? defaultOrFallback.getSort() : sort);
  }
View Full Code Here


    if (!(value instanceof Pageable)) {
      return;
    }

    Pageable pageable = (Pageable) value;

    String pagePropertyName = getParameterNameToUse(getPageParameterName(), parameter);
    String sizePropertyName = getParameterNameToUse(getSizeParameterName(), parameter);

    int pageNumber = pageable.getPageNumber();

    builder.replaceQueryParam(pagePropertyName, isOneIndexedParameters() ? pageNumber + 1 : pageNumber);
    builder.replaceQueryParam(sizePropertyName, pageable.getPageSize() <= getMaxPageSize() ? pageable.getPageSize()
        : getMaxPageSize());

    this.sortResolver.enhance(builder, parameter, pageable.getSort());
  }
View Full Code Here

  }

  @Test
  public void returnsPageableIfAvailable() {

    Pageable pageable = new PageRequest(0, 10);
    ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters, new Object[] { "test", pageable });
    assertThat(accessor.getPageable(), is(pageable));
    assertThat(accessor.getSort(), is(nullValue()));
  }
View Full Code Here

  @Test
  public void returnsSortFromPageableIfAvailable() throws Exception {

    Sort sort = new Sort("foo");
    Pageable pageable = new PageRequest(0, 10, sort);
    ParameterAccessor accessor = new ParametersParameterAccessor(pageableParameters, new Object[] { "test", pageable });
    assertThat(accessor.getPageable(), is(pageable));
    assertThat(accessor.getSort(), is(sort));
  }
View Full Code Here

  @Test
  public void createsRepositoryInstanceWithCustomIntermediateRepository() {

    CustomRepository repository = factory.getRepository(CustomRepository.class);
    Pageable pageable = new PageRequest(0, 10);
    repository.findAll(pageable);

    verify(backingRepo, times(1)).findAll(pageable);
  }
View Full Code Here

        PropertyFilters.get("EQI_state", "1")
    )),new Sort(Direction.DESC, "loginName","realName"));
    Assert.assertEquals(userList.size(), 5);
   
   
    Pageable pageable = new PageRequest(1, 2);
    Page<User> page = userRepository.findAll(Specifications.get(Lists.newArrayList(PropertyFilters.get("EQI_state", "1"))),pageable);
    Assert.assertEquals(page.getContent().size(), 2);
    Assert.assertEquals(page.getTotalPages(), 4);
    Assert.assertEquals(page.getTotalElements(), 8);
  }
View Full Code Here

        ApiVersionPlugin<C,P> apiVersionPlugin = context.getApiVersionPlugin();

        int size = limit == null ? 500 : limit;
        int pageStart = start == null ? 1 : start;

        Pageable pageable = new RangePageAdapter(pageStart,size,getSort(context.getEntityPlugin(), sort));

        List<Specification<P>> specificationList = new ArrayList<Specification<P>>();
        if(query != null && query.length() > 0)
        {
            specificationList.add(new QuerySpecification(predicateBuilder, query, getDomainType()));
View Full Code Here

    return getAllMessages(1, size);
  }

  public List<Message> getAllMessages(int page, int size)
  {
    Pageable pageable = new PageRequest(page, size, new Sort(Sort.Direction.DESC, "createdOn"));
    return messageRepository.findAll(pageable).getContent();
  }
View Full Code Here

   * org.springframework.data.domain.Pageable, java.lang.String)}
   * .
   */
  @Test
  public void testGetAll() {
    Pageable page = new PageRequest(1, 10);

    ModelMap model = new ModelMap();
    userController.getAll(model, null, page, null);

    model.clear();
View Full Code Here

    // save new user for test
    saveTestUser("NewUserId1", "NewUserName1");
    saveTestUser("NewUserId2", "NewUserName2");
    saveTestUser("NewUserId3", "NewUserName3");

    Pageable page = new PageRequest(0, 10);

    // search
    userController.getAll(model, null, page, "NewUserName");
    PageImpl userList = (PageImpl<User>) model.get("users");
    assertThat(userList.getContent().size(), is(3));
View Full Code Here

TOP

Related Classes of org.springframework.data.domain.Pageable

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.