DATADOC-236 - MongoQueryCreator now regards the Sort object from the PartTree on query completion.
This commit is contained in:
@@ -106,6 +106,8 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Query> {
|
||||
@Override
|
||||
protected Query complete(Query query, Sort sort) {
|
||||
|
||||
QueryUtils.applySorting(query, sort);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Created query " + query.getQueryObject());
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.data.mongodb.repository.QPerson;
|
||||
import org.springframework.data.mongodb.repository.Person.Sex;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.mongodb.core.geo.Box;
|
||||
import org.springframework.data.mongodb.core.geo.Circle;
|
||||
@@ -291,11 +292,29 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
repository.save(daveSyer);
|
||||
}
|
||||
|
||||
// @Test
|
||||
/**
|
||||
* @see DATADOC-236
|
||||
*/
|
||||
@Test
|
||||
public void findsPeopleByLastnameAndOrdersCorrectly() {
|
||||
List<Person> result = repository.findByLastnameOrderByFirstnameAsc("Matthews");
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result.get(0), is(dave));
|
||||
assertThat(result.get(1), is(oliver));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATADOC-236
|
||||
*/
|
||||
@Test
|
||||
public void appliesStaticAndDynamicSorting() {
|
||||
List<Person> result = repository.findByFirstnameLikeOrderByLastnameAsc("*e*", new Sort("age"));
|
||||
assertThat(result.size(), is(5));
|
||||
assertThat(result.get(0), is(carter));
|
||||
assertThat(result.get(1), is(stefan));
|
||||
assertThat(result.get(2), is(oliver));
|
||||
assertThat(result.get(3), is(dave));
|
||||
assertThat(result.get(4), is(leroi));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.core.geo.Box;
|
||||
import org.springframework.data.mongodb.core.geo.Circle;
|
||||
import org.springframework.data.mongodb.core.geo.Point;
|
||||
@@ -68,6 +69,8 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
|
||||
* @return
|
||||
*/
|
||||
List<Person> findByFirstnameLike(String firstname);
|
||||
|
||||
List<Person> findByFirstnameLikeOrderByLastnameAsc(String firstname, Sort sort);
|
||||
|
||||
/**
|
||||
* Returns a page of {@link Person}s with a lastname mathing the given one (*-wildcards supported).
|
||||
|
||||
Reference in New Issue
Block a user