DATAMONGO-323 - Annotated repository queries consider dynamic sort now.
Applying a Sort parameter handed into a repository query method now for string based (aka. @Query annotated) queries.
This commit is contained in:
@@ -74,6 +74,8 @@ public class StringBasedMongoQuery extends AbstractMongoQuery {
|
||||
} else {
|
||||
query = new BasicQuery(queryString);
|
||||
}
|
||||
|
||||
QueryUtils.applySorting(query, accessor.getSort());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug(String.format("Created query %s", query.getQueryObject()));
|
||||
|
||||
@@ -365,4 +365,22 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
||||
Metrics.KILOMETERS));
|
||||
assertThat(results.getContent().isEmpty(), is(false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAMONGO-323
|
||||
*/
|
||||
@Test
|
||||
public void considersSortForAnnotatedQuery() {
|
||||
|
||||
List<Person> result = repository.findByAgeLessThan(60, new Sort("firstname"));
|
||||
|
||||
assertThat(result.size(), is(7));
|
||||
assertThat(result.get(0), is(alicia));
|
||||
assertThat(result.get(1), is(boyd));
|
||||
assertThat(result.get(2), is(carter));
|
||||
assertThat(result.get(3), is(dave));
|
||||
assertThat(result.get(4), is(leroi));
|
||||
assertThat(result.get(5), is(oliver));
|
||||
assertThat(result.get(6), is(stefan));
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,9 @@ public interface PersonRepository extends MongoRepository<Person, String>, Query
|
||||
List<Person> findByFirstnameLike(String firstname);
|
||||
|
||||
List<Person> findByFirstnameLikeOrderByLastnameAsc(String firstname, Sort sort);
|
||||
|
||||
@Query("{'age' : { '$lt' : ?0 } }")
|
||||
List<Person> findByAgeLessThan(int age, 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