Merge pull request #31282 from sephiroth-j

* pr/31282:
  Polish "Use `singleOrEmpty()` instead of `buffer()`"
  Use `singleOrEmpty()` instead of `buffer()`

Closes gh-31282
This commit is contained in:
Stéphane Nicoll
2023-09-26 12:37:41 +02:00

View File

@@ -59,18 +59,11 @@ class DefaultFetchSpec<T> implements FetchSpec<T> {
@Override
public Mono<T> one() {
return all().buffer(2)
.flatMap(list -> {
if (list.isEmpty()) {
return Mono.empty();
}
if (list.size() > 1) {
return Mono.error(new IncorrectResultSizeDataAccessException(
String.format("Query [%s] returned non unique result.", this.resultFunction.getSql()),
1));
}
return Mono.just(list.get(0));
}).next();
return all().singleOrEmpty()
.onErrorMap(IndexOutOfBoundsException.class, ex -> {
String message = String.format("Query [%s] returned non unique result.", this.resultFunction.getSql());
return new IncorrectResultSizeDataAccessException(message, 1);
});
}
@Override