|
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; |
@@ -226,52 +226,20 @@ static class DefaultReactiveResultSet implements ReactiveResultSet { |
226 | 226 |
|
227 | 227 | @Override |
228 | 228 | public Flux<Row> rows() { |
229 | | - return getRows(Mono.just(this.resultSet)); |
230 | | - } |
231 | | - |
232 | | - @Override |
233 | | - public Flux<Row> availableRows() { |
234 | | - return toRows(this.resultSet); |
235 | | - } |
236 | 229 |
|
237 | | - private Flux<Row> getRows(Mono<AsyncResultSet> nextResults) { |
238 | | - |
239 | | - return nextResults.flatMapMany(it -> { |
240 | | - |
241 | | - Flux<Row> rows = toRows(it); |
242 | | - |
243 | | - if (!it.hasMorePages()) { |
244 | | - return rows; |
| 230 | + return Mono.just(this.resultSet).expand(asyncResultSet -> { |
| 231 | + if (asyncResultSet.hasMorePages()) { |
| 232 | + return Mono.fromCompletionStage(asyncResultSet.fetchNextPage()); |
245 | 233 | } |
246 | | - |
247 | | - MonoProcessor<AsyncResultSet> processor = MonoProcessor.create(); |
248 | | - |
249 | | - return rows.doOnComplete(() -> fetchMore(it.fetchNextPage(), processor)).concatWith(getRows(processor)); |
250 | | - }); |
| 234 | + return Mono.empty(); |
| 235 | + }).flatMapIterable(AsyncPagingIterable::currentPage); |
251 | 236 | } |
252 | 237 |
|
253 | | - static Flux<Row> toRows(AsyncResultSet resultSet) { |
| 238 | + @Override |
| 239 | + public Flux<Row> availableRows() { |
254 | 240 | return Flux.fromIterable(resultSet.currentPage()); |
255 | 241 | } |
256 | 242 |
|
257 | | - static void fetchMore(CompletionStage<AsyncResultSet> future, MonoProcessor<AsyncResultSet> sink) { |
258 | | - |
259 | | - try { |
260 | | - |
261 | | - future.whenComplete((rs, err) -> { |
262 | | - |
263 | | - if (err != null) { |
264 | | - sink.onError(err); |
265 | | - } else { |
266 | | - sink.onNext(rs); |
267 | | - sink.onComplete(); |
268 | | - } |
269 | | - }); |
270 | | - |
271 | | - } catch (Exception cause) { |
272 | | - sink.onError(cause); |
273 | | - } |
274 | | - } |
275 | 243 |
|
276 | 244 | @Override |
277 | 245 | public ColumnDefinitions getColumnDefinitions() { |
|
0 commit comments