Browse Source

DATAMONGO-1907 - Adjust SimpleReactiveMongoRepository.findOne(…) to complete without exception on empty result

We now no longer emit an exception via SimpleReactiveMongoRepository.findOne(Example) if the query completes without yielding a result. Previously findOne(Example) emitted a NoSuchElementException if the query returned no result.

Original pull request: #541.
pull/542/merge
Ruben J Garcia 8 years ago committed by Mark Paluch
parent
commit
f6314a321a
  1. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java
  2. 9
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/SimpleReactiveMongoRepository.java

@ -45,6 +45,7 @@ import org.springframework.util.Assert; @@ -45,6 +45,7 @@ import org.springframework.util.Assert;
* @author Mark Paluch
* @author Oliver Gierke
* @author Christoph Strobl
* @author Ruben J Garcia
* @since 2.0
*/
@RequiredArgsConstructor
@ -97,7 +98,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement @@ -97,7 +98,7 @@ public class SimpleReactiveMongoRepository<T, ID extends Serializable> implement
return Mono.error(new IncorrectResultSizeDataAccessException(1));
}
return Mono.just(vals.iterator().next());
}).single();
}).next();
}
/*

9
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/SimpleReactiveMongoRepositoryTests.java

@ -54,6 +54,7 @@ import org.springframework.util.ClassUtils; @@ -54,6 +54,7 @@ import org.springframework.util.ClassUtils;
*
* @author Mark Paluch
* @author Christoph Strobl
* @author Ruben J Garcia
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:reactive-infrastructure.xml")
@ -441,6 +442,14 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware, @@ -441,6 +442,14 @@ public class SimpleReactiveMongoRepositoryTests implements BeanClassLoaderAware,
StepVerifier.create(repository.findOne(example)).expectError(IncorrectResultSizeDataAccessException.class);
}
@Test // DATAMONGO-1907
public void existsByExampleShouldReturnNonExistingWithoutThrowException() {
Example<ReactivePerson> example = Example.of(new ReactivePerson("foo", "bar", -1));
StepVerifier.create(repository.findOne(example)).verifyComplete();
}
interface ReactivePersonRepostitory extends ReactiveMongoRepository<ReactivePerson, String> {
Flux<ReactivePerson> findByLastname(String lastname);

Loading…
Cancel
Save