mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge pull request #2681 from ebean-orm/feature/2647
#2647 - When Postgres + isAllQuotedIdentifiers true + using DataSourceConfig THEN `datasourceConfig.addProperty("quoteReturningIdentifiers", false);`
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user