Skip to content

Commit

Permalink
Merge pull request spring-projects#31282 from sephiroth-j
Browse files Browse the repository at this point in the history
* pr/31282:
  Polish "Use `singleOrEmpty()` instead of `buffer()`"
  Use `singleOrEmpty()` instead of `buffer()`

Closes spring-projectsgh-31282
  • Loading branch information
snicoll committed Sep 26, 2023
2 parents 2e2a62a + f929121 commit af0b39a
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af0b39a

Please sign in to comment.