quantranhong1999 commented on code in PR #1883:
URL: https://github.com/apache/james-project/pull/1883#discussion_r1439351488


##########
server/data/data-postgres/src/main/java/org/apache/james/domainlist/postgres/PostgresDomainList.java:
##########
@@ -41,7 +41,7 @@ public class PostgresDomainList extends AbstractDomainList {
     private final PostgresExecutor postgresExecutor;
 
     @Inject
-    public PostgresDomainList(DNSService dnsService, @Named(DEFAULT_INJECT) 
PostgresExecutor postgresExecutor) {
+    public PostgresDomainList(DNSService dnsService, @Named(POOL_INJECT_NAME) 
PostgresExecutor postgresExecutor) {

Review Comment:
   My feeling is this "pool" semantic change here and everywhere else is not 
needed and can be avoided.
   
   Maybe we can modify `SinglePostgresConnectionFactory` to be backed by the 
pool connection (and rename it), then avoid the `PoolPostgresExecutor` 
introduction?
   
   We already have this code:
   ```java
       @Provides
       @Singleton
       JamesPostgresConnectionFactory 
provideJamesPostgresConnectionFactory(PostgresConfiguration 
postgresConfiguration, ConnectionFactory connectionFactory) {
           if (postgresConfiguration.rowLevelSecurityEnabled()) {
               LOGGER.info("PostgreSQL row level security enabled");
               LOGGER.info("Implementation for PostgreSQL connection factory: 
{}", DomainImplPostgresConnectionFactory.class.getName());
               return new 
DomainImplPostgresConnectionFactory(connectionFactory);
           }
           LOGGER.info("Implementation for PostgreSQL connection factory: {}", 
SinglePostgresConnectionFactory.class.getName());
           return new 
SinglePostgresConnectionFactory(Mono.from(connectionFactory.create()).block());
       }
   ```
   If RLS enabled, we would use 1 connection per domain.
   If RLS disabled, we would just use pool everywhere.
   
   Then the connection factory (pool or not) would be backed by the 
`JamesPostgresConnectionFactory`, we do not need to care if this is POOL bean 
or not at the DAO layer.
   
   WDYT?



##########
server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java:
##########
@@ -111,7 +114,21 @@ PostgresTableManager 
postgresTableManager(PostgresExecutor.Factory factory,
     @Provides
     @Named(DEFAULT_INJECT)
     @Singleton
-    PostgresExecutor defaultPostgresExecutor(PostgresTableManager 
postgresTableManager) {
+    DefaultPostgresExecutor defaultPostgresExecutor(PostgresTableManager 
postgresTableManager) {
         return postgresTableManager.get();
     }
+
+    @Provides
+    @Named(DEFAULT_INJECT)
+    @Singleton
+    PostgresExecutor provideDefaultPostgresExecutor(DefaultPostgresExecutor 
defaultPostgresExecutor) {
+        return defaultPostgresExecutor;
+    }

Review Comment:
   Q: I see two bean declarations with the same name `@Named(DEFAULT_INJECT)`. 
Is that intended?
   
   BTW where is the `@Named(DEFAULT_INJECT)` bean being used? I do not see it 
injected anywhere (or maybe I missed it).



##########
backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolPostgresExecutor.java:
##########
@@ -0,0 +1,152 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.backends.postgres.utils;
+
+import java.util.Optional;
+import java.util.function.Function;
+
+import javax.inject.Inject;
+
+import org.apache.james.backends.postgres.PostgresConfiguration;
+import org.apache.james.lifecycle.api.Disposable;
+import org.jooq.DSLContext;
+import org.jooq.Record;
+import org.jooq.Record1;
+import org.jooq.impl.DSL;
+import org.reactivestreams.Publisher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.r2dbc.pool.ConnectionPool;
+import io.r2dbc.pool.ConnectionPoolConfiguration;
+import io.r2dbc.spi.Connection;
+import io.r2dbc.spi.ConnectionFactory;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+public class PoolPostgresExecutor implements PostgresExecutor, Disposable {

Review Comment:
   My feeling is this `PoolPostgresExecutor` introduction can be avoided, and 
we just use a single `PostgresExecutor`.
   
   We already have this code:
   ```java
       @Provides
       @Singleton
       JamesPostgresConnectionFactory 
provideJamesPostgresConnectionFactory(PostgresConfiguration 
postgresConfiguration, ConnectionFactory connectionFactory) {
           if (postgresConfiguration.rowLevelSecurityEnabled()) {
               LOGGER.info("PostgreSQL row level security enabled");
               LOGGER.info("Implementation for PostgreSQL connection factory: 
{}", DomainImplPostgresConnectionFactory.class.getName());
               return new 
DomainImplPostgresConnectionFactory(connectionFactory);
           }
           LOGGER.info("Implementation for PostgreSQL connection factory: {}", 
SinglePostgresConnectionFactory.class.getName());
           return new 
SinglePostgresConnectionFactory(Mono.from(connectionFactory.create()).block());
       }
   ```
   
   Maybe we can modify `SinglePostgresConnectionFactory` to be backed by the 
pool connection (and rename it), then avoid the `PoolPostgresExecutor` 
introduction?



##########
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxMessageDAO.java:
##########
@@ -110,7 +112,7 @@ private static SelectFinalStep<Record1<Long>> 
selectMessageUidByMailboxIdAndExtr
     private final PostgresExecutor postgresExecutor;
 
     @Inject
-    public PostgresMailboxMessageDAO(PostgresExecutor postgresExecutor) {
+    public PostgresMailboxMessageDAO(@Named(POOL_INJECT_NAME) PostgresExecutor 
postgresExecutor) {

Review Comment:
   Q: really this dao with RLS on can use pool?



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