DATACMNS-1005 - Paginated query methods now support Javaslang collection types.

To eagerly catch invalid declarations, query methods using pagination had a check applied that the method either returns a Page or List. We've introduced support for alternative collection libraries (Javaslang in particular) and thus the check needs to take these newly supported types into account.

This is now fixed by externalizing the valid types into QueryExecutionConverters and using the ones returned by that to check against.

Original pull request: #200.
This commit is contained in:
Maciek Opala
2017-03-07 20:08:29 +01:00
committed by Oliver Gierke
parent a3afa84198
commit b194f7794d
4 changed files with 63 additions and 3 deletions

View File

@@ -220,6 +220,15 @@ public class QueryMethodUnitTests {
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery(), is(false));
}
@Test // DATACMNS-1005
public void doesNotRejectSeqForPagination() throws Exception {
RepositoryMetadata repositoryMetadata = new DefaultRepositoryMetadata(SampleRepository.class);
Method method = SampleRepository.class.getMethod("returnsSeq", Pageable.class);
assertThat(new QueryMethod(method, repositoryMetadata, factory).isCollectionQuery(), is(true));
}
interface SampleRepository extends Repository<User, Serializable> {
String pagingMethodWithInvalidReturnType(Pageable pageable);
@@ -258,6 +267,9 @@ public class QueryMethodUnitTests {
Seq<User> returnsSeq();
// DATACMNS-1005
Seq<User> returnsSeq(Pageable pageable);
Future<Seq<User>> returnsFutureOfSeq();
Future<Option<User>> returnsFutureOfOption();

View File

@@ -21,7 +21,10 @@ import static org.springframework.data.repository.util.QueryExecutionConverters.
import javaslang.collection.HashMap;
import javaslang.collection.HashSet;
import javaslang.collection.Seq;
import javaslang.collection.Traversable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Slice;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import rx.Completable;
@@ -267,6 +270,16 @@ public class QueryExecutionConvertersUnitTests {
assertThat(unwrap(javaslangMap("key", "value")), is(instanceOf(Map.class)));
}
@Test // DATACMNS-1005
public void registersAllowedPageabletypes() {
final Set<Class<?>> allowedPageableTypes = QueryExecutionConverters.getAllowedPageableTypes();
assertThat(allowedPageableTypes, hasItem(Page.class));
assertThat(allowedPageableTypes, hasItem(Slice.class));
assertThat(allowedPageableTypes, hasItem(List.class));
assertThat(allowedPageableTypes, hasItem(Seq.class));
}
@SuppressWarnings("unchecked")
private static javaslang.control.Option<Object> optionNone() {