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
The following commit(s) were added to refs/heads/postgresql by this push: new 3fb1370128 JAMES-2586 Clean Code – the using PostgresExecutor.Factory (#1816) 3fb1370128 is described below commit 3fb137012885fbad06380f45b851e16806058ac3 Author: vttran <vtt...@linagora.com> AuthorDate: Mon Nov 27 14:49:27 2023 +0700 JAMES-2586 Clean Code – the using PostgresExecutor.Factory (#1816) --- .../backends/postgres/PostgresTableManager.java | 8 ++++---- .../backends/postgres/utils/PostgresExecutor.java | 4 +++- .../james/backends/postgres/PostgresExtension.java | 20 +++++++++++++++++--- .../backends/postgres/PostgresTableManagerTest.java | 6 ++++-- .../PostgresMailboxSessionMapperFactory.java | 11 +++++------ .../mailbox/postgres/JpaMailboxManagerProvider.java | 5 ++--- .../postgres/PostgresSubscriptionManagerTest.java | 3 +-- .../PostgresMailboxMapperRowLevelSecurityTest.java | 5 ++--- .../task/JPARecomputeCurrentQuotasServiceTest.java | 5 ++--- ...stgresSubscriptionMapperRowLevelSecurityTest.java | 5 ++--- .../postgres/host/PostgresHostSystem.java | 6 +----- .../james/modules/data/PostgresCommonModule.java | 14 ++++++++++++-- .../apache/james/user/postgres/PostgresUsersDAO.java | 7 ++++--- .../user/postgres/PostgresUsersRepositoryTest.java | 2 +- 14 files changed, 60 insertions(+), 41 deletions(-) diff --git a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java index a46e6b36a2..a7277dc414 100644 --- a/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java +++ b/backends-common/postgres/src/main/java/org/apache/james/backends/postgres/PostgresTableManager.java @@ -19,11 +19,11 @@ package org.apache.james.backends.postgres; -import java.util.Optional; +import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT; import javax.inject.Inject; +import javax.inject.Named; -import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory; import org.apache.james.backends.postgres.utils.PostgresExecutor; import org.apache.james.lifecycle.api.Startable; import org.jooq.exception.DataAccessException; @@ -43,10 +43,10 @@ public class PostgresTableManager implements Startable { private final boolean rowLevelSecurityEnabled; @Inject - public PostgresTableManager(JamesPostgresConnectionFactory postgresConnectionFactory, + public PostgresTableManager(@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor, PostgresModule module, PostgresConfiguration postgresConfiguration) { - this.postgresExecutor = new PostgresExecutor(postgresConnectionFactory.getConnection(Optional.empty())); + this.postgresExecutor = postgresExecutor; this.module = module; this.rowLevelSecurityEnabled = postgresConfiguration.rowLevelSecurityEnabled(); } 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 3b3fd01569..7a6485108f 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 @@ -41,6 +41,8 @@ import reactor.core.publisher.Mono; public class PostgresExecutor { + public static final String DEFAULT_INJECT = "default"; + public static class Factory { private final JamesPostgresConnectionFactory jamesPostgresConnectionFactory; @@ -65,7 +67,7 @@ public class PostgresExecutor { .withStatementType(StatementType.PREPARED_STATEMENT); private final Mono<Connection> connection; - public PostgresExecutor(Mono<Connection> connection) { + private PostgresExecutor(Mono<Connection> connection) { this.connection = connection; } diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java index 4f9ba51094..476b5819ee 100644 --- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java +++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresExtension.java @@ -29,7 +29,9 @@ import java.util.stream.Collectors; import org.apache.http.client.utils.URIBuilder; import org.apache.james.GuiceModuleTestExtension; +import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory; import org.apache.james.backends.postgres.utils.PostgresExecutor; +import org.apache.james.backends.postgres.utils.SinglePostgresConnectionFactory; import org.junit.jupiter.api.extension.ExtensionContext; import org.testcontainers.containers.PostgreSQLContainer; @@ -65,6 +67,7 @@ public class PostgresExtension implements GuiceModuleTestExtension { private PostgresConfiguration postgresConfiguration; private PostgresExecutor postgresExecutor; private PostgresqlConnectionFactory connectionFactory; + private PostgresExecutor.Factory executorFactory; private PostgresExtension(PostgresModule postgresModule, boolean rlsEnabled) { this.postgresModule = postgresModule; @@ -124,9 +127,16 @@ public class PostgresExtension implements GuiceModuleTestExtension { .schema(postgresConfiguration.getDatabaseSchema()) .build()); - postgresExecutor = new PostgresExecutor(connectionFactory.create() - .cache() - .cast(Connection.class)); + + if (rlsEnabled) { + executorFactory = new PostgresExecutor.Factory(new DomainImplPostgresConnectionFactory(connectionFactory)); + } else { + executorFactory = new PostgresExecutor.Factory(new SinglePostgresConnectionFactory(connectionFactory.create() + .cache() + .cast(Connection.class).block())); + } + + postgresExecutor = executorFactory.create(); } @Override @@ -180,6 +190,10 @@ public class PostgresExtension implements GuiceModuleTestExtension { return connectionFactory; } + public PostgresExecutor.Factory getExecutorFactory() { + return executorFactory; + } + private void initTablesAndIndexes() { PostgresTableManager postgresTableManager = new PostgresTableManager(postgresExecutor, postgresModule, postgresConfiguration.rowLevelSecurityEnabled()); postgresTableManager.initializeTables().block(); diff --git a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java index ac5d73c2d7..e0150d79db 100644 --- a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java +++ b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/PostgresTableManagerTest.java @@ -42,7 +42,7 @@ class PostgresTableManagerTest { static PostgresExtension postgresExtension = PostgresExtension.empty(); Function<PostgresModule, PostgresTableManager> tableManagerFactory = - module -> new PostgresTableManager(new PostgresExecutor(postgresExtension.getConnection()), module, true); + module -> new PostgresTableManager(postgresExtension.getPostgresExecutor(), module, true); @Test void initializeTableShouldSuccessWhenModuleHasSingleTable() { @@ -330,7 +330,9 @@ class PostgresTableManagerTest { PostgresModule module = PostgresModule.table(table); boolean disabledRLS = false; - PostgresTableManager testee = new PostgresTableManager(new PostgresExecutor(postgresExtension.getConnection()), module, disabledRLS); + + + PostgresTableManager testee = new PostgresTableManager(postgresExtension.getPostgresExecutor(), module, disabledRLS); testee.initializeTables() .block(); diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java index 7b20e1996f..34f5aa17b6 100644 --- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java +++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java @@ -25,7 +25,6 @@ import javax.persistence.EntityManagerFactory; import org.apache.commons.lang3.NotImplementedException; import org.apache.james.backends.jpa.EntityManagerUtils; import org.apache.james.backends.jpa.JPAConfiguration; -import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory; import org.apache.james.backends.postgres.utils.PostgresExecutor; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.postgres.mail.JPAAnnotationMapper; @@ -58,19 +57,20 @@ public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFac private final JPAModSeqProvider modSeqProvider; private final AttachmentMapper attachmentMapper; private final JPAConfiguration jpaConfiguration; - private final JamesPostgresConnectionFactory postgresConnectionFactory; + + private final PostgresExecutor.Factory executorFactory; @Inject public PostgresMailboxSessionMapperFactory(EntityManagerFactory entityManagerFactory, JPAUidProvider uidProvider, JPAModSeqProvider modSeqProvider, JPAConfiguration jpaConfiguration, - JamesPostgresConnectionFactory postgresConnectionFactory) { + PostgresExecutor.Factory executorFactory) { this.entityManagerFactory = entityManagerFactory; this.uidProvider = uidProvider; this.modSeqProvider = modSeqProvider; EntityManagerUtils.safelyClose(createEntityManager()); this.attachmentMapper = new JPAAttachmentMapper(entityManagerFactory); this.jpaConfiguration = jpaConfiguration; - this.postgresConnectionFactory = postgresConnectionFactory; + this.executorFactory = executorFactory; } @Override @@ -90,8 +90,7 @@ public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFac @Override public SubscriptionMapper createSubscriptionMapper(MailboxSession session) { - return new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(new PostgresExecutor( - postgresConnectionFactory.getConnection(session.getUser().getDomainPart())))); + return new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(executorFactory.create(session.getUser().getDomainPart()))); } /** diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java index 980804d2cc..d6100b2ade 100644 --- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java +++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java @@ -26,7 +26,6 @@ import javax.persistence.EntityManagerFactory; import org.apache.james.backends.jpa.JPAConfiguration; import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.backends.postgres.PostgresExtension; -import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory; import org.apache.james.events.EventBusTestFixture; import org.apache.james.events.InVMEventBus; import org.apache.james.events.MemoryEventDeadLetters; @@ -65,8 +64,8 @@ public class JpaMailboxManagerProvider { .attachmentStorage(true) .build(); - PostgresMailboxSessionMapperFactory mf = new PostgresMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(entityManagerFactory), new JPAModSeqProvider(entityManagerFactory), jpaConfiguration, - new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory())); + PostgresMailboxSessionMapperFactory mf = new PostgresMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(entityManagerFactory), + new JPAModSeqProvider(entityManagerFactory), jpaConfiguration, postgresExtension.getExecutorFactory()); MailboxACLResolver aclResolver = new UnionMailboxACLResolver(); MessageParser messageParser = new MessageParser(); diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java index ebf07bf37f..c68ed09b84 100644 --- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java +++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java @@ -23,7 +23,6 @@ import javax.persistence.EntityManagerFactory; import org.apache.james.backends.jpa.JPAConfiguration; import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.backends.postgres.PostgresExtension; -import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory; import org.apache.james.events.EventBusTestFixture; import org.apache.james.events.InVMEventBus; import org.apache.james.events.MemoryEventDeadLetters; @@ -66,7 +65,7 @@ class PostgresSubscriptionManagerTest implements SubscriptionManagerContract { new JPAUidProvider(entityManagerFactory), new JPAModSeqProvider(entityManagerFactory), jpaConfiguration, - new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory())); + postgresExtension.getExecutorFactory()); InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new RecordingMetricFactory()), EventBusTestFixture.RETRY_BACKOFF_CONFIGURATION, new MemoryEventDeadLetters()); subscriptionManager = new StoreSubscriptionManager(mapperFactory, mapperFactory, eventBus); } diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxMapperRowLevelSecurityTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxMapperRowLevelSecurityTest.java index 3eb23fe07e..bdf719dfe2 100644 --- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxMapperRowLevelSecurityTest.java +++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxMapperRowLevelSecurityTest.java @@ -44,9 +44,8 @@ public class PostgresMailboxMapperRowLevelSecurityTest { @BeforeEach public void setUp() { - mailboxMapperFactory = session -> new PostgresMailboxMapper(new PostgresMailboxDAO(new PostgresExecutor( - new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory()) - .getConnection(session.getUser().getDomainPart())))); + PostgresExecutor.Factory executorFactory = new PostgresExecutor.Factory(new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory())); + mailboxMapperFactory = session -> new PostgresMailboxMapper(new PostgresMailboxDAO(executorFactory.create(session.getUser().getDomainPart()))); } @Test diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java index ca3b89df12..077c249c19 100644 --- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java +++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java @@ -25,14 +25,13 @@ import org.apache.commons.configuration2.BaseHierarchicalConfiguration; import org.apache.james.backends.jpa.JPAConfiguration; import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.backends.postgres.PostgresExtension; -import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.jpa.model.JPADomain; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.SessionProvider; import org.apache.james.mailbox.postgres.JPAMailboxFixture; -import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory; import org.apache.james.mailbox.postgres.JpaMailboxManagerProvider; +import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory; import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider; import org.apache.james.mailbox.postgres.mail.JPAUidProvider; import org.apache.james.mailbox.postgres.quota.JpaCurrentQuotaManager; @@ -89,7 +88,7 @@ class JPARecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServ new JPAUidProvider(entityManagerFactory), new JPAModSeqProvider(entityManagerFactory), jpaConfiguration, - new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory())); + postgresExtension.getExecutorFactory()); usersRepository = new JPAUsersRepository(NO_DOMAIN_LIST); usersRepository.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory()); diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java index b9c1c2caa0..553d605612 100644 --- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java +++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/user/PostgresSubscriptionMapperRowLevelSecurityTest.java @@ -41,9 +41,8 @@ public class PostgresSubscriptionMapperRowLevelSecurityTest { @BeforeEach public void setUp() { - subscriptionMapperFactory = session -> new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(new PostgresExecutor( - new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory()) - .getConnection(session.getUser().getDomainPart())))); + PostgresExecutor.Factory executorFactory = new PostgresExecutor.Factory(new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory())); + subscriptionMapperFactory = session -> new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(executorFactory.create(session.getUser().getDomainPart()))); } @Test diff --git a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java index 5c98591f0e..9fc4823f9a 100644 --- a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java +++ b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java @@ -26,8 +26,6 @@ import javax.persistence.EntityManagerFactory; import org.apache.james.backends.jpa.JPAConfiguration; import org.apache.james.backends.jpa.JpaTestCluster; import org.apache.james.backends.postgres.PostgresExtension; -import org.apache.james.backends.postgres.utils.DomainImplPostgresConnectionFactory; -import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory; import org.apache.james.core.quota.QuotaCountLimit; import org.apache.james.core.quota.QuotaSizeLimit; import org.apache.james.events.EventBusTestFixture; @@ -99,14 +97,12 @@ public class PostgresHostSystem extends JamesImapHostSystem { private JPAPerUserMaxQuotaManager maxQuotaManager; private OpenJPAMailboxManager mailboxManager; private final PostgresExtension postgresExtension; - private static JamesPostgresConnectionFactory postgresConnectionFactory; public PostgresHostSystem(PostgresExtension postgresExtension) { this.postgresExtension = postgresExtension; } public void beforeAll() { Preconditions.checkNotNull(postgresExtension.getConnectionFactory()); - postgresConnectionFactory = new DomainImplPostgresConnectionFactory(postgresExtension.getConnectionFactory()); } @Override @@ -119,7 +115,7 @@ public class PostgresHostSystem extends JamesImapHostSystem { .driverName("driverName") .driverURL("driverUrl") .build(); - PostgresMailboxSessionMapperFactory mapperFactory = new PostgresMailboxSessionMapperFactory(entityManagerFactory, uidProvider, modSeqProvider, jpaConfiguration, postgresConnectionFactory); + PostgresMailboxSessionMapperFactory mapperFactory = new PostgresMailboxSessionMapperFactory(entityManagerFactory, uidProvider, modSeqProvider, jpaConfiguration, postgresExtension.getExecutorFactory()); MailboxACLResolver aclResolver = new UnionMailboxACLResolver(); MessageParser messageParser = new MessageParser(); 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 d33097bc4f..30dcf74a09 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 @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.modules.data; +import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT; + import java.io.FileNotFoundException; import java.util.Set; @@ -41,6 +43,7 @@ import com.google.inject.Scopes; import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; import com.google.inject.multibindings.ProvidesIntoSet; +import com.google.inject.name.Named; import io.r2dbc.postgresql.PostgresqlConnectionConfiguration; import io.r2dbc.postgresql.PostgresqlConnectionFactory; @@ -95,10 +98,17 @@ public class PostgresCommonModule extends AbstractModule { @Provides @Singleton - PostgresTableManager postgresTableManager(JamesPostgresConnectionFactory jamesPostgresConnectionFactory, + PostgresTableManager postgresTableManager(@Named(DEFAULT_INJECT) PostgresExecutor defaultPostgresExecutor, PostgresModule postgresModule, PostgresConfiguration postgresConfiguration) { - return new PostgresTableManager(jamesPostgresConnectionFactory, postgresModule, postgresConfiguration); + return new PostgresTableManager(defaultPostgresExecutor, postgresModule, postgresConfiguration); + } + + @Provides + @Named(DEFAULT_INJECT) + @Singleton + PostgresExecutor defaultPostgresExecutor(PostgresExecutor.Factory factory) { + return factory.create(); } @ProvidesIntoSet diff --git a/server/data/data-postgres/src/main/java/org/apache/james/user/postgres/PostgresUsersDAO.java b/server/data/data-postgres/src/main/java/org/apache/james/user/postgres/PostgresUsersDAO.java index 67c998b09a..d8447e527f 100644 --- a/server/data/data-postgres/src/main/java/org/apache/james/user/postgres/PostgresUsersDAO.java +++ b/server/data/data-postgres/src/main/java/org/apache/james/user/postgres/PostgresUsersDAO.java @@ -19,6 +19,7 @@ package org.apache.james.user.postgres; +import static org.apache.james.backends.postgres.utils.PostgresExecutor.DEFAULT_INJECT; import static org.apache.james.backends.postgres.utils.PostgresUtils.UNIQUE_CONSTRAINT_VIOLATION_PREDICATE; import static org.apache.james.user.postgres.PostgresUserModule.PostgresUserTable.ALGORITHM; import static org.apache.james.user.postgres.PostgresUserModule.PostgresUserTable.HASHED_PASSWORD; @@ -30,8 +31,8 @@ import java.util.Iterator; import java.util.Optional; import javax.inject.Inject; +import javax.inject.Named; -import org.apache.james.backends.postgres.utils.JamesPostgresConnectionFactory; import org.apache.james.backends.postgres.utils.PostgresExecutor; import org.apache.james.core.Username; import org.apache.james.user.api.AlreadyExistInUsersRepositoryException; @@ -52,9 +53,9 @@ public class PostgresUsersDAO implements UsersDAO { private final Algorithm.HashingMode fallbackHashingMode; @Inject - public PostgresUsersDAO(JamesPostgresConnectionFactory jamesPostgresConnectionFactory, + public PostgresUsersDAO(@Named(DEFAULT_INJECT) PostgresExecutor postgresExecutor, PostgresUsersRepositoryConfiguration postgresUsersRepositoryConfiguration) { - this.postgresExecutor = new PostgresExecutor(jamesPostgresConnectionFactory.getConnection(Optional.empty())); + this.postgresExecutor = postgresExecutor; this.algorithm = postgresUsersRepositoryConfiguration.getPreferredAlgorithm(); this.fallbackHashingMode = postgresUsersRepositoryConfiguration.getFallbackHashingMode(); } diff --git a/server/data/data-postgres/src/test/java/org/apache/james/user/postgres/PostgresUsersRepositoryTest.java b/server/data/data-postgres/src/test/java/org/apache/james/user/postgres/PostgresUsersRepositoryTest.java index e83f03bf10..00c250104d 100644 --- a/server/data/data-postgres/src/test/java/org/apache/james/user/postgres/PostgresUsersRepositoryTest.java +++ b/server/data/data-postgres/src/test/java/org/apache/james/user/postgres/PostgresUsersRepositoryTest.java @@ -89,7 +89,7 @@ class PostgresUsersRepositoryTest { } private static UsersRepositoryImpl<PostgresUsersDAO> getUsersRepository(DomainList domainList, boolean enableVirtualHosting, Optional<Username> administrator) throws Exception { - PostgresUsersDAO usersDAO = new PostgresUsersDAO(new SinglePostgresConnectionFactory(postgresExtension.getConnection().block()), + PostgresUsersDAO usersDAO = new PostgresUsersDAO(postgresExtension.getPostgresExecutor(), PostgresUsersRepositoryConfiguration.DEFAULT); BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration(); configuration.addProperty("enableVirtualHosting", String.valueOf(enableVirtualHosting)); --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org