kitoha commented on code in PR #8210:
URL: https://github.com/apache/gravitino/pull/8210#discussion_r2287484310


##########
core/src/main/java/org/apache/gravitino/storage/relational/session/SqlSessions.java:
##########
@@ -111,4 +89,19 @@ public static void closeSqlSession() {
   public static <T> T getMapper(Class<T> className) {
     return getSqlSession().getMapper(className);
   }
+
+  private static void executeAndCleanupSession(Consumer<SqlSession> consumer) {
+    SqlSession sqlSession = sessions.get();
+
+    if (sqlSession == null) {
+      getSessions().remove();
+      return;
+    }
+
+    try (sqlSession) {
+      consumer.accept(sqlSession);
+    } finally {
+      sessions.remove();
+    }
+  }
 }

Review Comment:
   hi, @justinmclean. Thank you for the review! 
   This code uses a **try-with-resources** statement, which guarantees that 
close() will be called on the SqlSession. This is ensured even if an exception 
is thrown from consumer.accept().
   I was wondering if there was a particular reason you thought the close() 
call might not be guaranteed? I would appreciate your insight.
   Thanks again for your help.



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