|
1 | 1 | /* |
2 | | - * Copyright 2017-2021 the original author or authors. |
| 2 | + * Copyright 2017-2022 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
17 | 17 |
|
18 | 18 | import reactor.core.publisher.Flux; |
19 | 19 | import reactor.core.publisher.Mono; |
20 | | -import reactor.core.publisher.MonoProcessor; |
21 | 20 | import reactor.core.scheduler.Scheduler; |
22 | 21 |
|
23 | 22 | import java.util.Collections; |
|
33 | 32 | import org.springframework.data.cassandra.ReactiveSession; |
34 | 33 | import org.springframework.util.Assert; |
35 | 34 |
|
| 35 | +import com.datastax.oss.driver.api.core.AsyncPagingIterable; |
36 | 36 | import com.datastax.oss.driver.api.core.CqlIdentifier; |
37 | 37 | import com.datastax.oss.driver.api.core.CqlSession; |
38 | 38 | import com.datastax.oss.driver.api.core.context.DriverContext; |
@@ -263,55 +263,23 @@ static class DefaultReactiveResultSet implements ReactiveResultSet { |
263 | 263 | */ |
264 | 264 | @Override |
265 | 265 | public Flux<Row> rows() { |
266 | | - return getRows(Mono.just(this.resultSet)); |
| 266 | + |
| 267 | + return Mono.just(this.resultSet).expand(asyncResultSet -> { |
| 268 | + if (asyncResultSet.hasMorePages()) { |
| 269 | + return Mono.fromCompletionStage(asyncResultSet.fetchNextPage()); |
| 270 | + } |
| 271 | + return Mono.empty(); |
| 272 | + }).flatMapIterable(AsyncPagingIterable::currentPage); |
267 | 273 | } |
268 | 274 |
|
269 | 275 | /* (non-Javadoc) |
270 | 276 | * @see org.springframework.data.cassandra.ReactiveResultSet#availableRows() |
271 | 277 | */ |
272 | 278 | @Override |
273 | 279 | public Flux<Row> availableRows() { |
274 | | - return toRows(this.resultSet); |
275 | | - } |
276 | | - |
277 | | - private Flux<Row> getRows(Mono<AsyncResultSet> nextResults) { |
278 | | - |
279 | | - return nextResults.flatMapMany(it -> { |
280 | | - |
281 | | - Flux<Row> rows = toRows(it); |
282 | | - |
283 | | - if (!it.hasMorePages()) { |
284 | | - return rows; |
285 | | - } |
286 | | - |
287 | | - MonoProcessor<AsyncResultSet> processor = MonoProcessor.create(); |
288 | | - |
289 | | - return rows.doOnComplete(() -> fetchMore(it.fetchNextPage(), processor)).concatWith(getRows(processor)); |
290 | | - }); |
291 | | - } |
292 | | - |
293 | | - static Flux<Row> toRows(AsyncResultSet resultSet) { |
294 | 280 | return Flux.fromIterable(resultSet.currentPage()); |
295 | 281 | } |
296 | 282 |
|
297 | | - static void fetchMore(CompletionStage<AsyncResultSet> future, MonoProcessor<AsyncResultSet> sink) { |
298 | | - |
299 | | - try { |
300 | | - |
301 | | - future.whenComplete((rs, err) -> { |
302 | | - |
303 | | - if (err != null) { |
304 | | - sink.onError(err); |
305 | | - } else { |
306 | | - sink.onNext(rs); |
307 | | - sink.onComplete(); |
308 | | - } |
309 | | - }); |
310 | | - |
311 | | - } catch (Exception cause) { |
312 | | - sink.onError(cause); |
313 | | - } |
314 | | - } |
315 | 283 |
|
316 | 284 | /* (non-Javadoc) |
317 | 285 | * @see org.springframework.data.cassandra.ReactiveResultSet#getColumnDefinitions() |
|
0 commit comments