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

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

commit 666c7e1b22f2da9be5148e7e3d409a6791a38e7f
Author: Tung Tran <[email protected]>
AuthorDate: Wed Nov 22 10:16:27 2023 +0700

    JAMES-2586 Implement PostgresExecutor Factory and Mailbox Aggregate Module
---
 .../backends/postgres/utils/PostgresExecutor.java  | 21 +++++++++++++++++++-
 .../postgres/PostgresMailboxAggregateModule.java   | 23 ++++++++--------------
 .../mailbox/postgres/JPAMailboxManagerTest.java    |  3 +--
 .../postgres/JpaMailboxManagerStressTest.java      |  3 +--
 .../postgres/host/PostgresHostSystemExtension.java |  4 ++--
 .../modules/mailbox/PostgresMailboxModule.java     |  4 ++--
 .../james/modules/data/PostgresCommonModule.java   |  6 ++++--
 7 files changed, 38 insertions(+), 26 deletions(-)

diff --git 
a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
 
b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
index 30f2812a8a..3b3fd01569 100644
--- 
a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
+++ 
b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/utils/PostgresExecutor.java
@@ -20,10 +20,12 @@
 package org.apache.james.backends.postgres.utils;
 
 import java.util.List;
+import java.util.Optional;
 import java.util.function.Function;
 
 import javax.inject.Inject;
 
+import org.apache.james.core.Domain;
 import org.jooq.DSLContext;
 import org.jooq.Record;
 import org.jooq.SQLDialect;
