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


##########
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:
   Hi, the point of returning a stream was to not go through the whole list 
returned by the JDBC driver, avoiding a performance issue if the list of 
process instances is huge (notice that in the implementation being replaced you 
do not have to build the whole list of records )
   Cant we fix the leak in closeablewrapper (whatever is it, maybe onclose is 
not invoked always?) without changing this part? I think we are going back to 
former implementaiton that provokes performance issues when the list of process 
instances grow. 



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