DATAMONGO-2406 - Derived reactive deleteBy query execution should allow Mono<Void> result.
Mono<Void> is now a supported return type of derived reactive deleteBy queries like:
Mono<Void> deleteByLastname(String lastname);
Original pull request: #825.
This commit is contained in:
committed by
Mark Paluch
parent
708466b323
commit
80da9e21ed
@@ -19,6 +19,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.EntityInstantiators;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -168,6 +169,10 @@ interface ReactiveMongoQueryExecution {
|
||||
|
||||
ReturnedType returnedType = processor.getReturnedType();
|
||||
|
||||
if (returnsMonoVoid(returnedType)) {
|
||||
return Flux.from((Publisher) source).then();
|
||||
}
|
||||
|
||||
if (ClassUtils.isPrimitiveOrWrapper(returnedType.getReturnedType())) {
|
||||
return source;
|
||||
}
|
||||
@@ -182,4 +187,8 @@ interface ReactiveMongoQueryExecution {
|
||||
return processor.processResult(source, converter);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean returnsMonoVoid(ReturnedType returnedType) {
|
||||
return returnedType.getReturnedType() == Void.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.mongodb.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.*;
|
||||
import static org.springframework.data.mongodb.core.query.Query.*;
|
||||
import static org.springframework.data.mongodb.test.util.Assertions.assertThat;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -575,6 +577,18 @@ public class ReactiveMongoRepositoryTests {
|
||||
.expectNext("lastname").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2406
|
||||
public void deleteByShouldHandleVoidResultTypeCorrectly() {
|
||||
|
||||
repository.deleteByLastname(dave.getLastname()) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
template.find(query(where("lastname").is(dave.getLastname())), Person.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
interface ReactivePersonRepository
|
||||
extends ReactiveMongoRepository<Person, String>, ReactiveQuerydslPredicateExecutor<Person> {
|
||||
|
||||
@@ -645,6 +659,8 @@ public class ReactiveMongoRepositoryTests {
|
||||
|
||||
@Query(value = "{_id:?0}")
|
||||
Mono<org.bson.Document> findDocumentById(String id);
|
||||
|
||||
Mono<Void> deleteByLastname(String lastname);
|
||||
}
|
||||
|
||||
interface ReactiveContactRepository extends ReactiveMongoRepository<Contact, String> {}
|
||||
|
||||
Reference in New Issue
Block a user