Search in sources :

Example 1 with QSort

use of org.springframework.data.querydsl.QSort in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method shouldSupportSortingWithQSortByQueryDslOrderSpecifier.

// DATAMONGO-1085
@Test
public void shouldSupportSortingWithQSortByQueryDslOrderSpecifier() throws Exception {
    repository.deleteAll();
    List<Person> persons = new ArrayList<Person>();
    for (int i = 0; i < 3; i++) {
        Person person = new Person(String.format("Siggi %s", i), "Bar", 30);
        person.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
        persons.add(person);
    }
    repository.saveAll(persons);
    PageRequest pageRequest = PageRequest.of(0, 2, new QSort(person.address.street.desc()));
    Iterable<Person> result = repository.findAll(pageRequest);
    assertThat(result, is(Matchers.<Person>iterableWithSize(2)));
    assertThat(result.iterator().next().getFirstname(), is("Siggi 2"));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) QSort(org.springframework.data.querydsl.QSort) ArrayList(java.util.ArrayList) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.Test)

Example 2 with QSort

use of org.springframework.data.querydsl.QSort in project spring-data-mongodb by spring-projects.

the class AbstractPersonRepositoryIntegrationTests method shouldSupportSortingWithQSort.

// DATAMONGO-1085
@Test
public void shouldSupportSortingWithQSort() throws Exception {
    repository.deleteAll();
    List<Person> persons = new ArrayList<Person>();
    for (int i = 0; i < 3; i++) {
        Person person = new Person(String.format("Siggi %s", i), "Bar", 30);
        person.setAddress(new Address(String.format("Street %s", i), "12345", "SinCity"));
        persons.add(person);
    }
    repository.saveAll(persons);
    Iterable<Person> result = repository.findAll(new QSort(person.address.street.desc()));
    assertThat(result, is(Matchers.<Person>iterableWithSize(persons.size())));
    assertThat(result.iterator().next().getFirstname(), is("Siggi 2"));
}
Also used : QSort(org.springframework.data.querydsl.QSort) ArrayList(java.util.ArrayList) Point(org.springframework.data.geo.Point) GeoJsonPoint(org.springframework.data.mongodb.core.geo.GeoJsonPoint) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Point (org.springframework.data.geo.Point)2 GeoJsonPoint (org.springframework.data.mongodb.core.geo.GeoJsonPoint)2 QSort (org.springframework.data.querydsl.QSort)2 PageRequest (org.springframework.data.domain.PageRequest)1