Skip to content

Commit bf1137b

Browse files
committed
Polishing.
Align handle methods exiting avoiding a flatMap stage. See #1107
1 parent 8eac3fe commit bf1137b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/ReactiveSelectOperationSupport.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,19 @@ public Mono<T> one() {
139139
Flux<T> result = this.template.doSelect(this.query.limit(2), this.domainType, getTableName(), this.returnType);
140140

141141
return result.collectList() //
142-
.flatMap(it -> {
142+
.handle((objects, sink) -> {
143143

144-
if (it.isEmpty()) {
145-
return Mono.empty();
144+
if (objects.isEmpty()) {
145+
return;
146146
}
147147

148-
if (it.size() > 1) {
149-
return Mono.error(new IncorrectResultSizeDataAccessException(
150-
String.format("Query [%s] returned non unique result.", this.query), 1));
148+
if (objects.size() == 1) {
149+
sink.next(objects.get(0));
150+
return;
151151
}
152152

153-
return Mono.just(it.get(0));
153+
sink.error(new IncorrectResultSizeDataAccessException(
154+
String.format("Query [%s] returned non unique result.", this.query), 1));
154155
});
155156
}
156157

0 commit comments

Comments
 (0)