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


##########
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:
   This can be simplified with sneakyThrow.
   ```suggestion
                       .handle((res, error) ->
                           if (error == null) {
                               return res;
                           }
   
                           if (sessionExpiredError(error)) {
                               SessionId newSessionId = 
recreateSession(finalSessionId);
   
                               return action.perform(newSessionId);
                           }
   
                           IgniteUtils.sneakyThrow(error); // Re-throw original 
exception here.
   ```



-- 
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