Package org.springframework.data.domain

Examples of org.springframework.data.domain.PageRequest


   * @see DATAJPA-486
   */
  @Test
  public void executesQueryToSlice() {

    Slice<User> slice = userRepository.findSliceByLastname("Matthews", new PageRequest(0, 1, ASC, "firstname"));

    assertThat(slice.getContent(), hasItem(dave));
    assertThat(slice.hasNext(), is(true));
  }
View Full Code Here


  public void supportForPaginationCustomQueryMethodsWithEntityExpression() {

    concreteRepository1.save(new ConcreteType1("foo"));
    concreteRepository2.save(new ConcreteType2("foo"));

    Page<ConcreteType2> page = concreteRepository2.findByAttribute1Custom("foo", new PageRequest(0, 10,
        Sort.Direction.DESC, "attribute1"));

    assertThat(page.getNumberOfElements(), is(1));
  }
View Full Code Here

      public Predicate toPredicate(Root<Parent> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
        Path<Set<Child>> childrenPath = root.get("children");
        query.distinct(true);
        return cb.isNotEmpty(childrenPath);
      }
    }, new PageRequest(0, 5, new Sort(Sort.Direction.ASC, "id")));

    List<Parent> content = page.getContent();

    assertThat(content.size(), is(3));
    assertThat(page.getSize(), is(5));
View Full Code Here

        root.join("children");
        // we are interesting in distinct items, especially when join presents in query
        query.distinct(true);
        return cb.isNotEmpty(root.<Set<Child>> get("children"));
      }
    }, new PageRequest(0, 5, new Sort(Sort.Direction.ASC, "id")));

    List<Parent> content = page.getContent();

    // according to the initial setup there should be
    // 3 parents which children collection is not empty
View Full Code Here

    IdClassExampleEmployee emp = new IdClassExampleEmployee();
    emp.setDepartment(dep);
    emp = employeeRepositoryWithIdClass.save(emp);

    Page<IdClassExampleEmployee> page = employeeRepositoryWithIdClass.findAll(new PageRequest(0, 10));

    assertThat(page, is(notNullValue()));
    assertThat(page.getTotalElements(), is(1L));
  }
View Full Code Here

    Method method = UserRepository.class.getMethod("findByFirstname", String.class, Pageable.class);
    JpaQueryMethod queryMethod = new JpaQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
        PersistenceProvider.fromEntityManager(entityManager));
    PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager);

    jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) });
    jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) });
  }
View Full Code Here

    Method method = UserRepository.class.getMethod("findByFirstname", String.class, Pageable.class);
    JpaQueryMethod queryMethod = new JpaQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
        PersistenceProvider.fromEntityManager(entityManager));
    PartTreeJpaQuery jpaQuery = new PartTreeJpaQuery(queryMethod, entityManager);

    Query query = jpaQuery.createQuery(new Object[] { "Matthews", new PageRequest(0, 1) });

    HibernateQuery hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery"));
    assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname=:param0"));

    query = jpaQuery.createQuery(new Object[] { null, new PageRequest(0, 1) });

    hibernateQuery = getValue(query, "h.target." + (isHibernate43() ? "jpqlQuery" : "val$jpaqlQuery"));
    assertThat(hibernateQuery.getHibernateQuery().getQueryString(), endsWith("firstname is null"));
  }
View Full Code Here

  @Test
  public void considersSortingProvidedThroughPageable() {

    Predicate lastnameContainsE = user.lastname.contains("e");

    Page<User> result = repository.findAll(lastnameContainsE, new PageRequest(0, 1, Direction.ASC, "lastname"));

    assertThat(result.getContent(), hasSize(1));
    assertThat(result.getContent().get(0), is(carter));

    result = repository.findAll(lastnameContainsE, new PageRequest(0, 2, Direction.DESC, "lastname"));

    assertThat(result.getContent(), hasSize(2));
    assertThat(result.getContent().get(0), is(oliver));
    assertThat(result.getContent().get(1), is(dave));
  }
View Full Code Here

  @Test
  public void appliesIgnoreCaseOrdering() {

    Sort sort = new Sort(new Order(Direction.DESC, "lastname").ignoreCase(), new Order(Direction.ASC, "firstname"));

    Page<User> result = repository.findAll(user.lastname.contains("e"), new PageRequest(0, 2, sort));

    assertThat(result.getContent(), hasSize(2));
    assertThat(result.getContent().get(0), is(dave));
    assertThat(result.getContent().get(1), is(oliver));
  }
View Full Code Here

    oliver.getColleagues().add(dave);
    dave.getColleagues().add(oliver);

    QUser user = QUser.user;

    Page<User> page = repository.findAll(user.firstname.isNotNull(), new PageRequest(0, 10, new Sort(
        Sort.Direction.ASC, "colleagues.firstname")));

    assertThat(page.getContent(), hasSize(3));
    assertThat(page.getContent(), hasItems(oliver, dave, carter));
  }
View Full Code Here

TOP

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

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.