elguardian commented on code in PR #3784:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/3784#discussion_r2044473238


##########
addons/common/persistence/jdbc/src/main/java/org/kie/kogito/persistence/jdbc/GenericRepository.java:
##########
@@ -160,74 +160,33 @@ Optional<Record> findByBusinessKey(String processId, 
String processVersion, Stri
         }
     }
 
-    private static class CloseableWrapper implements Runnable {
-
-        private Deque<AutoCloseable> wrapped = new ArrayDeque<>();
-
-        public <T extends AutoCloseable> T nest(T c) {
-            wrapped.addFirst(c);
-            return c;
-        }
-
-        @Override
-        public void run() {
-            try {
-                close();
-            } catch (Exception ex) {
-                throw new RuntimeException("Error closing resources", ex);
-            }
-        }
-
-        public void close() throws Exception {
-            Exception exception = null;
-            for (AutoCloseable wrap : wrapped) {
-                try {
-                    wrap.close();
-                } catch (Exception ex) {
-                    if (exception != null) {
-                        ex.addSuppressed(exception);
-                    }
-                    exception = ex;
-                }
-            }
-            if (exception != null) {
-                throw exception;
-            }
-        }
-    }
-
     @Override
     Stream<Record> findAllInternal(String processId, String processVersion) {
-        CloseableWrapper close = new CloseableWrapper();
-        try {
-            Connection connection = close.nest(dataSource.getConnection());
-            PreparedStatement statement = 
close.nest(connection.prepareStatement(sqlIncludingVersion(FIND_ALL, 
processVersion)));
+        try (Connection connection = dataSource.getConnection();
+                PreparedStatement statement = 
connection.prepareStatement(sqlIncludingVersion(FIND_ALL, processVersion))) {
             statement.setString(1, processId);
             if (processVersion != null) {
                 statement.setString(2, processVersion);
             }
-            ResultSet resultSet = close.nest(statement.executeQuery());
-            return StreamSupport.stream(new 
Spliterators.AbstractSpliterator<Record>(
-                    Long.MAX_VALUE, Spliterator.ORDERED) {
+            List<Record> record = new ArrayList<>();

Review Comment:
   the performance issue was caused due to the lack of pagination. opening a 
cursor without close it properly causes connection leaks.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to