korlov42 commented on code in PR #4814:
URL: https://github.com/apache/ignite-3/pull/4814#discussion_r1870781469


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -415,5 +463,59 @@ void close() {
                 finishTransactionAsync(false);
             }
         }
+
+        CancellationToken registerExecution(long token) {
+            CancelHandle handle = CancelHandle.create();
+
+            CancelHandle previousHandle = cancelHandles.putIfAbsent(token, 
handle);
+
+            assert previousHandle == null;
+
+            return handle.token();
+        }
+
+        void deregisterExecution(long token) {
+            cancelHandles.remove(token);
+        }
+
+        CompletableFuture<Void> cancelExecution(long token) {
+            CancelHandle handle = cancelHandles.remove(token);
+
+            if (handle == null) {
+                return nullCompletedFuture();
+            }
+
+            return handle.cancelAsync();
+        }
+    }
+
+    private void doWhenAllCursorsComplete(
+            CompletableFuture<AsyncSqlCursor<InternalSqlRow>> cursorFuture, 
Runnable action
+    ) {
+        List<CompletableFuture<?>> dependency = new ArrayList<>();
+        var cursorChainTraverser = new Function<AsyncSqlCursor<?>, 
CompletableFuture<AsyncSqlCursor<?>>>() {
+            @Override
+            public CompletableFuture<AsyncSqlCursor<?>> 
apply(AsyncSqlCursor<?> cursor) {
+                dependency.add(cursor.onClose());
+
+                if (cursor.hasNextResult()) {
+                    return cursor.nextResult().thenCompose(this);
+                }
+
+                return allOf(dependency)
+                        .thenRun(action)
+                        .thenApply(ignored -> cursor);
+            }
+        };
+
+        cursorFuture
+                .thenCompose(cursorChainTraverser)
+                .handle((ignored, ex) -> {
+                    if (ex != null) {
+                        action.run();
+                    }
+
+                    return null;
+                });

Review Comment:
   replaced, thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to