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.
This commit is contained in:
committed by
Mark Paluch
parent
6b0b1cd97d
commit
b47c5704e7
@@ -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
|
||||
return Mono.error(new IncorrectResultSizeDataAccessException(1));
|
||||
}
|
||||
return Mono.just(vals.iterator().next());
|
||||
}).single();
|
||||
}).next();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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,
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user