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


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/JdbcQueryEventHandlerImpl.java:
##########
@@ -345,4 +364,111 @@ private boolean validateDmlResult(ResultSetMetadata meta, 
boolean next) {
 
         return meta.columns().get(0).type() == ColumnType.INT64;
     }
+
+    static class JdbcConnectionContext {
+        private final Object mux = new Object();
+
+        private final SessionFactory factory;
+        private final SessionCleaner cleaner;
+        private final PropertiesHolder properties = 
PropertiesHelper.emptyHolder();
+
+        private volatile @Nullable SessionId sessionId;
+
+        JdbcConnectionContext(
+                SessionFactory factory,
+                SessionCleaner cleaner
+        ) {
+            this.factory = factory;
+            this.cleaner = cleaner;
+        }
+
+        void close() {
+            synchronized (mux) {
+                SessionId sessionId = this.sessionId;
+
+                this.sessionId = null;
+
+                cleaner.clean(sessionId);
+            }
+        }
+
+        <T> CompletableFuture<T> doInSession(SessionAwareAction<T> action) {
+            SessionId potentiallyNotCreatedSessionId = this.sessionId;
+
+            if (potentiallyNotCreatedSessionId == null) {
+                potentiallyNotCreatedSessionId = recreateSession(null);
+            }
+
+            final SessionId finalSessionId = potentiallyNotCreatedSessionId;
+
+            return action.perform(finalSessionId)
+                    .handle((BiFunction<T, Throwable, Pair<T, Throwable>>) 
Pair::new)
+                    .thenCompose(resAndError -> {
+                        if (resAndError.getSecond() == null) {
+                            return 
CompletableFuture.completedFuture(resAndError.getFirst());
+                        }
+
+                        Throwable error = resAndError.getSecond();
+
+                        if (sessionExpiredError(error)) {
+                            SessionId newSessionId = 
recreateSession(finalSessionId);
+
+                            return action.perform(newSessionId);
+                        }
+
+                        return CompletableFuture.failedFuture(error);

Review Comment:
   suggested change won't work because `action.perform(newSessionId)` returns 
CompletableFuture, and we need to inline result of this future into a chain. 
Thus, we can't avoid `thenCompose`



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to