diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java index df9f64c62..5d9bc91ed 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/HikariConnectionFactory.java @@ -89,6 +89,18 @@ public abstract class HikariConnectionFactory implements ConnectionFactory { properties.putIfAbsent("socketTimeout", String.valueOf(TimeUnit.SECONDS.toMillis(30))); } + /** + * Sets the given connection properties onto the config. + * + * @param config the hikari config + * @param properties the properties + */ + protected void setProperties(HikariConfig config, Map properties) { + for (Map.Entry property : properties.entrySet()) { + config.addDataSourceProperty(property.getKey(), property.getValue()); + } + } + @Override public void init(LuckPermsPlugin plugin) { HikariConfig config; @@ -119,9 +131,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory { overrideProperties(properties); // set the properties - for (Map.Entry property : properties.entrySet()) { - config.addDataSourceProperty(property.getKey(), property.getValue()); - } + setProperties(config, properties); // configure the connection pool config.setMaximumPoolSize(this.configuration.getMaxPoolSize()); diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java index be973352f..c80dedb7d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MariaDbConnectionFactory.java @@ -29,7 +29,9 @@ import com.zaxxer.hikari.HikariConfig; import me.lucko.luckperms.common.storage.misc.StorageCredentials; +import java.util.Map; import java.util.function.Function; +import java.util.stream.Collectors; public class MariaDbConnectionFactory extends HikariConnectionFactory { public MariaDbConnectionFactory(StorageCredentials configuration) { @@ -48,12 +50,30 @@ public class MariaDbConnectionFactory extends HikariConnectionFactory { @Override protected void configureDatabase(HikariConfig config, String address, String port, String databaseName, String username, String password) { + config.setDataSourceClassName("org.mariadb.jdbc.MariaDbDataSource"); + config.addDataSourceProperty("serverName", address); + config.addDataSourceProperty("port", port); + config.addDataSourceProperty("databaseName", databaseName); + config.setUsername(username); + config.setPassword(password); + config.setDriverClassName("org.mariadb.jdbc.Driver"); config.setJdbcUrl("jdbc:mariadb://" + address + ":" + port + "/" + databaseName); config.setUsername(username); config.setPassword(password); } + @Override + protected void setProperties(HikariConfig config, Map properties) { + 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. + config.addDataSourceProperty("properties", propertiesString); + } + @Override public Function getStatementProcessor() { return s -> s.replace("'", "`"); // use backticks for quotes diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java index 777141594..e0a410009 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/sql/connection/hikari/MySqlConnectionFactory.java @@ -49,7 +49,8 @@ public class MySqlConnectionFactory extends HikariConnectionFactory { @Override protected void configureDatabase(HikariConfig config, String address, String port, String databaseName, String username, String password) { - config.setDriverClassName("com.mysql.cj.jdbc.Driver"); + // other plugins shouldn't be able to use our driver, so use the non-registering type. + config.setDriverClassName("com.mysql.cj.jdbc.NonRegisteringDriver"); config.setJdbcUrl("jdbc:mysql://" + address + ":" + port + "/" + databaseName); config.setUsername(username); config.setPassword(password);