You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/05/03 03:35:21 UTC

(james-project) 02/06: JAMES-2586 Update PostgresCommonModule to use PoolBackedPostgresConnectionFactory

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch postgresql
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 435600614fcfbc9bb2f4dccfea1b43a5069bd5a6
Author: hung phan <hp...@linagora.com>
AuthorDate: Thu Apr 11 11:44:05 2024 +0700

    JAMES-2586 Update PostgresCommonModule to use PoolBackedPostgresConnectionFactory
---
 .../postgres/utils/PoolBackedPostgresConnectionFactory.java | 13 +++++++------
 .../org/apache/james/modules/data/PostgresCommonModule.java | 12 ++++++------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
index 5441a1f4fe..7ad10839bf 100644
--- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
+++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PoolBackedPostgresConnectionFactory.java
@@ -22,8 +22,6 @@ package org.apache.james.backends.postgres.utils;
 import java.time.Duration;
 import java.util.Optional;
 
-import javax.inject.Inject;
-
 import org.apache.james.core.Domain;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,23 +37,26 @@ public class PoolBackedPostgresConnectionFactory implements JamesPostgresConnect
     private static final Domain DEFAULT = Domain.of("default");
     private static final String DEFAULT_DOMAIN_ATTRIBUTE_VALUE = "";
     private static final int INITIAL_SIZE = 10;
-    private static final int MAX_SIZE = 50;
+    private static final int MAX_SIZE = 20;
     private static final Duration MAX_IDLE_TIME = Duration.ofMillis(5000);
 
     private final boolean rowLevelSecurityEnabled;
     private final ConnectionPool pool;
 
-    @Inject
-    public PoolBackedPostgresConnectionFactory(boolean rowLevelSecurityEnabled, ConnectionFactory connectionFactory) {
+    public PoolBackedPostgresConnectionFactory(boolean rowLevelSecurityEnabled, Optional<Integer> maxSize, ConnectionFactory connectionFactory) {
         this.rowLevelSecurityEnabled = rowLevelSecurityEnabled;
         final ConnectionPoolConfiguration configuration = ConnectionPoolConfiguration.builder(connectionFactory)
             .maxIdleTime(MAX_IDLE_TIME)
             .initialSize(INITIAL_SIZE)
-            .maxSize(MAX_SIZE)
+            .maxSize(maxSize.orElse(MAX_SIZE))
             .build();
         pool = new ConnectionPool(configuration);
     }
 
+    public PoolBackedPostgresConnectionFactory(boolean rowLevelSecurityEnabled, ConnectionFactory connectionFactory) {
+        this(rowLevelSecurityEnabled, Optional.empty(), connectionFactory);
+    }
+
     @Override
     public Mono<Connection> getConnection(Optional<Domain> domain) {
         if (rowLevelSecurityEnabled) {
diff --git a/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java b/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
index a2e882f1e7..cc5214df17 100644
--- a/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
+++ b/server/container/guice/postgres-common/src/main/java/org/apache/james/modules/data/PostgresCommonModule.java
@@ -28,8 +28,8 @@ import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.james.backends.postgres.PostgresConfiguration;
 import org.apache.james.backends.postgres.PostgresModule;
 import org.apache.james.backends.postgres.PostgresTableManager;
-import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory;
 import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory;
+import org.apache.james.backends.postgres.utils.PoolBackedPostgresConnectionFactory;
 import org.apache.james.backends.postgres.utils.PostgresExecutor;
 import org.apache.james.backends.postgres.utils.PostgresHealthCheck;
 import org.apache.james.backends.postgres.utils.SinglePostgresConnectionFactory;
@@ -76,14 +76,14 @@ public class PostgresCommonModule extends AbstractModule {
     @Singleton
     JamesPostgresConnectionFactory provideJamesPostgresConnectionFactory(PostgresConfiguration postgresConfiguration,
                                                                          ConnectionFactory connectionFactory,
-                                                                         @Named(JamesPostgresConnectionFactory.NON_RLS_INJECT) JamesPostgresConnectionFactory singlePostgresConnectionFactory) {
+                                                                         @Named(JamesPostgresConnectionFactory.NON_RLS_INJECT) JamesPostgresConnectionFactory jamesPostgresConnectionFactory) {
         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: {}", PoolBackedPostgresConnectionFactory.class.getName());
+            return new PoolBackedPostgresConnectionFactory(true, connectionFactory);
         }
-        LOGGER.info("Implementation for PostgreSQL connection factory: {}", SinglePostgresConnectionFactory.class.getName());
-        return singlePostgresConnectionFactory;
+        LOGGER.info("Implementation for PostgreSQL connection factory: {}", PoolBackedPostgresConnectionFactory.class.getName());
+        return new PoolBackedPostgresConnectionFactory(false, connectionFactory);
     }
 
     @Provides


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