DATACMNS-1063 - Accept Publisher in ReactiveCrudRepository findById(…) and existsById(…).
We now accept Publisher<T> instead of Mono<T> 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
This commit is contained in:
committed by
Christoph Strobl
parent
f0fa12340a
commit
9f1af1fb09
@@ -73,11 +73,11 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
|
||||
/**
|
||||
* 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<T> findById(Mono<ID> id);
|
||||
Mono<T> findById(Publisher<ID> id);
|
||||
|
||||
/**
|
||||
* Returns whether an entity with the given id exists.
|
||||
@@ -89,13 +89,14 @@ public interface ReactiveCrudRepository<T, ID> extends Repository<T, ID> {
|
||||
Mono<Boolean> 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<Boolean> existsById(Mono<ID> id);
|
||||
Mono<Boolean> existsById(Publisher<ID> id);
|
||||
|
||||
/**
|
||||
* Returns all instances of the type.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user