@@ -39,13 +41,30 @@ import reactor.core.publisher.Mono;
 
 public class PostgresExecutor {
 
+    public static class Factory {
+
+        private final JamesPostgresConnectionFactory 
jamesPostgresConnectionFactory;
+
+        @Inject
+        public Factory(JamesPostgresConnectionFactory 
jamesPostgresConnectionFactory) {
+            this.jamesPostgresConnectionFactory = 
jamesPostgresConnectionFactory;
+        }
+
+        public PostgresExecutor create(Optional<Domain> domain) {
+            return new 
PostgresExecutor(jamesPostgresConnectionFactory.getConnection(domain));
+        }
+
+        public PostgresExecutor create() {
+            return create(Optional.empty());
+        }
+    }
+
     private static final SQLDialect PGSQL_DIALECT = SQLDialect.POSTGRES;
     private static final Settings SETTINGS = new Settings()
         .withRenderFormatted(true)
         .withStatementType(StatementType.PREPARED_STATEMENT);
     private final Mono<Connection> connection;
 
-    @Inject
     public PostgresExecutor(Mono<Connection> connection) {
         this.connection = connection;
     }
diff --git 
a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxAggregateModule.java
similarity index 70%
copy from 
server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
copy to 
mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxAggregateModule.java
index a8c132a6dc..db208dd975 100644
--- 
a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
+++ 
b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxAggregateModule.java
@@ -16,23 +16,16 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.modules.mailbox;
+
+package org.apache.james.mailbox.postgres;
 
 import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxModule;
 import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
-import org.apache.james.modules.data.PostgresCommonModule;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-
-public class PostgresMailboxModule extends AbstractModule {
-
-    @Override
-    protected void configure() {
-        install(new PostgresCommonModule());
 
-        Multibinder<PostgresModule> postgresDataDefinitions = 
Multibinder.newSetBinder(binder(), PostgresModule.class);
-        
postgresDataDefinitions.addBinding().toInstance(PostgresSubscriptionModule.MODULE);
-    }
+public interface PostgresMailboxAggregateModule {
 
-}
\ No newline at end of file
+    PostgresModule MODULE = PostgresModule.aggregateModules(
+        PostgresMailboxModule.MODULE,
+        PostgresSubscriptionModule.MODULE);
+}
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
index 53871f68f8..bc98c13a50 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
@@ -26,7 +26,6 @@ import org.apache.james.events.EventBus;
 import org.apache.james.mailbox.MailboxManagerTest;
 import org.apache.james.mailbox.SubscriptionManager;
 import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
 import org.apache.james.mailbox.store.StoreSubscriptionManager;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Disabled;
@@ -43,7 +42,7 @@ class JPAMailboxManagerTest extends 
MailboxManagerTest<OpenJPAMailboxManager> {
     }
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
index 2abd96da33..ea1ce952e4 100644
--- 
a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
+++ 
b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
@@ -26,7 +26,6 @@ import org.apache.james.backends.postgres.PostgresExtension;
 import org.apache.james.events.EventBus;
 import org.apache.james.mailbox.MailboxManagerStressContract;
 import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -34,7 +33,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 class JpaMailboxManagerStressTest implements 
MailboxManagerStressContract<OpenJPAMailboxManager> {
 
     @RegisterExtension
-    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
+    static PostgresExtension postgresExtension = 
PostgresExtension.withoutRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
 
     static final JpaTestCluster JPA_TEST_CLUSTER = 
JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
     Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
diff --git 
a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystemExtension.java
 
b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystemExtension.java
index 298c9a222a..8ec2e1df87 100644
--- 
a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystemExtension.java
+++ 
b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystemExtension.java
@@ -20,7 +20,7 @@
 package org.apache.james.mpt.imapmailbox.postgres.host;
 
 import org.apache.james.backends.postgres.PostgresExtension;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
+import org.apache.james.mailbox.postgres.PostgresMailboxAggregateModule;
 import org.apache.james.mpt.host.JamesImapHostSystem;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
@@ -36,7 +36,7 @@ public class PostgresHostSystemExtension implements 
BeforeEachCallback, AfterEac
     private final PostgresExtension postgresExtension;
 
     public PostgresHostSystemExtension() {
-        this.postgresExtension = 
PostgresExtension.withRowLevelSecurity(PostgresSubscriptionModule.MODULE);
+        this.postgresExtension = 
PostgresExtension.withRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
         try {
             hostSystem = PostgresHostSystem.build(postgresExtension);
         } catch (Exception e) {
diff --git 
a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
 
b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
index a8c132a6dc..4ef3119e07 100644
--- 
a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
+++ 
b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
@@ -19,7 +19,7 @@
 package org.apache.james.modules.mailbox;
 
 import org.apache.james.backends.postgres.PostgresModule;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
+import org.apache.james.mailbox.postgres.PostgresMailboxAggregateModule;
 import org.apache.james.modules.data.PostgresCommonModule;
 
 import com.google.inject.AbstractModule;
@@ -32,7 +32,7 @@ public class PostgresMailboxModule extends AbstractModule {
         install(new PostgresCommonModule());
 
         Multibinder<PostgresModule> postgresDataDefinitions = 
Multibinder.newSetBinder(binder(), PostgresModule.class);
-        
postgresDataDefinitions.addBinding().toInstance(PostgresSubscriptionModule.MODULE);
+        
postgresDataDefinitions.addBinding().toInstance(PostgresMailboxAggregateModule.MODULE);
     }
 
 }
\ No newline at end of file
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 e9f53a7046..5492c65893 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
@@ -21,14 +21,13 @@ package org.apache.james.modules.data;
 import java.io.FileNotFoundException;
 import java.util.Set;
 
-import javax.inject.Singleton;
-
 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.PostgresExecutor;
 import 
org.apache.james.backends.postgres.utils.SinglePostgresConnectionFactory;
 import org.apache.james.utils.InitializationOperation;
 import org.apache.james.utils.InitilizationOperationBuilder;
@@ -38,6 +37,8 @@ import org.slf4j.LoggerFactory;
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Provides;
+import com.google.inject.Scopes;
+import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
 import com.google.inject.multibindings.ProvidesIntoSet;
 
@@ -52,6 +53,7 @@ public class PostgresCommonModule extends AbstractModule {
     @Override
     public void configure() {
         Multibinder.newSetBinder(binder(), PostgresModule.class);
+        bind(PostgresExecutor.Factory.class).in(Scopes.SINGLETON);
     }
 
     @Provides


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

Reply via email to