vttranlina commented on code in PR #2190:
URL: https://github.com/apache/james-project/pull/2190#discussion_r1557132970


##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java:
##########
@@ -139,19 +156,21 @@ public Mono<Boolean> executeExists(Function<DSLContext, 
SelectConditionStep<?>>
     }
 
     public Mono<Integer> executeReturnAffectedRowsCount(Function<DSLContext, 
Mono<Integer>> queryFunction) {
-        return dslContext()
-            .flatMap(queryFunction)
-            .retryWhen(Retry.backoff(MAX_RETRY_ATTEMPTS, MIN_BACKOFF)
-                .filter(preparedStatementConflictException()));
+        return 
Mono.usingWhen(jamesPostgresConnectionFactory.getConnection(domain),
+            connection -> dslContext(connection)
+                .flatMap(queryFunction)
+                .retryWhen(Retry.backoff(MAX_RETRY_ATTEMPTS, MIN_BACKOFF)
+                    .filter(preparedStatementConflictException())),
+            jamesPostgresConnectionFactory::closeConnection);
     }
 
     public Mono<Connection> connection() {
-        return connection;
+        return jamesPostgresConnectionFactory.getConnection(domain);
     }
 
     @VisibleForTesting
     public Mono<Void> dispose() {
-        return connection.flatMap(con -> Mono.from(con.close()));
+        return jamesPostgresConnectionFactory.close();

Review Comment:
   Got your idea
   It looks nice 
   don't forget close connection in method `public Mono<Connection> 
connection() {`



-- 
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: notifications-unsubscr...@james.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to