Browse Source

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.
pull/832/head
Christoph Strobl 6 years ago committed by Mark Paluch
parent
commit
80da9e21ed
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 9
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecution.java
  2. 16
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

9
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ReactiveMongoQueryExecution.java

@ -19,6 +19,7 @@ import lombok.NonNull; @@ -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 { @@ -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 { @@ -182,4 +187,8 @@ interface ReactiveMongoQueryExecution {
return processor.processResult(source, converter);
}
}
static boolean returnsMonoVoid(ReturnedType returnedType) {
return returnedType.getReturnedType() == Void.class;
}
}

16
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ReactiveMongoRepositoryTests.java

@ -17,6 +17,8 @@ package org.springframework.data.mongodb.repository; @@ -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 { @@ -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 { @@ -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> {}

Loading…
Cancel
Save