Polishing.

Align handle methods exiting avoiding a flatMap stage.

See #1107
This commit is contained in:
Mark Paluch
2021-03-22 11:39:32 +01:00
parent 8eac3fed03
commit bf1137b99b

View File

@@ -139,18 +139,19 @@ class ReactiveSelectOperationSupport implements ReactiveSelectOperation {
Flux<T> result = this.template.doSelect(this.query.limit(2), this.domainType, getTableName(), this.returnType);
return result.collectList() //
.flatMap(it -> {
.handle((objects, sink) -> {
if (it.isEmpty()) {
return Mono.empty();
if (objects.isEmpty()) {
return;
}
if (it.size() > 1) {
return Mono.error(new IncorrectResultSizeDataAccessException(
String.format("Query [%s] returned non unique result.", this.query), 1));
if (objects.size() == 1) {
sink.next(objects.get(0));
return;
}
return Mono.just(it.get(0));
sink.error(new IncorrectResultSizeDataAccessException(
String.format("Query [%s] returned non unique result.", this.query), 1));
});
}