From 244f336f547b8ba68f7b60329108b70551da6f5e Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 3 May 2022 10:15:07 +1200 Subject: [PATCH] #2647 - When Postgres + isAllQuotedIdentifiers true + using DataSourceConfig THEN `datasourceConfig.addProperty("quoteReturningIdentifiers", false);` I think there is not a case where we do NOT want to do this. allQuotedIdentifiers + Postgres is almost not usable without this. --- .../server/core/InitDataSource.java | 7 ++++ .../server/core/InitDataSourceTest.java | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java index 833f00986..c7e17119f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.core; +import io.ebean.annotation.Platform; import io.ebean.config.DatabaseConfig; import io.ebean.datasource.DataSourceAlertFactory; import io.ebean.datasource.DataSourceConfig; @@ -97,10 +98,16 @@ final class InitDataSource { dsConfig.setReadOnly(true); dsConfig.setDefaults(config.getDataSourceConfig()); dsConfig.setIsolationLevel(config.getDataSourceConfig().getIsolationLevel()); + } else if (isPostgresAllQuotedIdentifiers()) { + dsConfig.addProperty("quoteReturningIdentifiers", false); } return create(dsConfig, readOnly); } + boolean isPostgresAllQuotedIdentifiers() { + return config.isAllQuotedIdentifiers() && Platform.POSTGRES == config.getDatabasePlatform().getPlatform().base(); + } + private DataSource create(DataSourceConfig dsConfig, boolean readOnly) { String poolName = config.getName() + (readOnly ? "-ro" : ""); return DataSourceFactory.create(poolName, dsConfig); diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java index b6a11a959..c6cc19d37 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java @@ -4,6 +4,9 @@ import io.ebean.config.DatabaseConfig; import io.ebean.datasource.DataSourceAlert; import io.ebean.datasource.DataSourceConfig; import io.ebean.datasource.DataSourcePool; +import io.ebean.platform.h2.H2Platform; +import io.ebean.platform.postgres.Postgres9Platform; +import io.ebean.platform.postgres.PostgresPlatform; import org.junit.jupiter.api.Test; import javax.sql.DataSource; @@ -128,6 +131,41 @@ public class InitDataSourceTest { assertEquals("foo", roConfig.getUrl()); } + @Test + void isPostgresAllQuotedIdentifiers_true_when_postgres() { + DatabaseConfig config = new DatabaseConfig(); + config.setAllQuotedIdentifiers(true); + config.setDatabasePlatform(new PostgresPlatform()); + + assertTrue(new InitDataSource(config).isPostgresAllQuotedIdentifiers()); + } + + @Test + void isPostgresAllQuotedIdentifiers_true_when_postgres9() { + DatabaseConfig config = new DatabaseConfig(); + config.setAllQuotedIdentifiers(true); + config.setDatabasePlatform(new Postgres9Platform()); + + assertTrue(new InitDataSource(config).isPostgresAllQuotedIdentifiers()); + } + + @Test + void isPostgresAllQuotedIdentifiers_false() { + DatabaseConfig config = new DatabaseConfig(); + config.setAllQuotedIdentifiers(false); + config.setDatabasePlatform(new PostgresPlatform()); + + assertFalse(new InitDataSource(config).isPostgresAllQuotedIdentifiers()); + } + + @Test + void isPostgresAllQuotedIdentifiers_false_when_notPostgres() { + DatabaseConfig config = new DatabaseConfig(); + config.setAllQuotedIdentifiers(true); + config.setDatabasePlatform(new H2Platform()); + + assertFalse(new InitDataSource(config).isPostgresAllQuotedIdentifiers()); + } @Test public void online() {