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
The following commit(s) were added to refs/heads/postgresql by this push:
new 076d5d0f52 JAMES-2586 Update PoolBackedPostgresConnectionFactory to
avoid running set-domain command in case of empty domain
076d5d0f52 is described below
commit 076d5d0f52aee348703b800e4c40794143411b9b
Author: hung phan <[email protected]>
AuthorDate: Fri May 17 16:40:24 2024 +0700
JAMES-2586 Update PoolBackedPostgresConnectionFactory to avoid running
set-domain command in case of empty domain
---
.../utils/PoolBackedPostgresConnectionFactory.java | 17 ++++-------------
.../postgres/JamesPostgresConnectionFactoryTest.java | 16 ----------------
2 files changed, 4 insertions(+), 29 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 ba558495b3..441af557e0 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
@@ -33,8 +33,6 @@ import reactor.core.publisher.Mono;
public class PoolBackedPostgresConnectionFactory implements
JamesPostgresConnectionFactory {
private static final Logger LOGGER =
LoggerFactory.getLogger(PoolBackedPostgresConnectionFactory.class);
- private static final Domain DEFAULT = Domain.of("default");
- private static final String DEFAULT_DOMAIN_ATTRIBUTE_VALUE = "";
private static final int DEFAULT_INITIAL_SIZE = 10;
private static final int DEFAULT_MAX_SIZE = 20;
@@ -56,9 +54,10 @@ public class PoolBackedPostgresConnectionFactory implements
JamesPostgresConnect
}
@Override
- public Mono<Connection> getConnection(Optional<Domain> domain) {
+ public Mono<Connection> getConnection(Optional<Domain> maybeDomain) {
if (rowLevelSecurityEnabled) {
- return pool.create().flatMap(connection ->
setDomainAttributeForConnection(domain.orElse(DEFAULT), connection));
+ return pool.create().flatMap(connection -> maybeDomain.map(domain
-> setDomainAttributeForConnection(domain, connection))
+ .orElse(Mono.just(connection)));
} else {
return pool.create();
}
@@ -75,17 +74,9 @@ public class PoolBackedPostgresConnectionFactory implements
JamesPostgresConnect
}
private Mono<Connection> setDomainAttributeForConnection(Domain domain,
Connection connection) {
- return Mono.from(connection.createStatement("SET " + DOMAIN_ATTRIBUTE
+ " TO '" + getDomainAttributeValue(domain) + "'") // It should be set value
via Bind, but it doesn't work
+ return Mono.from(connection.createStatement("SET " + DOMAIN_ATTRIBUTE
+ " TO '" + domain.asString() + "'") // It should be set value via Bind, but it
doesn't work
.execute())
.doOnError(e -> LOGGER.error("Error while setting domain attribute
for domain {}", domain, e))
.then(Mono.just(connection));
}
-
- private String getDomainAttributeValue(Domain domain) {
- if (DEFAULT.equals(domain)) {
- return DEFAULT_DOMAIN_ATTRIBUTE_VALUE;
- } else {
- return domain.asString();
- }
- }
}
diff --git
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/JamesPostgresConnectionFactoryTest.java
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/JamesPostgresConnectionFactoryTest.java
index 98fb54de43..4c42b0144c 100644
---
a/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/JamesPostgresConnectionFactoryTest.java
+++
b/backends-common/postgres/src/test/java/org/apache/james/backends/postgres/JamesPostgresConnectionFactoryTest.java
@@ -31,7 +31,6 @@ import com.google.common.collect.ImmutableList;
import io.r2dbc.spi.Connection;
import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
public abstract class JamesPostgresConnectionFactoryTest {
@@ -70,21 +69,6 @@ public abstract class JamesPostgresConnectionFactoryTest {
assertThat(actual).isEqualTo(domain.asString());
}
- @Test
- void getConnectionWithoutDomainShouldReturnEmptyAttribute() {
- Connection connection =
jamesPostgresConnectionFactory().getConnection(Optional.empty()).block();
-
- String message = Flux.from(connection.createStatement("show " +
JamesPostgresConnectionFactory.DOMAIN_ATTRIBUTE)
- .execute())
- .flatMap(result -> result.map((row, rowMetadata) -> row.get(0,
String.class)))
- .collect(ImmutableList.toImmutableList())
- .map(strings -> "")
- .onErrorResume(throwable -> Mono.just(throwable.getMessage()))
- .block();
-
- assertThat(message).isEqualTo("");
- }
-
String getDomainAttributeValue(Connection connection) {
return Flux.from(connection.createStatement("show " +
JamesPostgresConnectionFactory.DOMAIN_ATTRIBUTE)
.execute())
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]