diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java index 979de664..391cd449 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractCouchbaseQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors + * Copyright 2020-2021 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,8 @@ public abstract class AbstractCouchbaseQuery extends AbstractCouchbaseQueryBase< return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).all(); // s/b tail() instead of all() } else if (getQueryMethod().isCollectionQuery()) { return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).all(); + } else if (getQueryMethod().isStreamQuery()) { + return (q, t, c) -> operation.matching(q.with(accessor.getPageable())).stream(); } else if (isCountQuery()) { return (q, t, c) -> operation.matching(q).count(); } else if (isExistsQuery()) { diff --git a/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java b/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java index 63293b33..07e7bd9c 100644 --- a/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java +++ b/src/test/java/org/springframework/data/couchbase/domain/UserRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors + * Copyright 2012-2021 the original author or authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.data.couchbase.domain; import java.util.List; +import java.util.stream.Stream; import org.springframework.data.couchbase.repository.CouchbaseRepository; import org.springframework.data.couchbase.repository.Query; @@ -36,6 +37,8 @@ public interface UserRepository extends CouchbaseRepository { List findByFirstname(String firstname); + Stream findByLastname(String lastname); + List findByFirstnameIn(String... firstnames); List findByFirstnameIn(JsonArray firstnames); diff --git a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java index 49ddbcee..669daf0f 100644 --- a/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java +++ b/src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -233,6 +233,21 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr userRepository.delete(user); } + @Test + public void testStreamQuery() { + User user1 = new User("1", "Dave", "Wilson"); + User user2 = new User("2", "Brian", "Wilson"); + + userRepository.save(user1); + userRepository.save(user2); + List users = userRepository.findByLastname("Wilson").collect(Collectors.toList()); + assertEquals(2,users.size()); + assertTrue(users.contains(user1)); + assertTrue(users.contains(user2)); + userRepository.delete(user1); + userRepository.delete(user2); + } + @Test void count() { String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };