From 9f1af1fb094da5f2d193078a2abd29573d154376 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 9 Jun 2017 11:08:48 +0200 Subject: [PATCH] =?UTF-8?q?DATACMNS-1063=20-=20Accept=20Publisher=20in=20R?= =?UTF-8?q?eactiveCrudRepository=20findById(=E2=80=A6)=20and=20existsById(?= =?UTF-8?q?=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now accept Publisher instead of Mono in findById(…) and existsById(…). Users of a ReactiveStreams-based framework are no longer required to perform Publisher to Mono-adoption themselves but can pass a Publisher directly. Both methods use the first emitted value to issue their queries. Additional values are not consumed from the stream. Original Pull Request: #226 --- .../data/repository/reactive/ReactiveCrudRepository.java | 9 +++++---- ...ReactiveWrapperRepositoryFactorySupportUnitTests.java | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java b/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java index b907eb9c0..4602ef22c 100644 --- a/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java +++ b/src/main/java/org/springframework/data/repository/reactive/ReactiveCrudRepository.java @@ -73,11 +73,11 @@ public interface ReactiveCrudRepository extends Repository { /** * Retrieves an entity by its id supplied by a {@link Mono}. * - * @param id must not be {@literal null}. + * @param id must not be {@literal null}. Uses the first emitted element to perform the find-query. * @return the entity with the given id or {@link Mono#empty()} if none found. * @throws IllegalArgumentException if {@code id} is {@literal null}. */ - Mono findById(Mono id); + Mono findById(Publisher id); /** * Returns whether an entity with the given id exists. @@ -89,13 +89,14 @@ public interface ReactiveCrudRepository extends Repository { Mono existsById(ID id); /** - * Returns whether an entity with the given id, supplied by a {@link Mono}, exists. + * Returns whether an entity with the given id, supplied by a {@link Mono}, exists. Uses the first emitted element to + * perform the exists-query. * * @param id must not be {@literal null}. * @return {@literal true} if an entity with the given id exists, {@literal false} otherwise * @throws IllegalArgumentException if {@code id} is {@literal null} */ - Mono existsById(Mono id); + Mono existsById(Publisher id); /** * Returns all instances of the type. diff --git a/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java b/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java index 710f2c94d..3c4e59855 100644 --- a/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java +++ b/src/test/java/org/springframework/data/repository/core/support/ReactiveWrapperRepositoryFactorySupportUnitTests.java @@ -20,6 +20,7 @@ import static org.mockito.Mockito.*; import io.reactivex.Completable; import io.reactivex.Maybe; +import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import rx.Single; @@ -37,7 +38,7 @@ import org.springframework.data.repository.reactive.ReactiveSortingRepository; /** * Unit tests for {@link RepositoryFactorySupport} using reactive wrapper types. - * + * * @author Mark Paluch * @author Christoph Strobl */ @@ -77,7 +78,7 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { verify(backingRepo, times(2)).existsById(id); } - @Test // DATACMNS-836 + @Test // DATACMNS-836, DATACMNS-1063 @SuppressWarnings("unchecked") public void callsRxJava1MethodOnBaseImplementationWithTypeConversion() { @@ -86,7 +87,7 @@ public class ReactiveWrapperRepositoryFactorySupportUnitTests { RxJava1ConvertingRepository repository = factory.getRepository(RxJava1ConvertingRepository.class); repository.existsById(ids); - verify(backingRepo, times(1)).existsById(any(Mono.class)); + verify(backingRepo, times(1)).existsById(any(Publisher.class)); } @Test // DATACMNS-988