Don't try to set unicode connection properties for PostgreSQL (#1134)

This commit is contained in:
Luck 2019-02-04 19:36:53 +00:00
parent 43d04a97f5
commit 526448ce40
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 28 additions and 18 deletions

View File

@ -34,6 +34,7 @@ import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -50,8 +51,8 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
return null;
}
protected void appendProperties(HikariConfig config, StorageCredentials credentials) {
for (Map.Entry<String, String> property : credentials.getProperties().entrySet()) {
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
for (Map.Entry<String, String> property : properties.entrySet()) {
config.addDataSourceProperty(property.getKey(), property.getValue());
}
}
@ -76,7 +77,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
config.setPoolName("luckperms-hikari");
appendConfigurationInfo(config);
appendProperties(config, this.configuration);
appendProperties(config, new HashMap<>(this.configuration.getProperties()));
config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
config.setMinimumIdle(this.configuration.getMinIdleConnections());

View File

@ -30,7 +30,6 @@ import com.zaxxer.hikari.HikariConfig;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -50,13 +49,12 @@ public class MariaDbConnectionFactory extends HikariConnectionFactory {
}
@Override
protected void appendProperties(HikariConfig config, StorageCredentials credentials) {
Set<Map.Entry<String, String>> properties = credentials.getProperties().entrySet();
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
if (properties.isEmpty()) {
return;
}
String propertiesString = properties.stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(";"));
String propertiesString = properties.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining(";"));
// kinda hacky. this will call #setProperties on the datasource, which will append these options
// onto the connections.

View File

@ -29,6 +29,7 @@ import com.zaxxer.hikari.HikariConfig;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import java.util.Map;
import java.util.function.Function;
public class MySqlConnectionFactory extends HikariConnectionFactory {
@ -47,20 +48,20 @@ public class MySqlConnectionFactory extends HikariConnectionFactory {
}
@Override
protected void appendProperties(HikariConfig config, StorageCredentials credentials) {
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("alwaysSendSetIsolation", "false");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
properties.putIfAbsent("cachePrepStmts", "true");
properties.putIfAbsent("alwaysSendSetIsolation", "false");
properties.putIfAbsent("cacheServerConfiguration", "true");
properties.putIfAbsent("elideSetAutoCommits", "true");
properties.putIfAbsent("useLocalSessionState", "true");
config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("cacheCallableStmts", "true");
properties.putIfAbsent("useServerPrepStmts", "true");
properties.putIfAbsent("prepStmtCacheSize", "250");
properties.putIfAbsent("prepStmtCacheSqlLimit", "2048");
properties.putIfAbsent("cacheCallableStmts", "true");
// append configurable properties
super.appendProperties(config, credentials);
super.appendProperties(config, properties);
}
@Override

View File

@ -29,6 +29,7 @@ import com.zaxxer.hikari.HikariConfig;
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
import java.util.Map;
import java.util.function.Function;
public class PostgreConnectionFactory extends HikariConnectionFactory {
@ -41,6 +42,15 @@ public class PostgreConnectionFactory extends HikariConnectionFactory {
return "PostgreSQL";
}
@Override
protected void appendProperties(HikariConfig config, Map<String, String> properties) {
// remove the default config properties which don't exist for PostgreSQL
properties.remove("useUnicode");
properties.remove("characterEncoding");
super.appendProperties(config, properties);
}
@Override
protected void appendConfigurationInfo(HikariConfig config) {
String address = this.configuration.getAddress();