diff --git a/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java index e59eac7..e66f1ff 100644 --- a/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java +++ b/src/main/java/org/springframework/data/keyvalue/repository/support/QuerydslKeyValueRepository.java @@ -22,6 +22,7 @@ import java.io.Serializable; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.keyvalue.core.KeyValueOperations; import org.springframework.data.keyvalue.repository.KeyValueRepository; import org.springframework.data.querydsl.EntityPathResolver; @@ -43,6 +44,7 @@ import com.mysema.query.types.path.PathBuilder; * * @author Christoph Strobl * @author Oliver Gierke + * @author Thomas Darimont * @param the domain type to manage * @param the identififer type of the domain type */ @@ -115,6 +117,15 @@ public class QuerydslKeyValueRepository extends Simp return query.list(builder); } + /* + * (non-Javadoc) + * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.Predicate, org.springframework.data.domain.Sort) + */ + @Override + public Iterable findAll(Predicate predicate, Sort sort) { + return findAll(predicate, toOrderSpecifier(sort, builder)); + } + /* * (non-Javadoc) * @see org.springframework.data.querydsl.QueryDslPredicateExecutor#findAll(com.mysema.query.types.Predicate, org.springframework.data.domain.Pageable) @@ -188,5 +199,4 @@ public class QuerydslKeyValueRepository extends Simp } return query; } - } diff --git a/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java index f9bc531..3e2d7de 100644 --- a/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java @@ -30,6 +30,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; import org.springframework.data.keyvalue.Person; +import org.springframework.data.keyvalue.QPerson; import org.springframework.data.keyvalue.core.KeyValueOperations; import org.springframework.data.keyvalue.core.KeyValueTemplate; import org.springframework.data.keyvalue.repository.KeyValueRepository; @@ -41,6 +42,7 @@ import org.springframework.data.repository.CrudRepository; * * @author Christoph Strobl * @author Oliver Gierke + * @author Thomas Darimont */ public abstract class AbstractRepositoryUnitTests { @@ -50,6 +52,8 @@ public abstract class AbstractRepositoryUnitTests LENNISTERS = Arrays.asList(CERSEI, JAIME, TYRION); + protected final QPerson person = QPerson.person; + protected T repository; protected KeyValueRepositoryFactory factory; diff --git a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java index cbf50b0..15c28e9 100644 --- a/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java +++ b/src/test/java/org/springframework/data/map/QuerydslKeyValueRepositoryUnitTests.java @@ -15,15 +15,15 @@ */ package org.springframework.data.map; -import static org.hamcrest.collection.IsCollectionWithSize.*; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*; -import static org.hamcrest.collection.IsIterableContainingInOrder.*; -import static org.hamcrest.core.Is.*; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import java.util.List; + import org.junit.Test; 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.keyvalue.Person; import org.springframework.data.keyvalue.QPerson; @@ -33,11 +33,14 @@ import org.springframework.data.map.QuerydslKeyValueRepositoryUnitTests.QPersonR import org.springframework.data.querydsl.QSort; import org.springframework.data.querydsl.QueryDslPredicateExecutor; +import com.google.common.collect.Lists; + /** * Unit tests for {@link QuerydslKeyValueRepository}. * * @author Christoph Strobl * @author Oliver Gierke + * @author Thomas Darimont */ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitTests { @@ -165,6 +168,22 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT assertThat(repository.exists(QPerson.person.age.eq(CERSEI.getAge())), is(true)); } + /** + * @see DATAKV-96 + */ + @Test + public void shouldSupportFindAllWithPredicateAndSort() { + + repository.save(LENNISTERS); + + List users = Lists.newArrayList(repository.findAll(person.age.gt(0), new Sort(Direction.ASC, "firstname"))); + + assertThat(users, hasSize(3)); + assertThat(users.get(0).getFirstname(), is(CERSEI.getFirstname())); + assertThat(users.get(2).getFirstname(), is(TYRION.getFirstname())); + assertThat(users, hasItems(CERSEI, JAIME, TYRION)); + } + /* * (non-Javadoc) * @see org.springframework.data.map.SimpleKeyValueRepositoryUnitTests#getRepository(org.springframework.data.keyvalue.repository.support.KeyValueRepositoryFactory)