mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 20:17:55 +01:00
Use the non-registering MySQL driver and revert to using DataSource for MariaDB
This commit is contained in:
parent
129a10aa60
commit
9af6dccd9d
@ -89,6 +89,18 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
|
|||||||
properties.putIfAbsent("socketTimeout", String.valueOf(TimeUnit.SECONDS.toMillis(30)));
|
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<String, String> properties) {
|
||||||
|
for (Map.Entry<String, String> property : properties.entrySet()) {
|
||||||
|
config.addDataSourceProperty(property.getKey(), property.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(LuckPermsPlugin plugin) {
|
public void init(LuckPermsPlugin plugin) {
|
||||||
HikariConfig config;
|
HikariConfig config;
|
||||||
@ -119,9 +131,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
|
|||||||
overrideProperties(properties);
|
overrideProperties(properties);
|
||||||
|
|
||||||
// set the properties
|
// set the properties
|
||||||
for (Map.Entry<String, String> property : properties.entrySet()) {
|
setProperties(config, properties);
|
||||||
config.addDataSourceProperty(property.getKey(), property.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure the connection pool
|
// configure the connection pool
|
||||||
config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
|
config.setMaximumPoolSize(this.configuration.getMaxPoolSize());
|
||||||
|
@ -29,7 +29,9 @@ import com.zaxxer.hikari.HikariConfig;
|
|||||||
|
|
||||||
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
|
import me.lucko.luckperms.common.storage.misc.StorageCredentials;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class MariaDbConnectionFactory extends HikariConnectionFactory {
|
public class MariaDbConnectionFactory extends HikariConnectionFactory {
|
||||||
public MariaDbConnectionFactory(StorageCredentials configuration) {
|
public MariaDbConnectionFactory(StorageCredentials configuration) {
|
||||||
@ -48,12 +50,30 @@ public class MariaDbConnectionFactory extends HikariConnectionFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureDatabase(HikariConfig config, String address, String port, String databaseName, String username, String password) {
|
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.setDriverClassName("org.mariadb.jdbc.Driver");
|
||||||
config.setJdbcUrl("jdbc:mariadb://" + address + ":" + port + "/" + databaseName);
|
config.setJdbcUrl("jdbc:mariadb://" + address + ":" + port + "/" + databaseName);
|
||||||
config.setUsername(username);
|
config.setUsername(username);
|
||||||
config.setPassword(password);
|
config.setPassword(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setProperties(HikariConfig config, Map<String, String> 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
|
@Override
|
||||||
public Function<String, String> getStatementProcessor() {
|
public Function<String, String> getStatementProcessor() {
|
||||||
return s -> s.replace("'", "`"); // use backticks for quotes
|
return s -> s.replace("'", "`"); // use backticks for quotes
|
||||||
|
@ -49,7 +49,8 @@ public class MySqlConnectionFactory extends HikariConnectionFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureDatabase(HikariConfig config, String address, String port, String databaseName, String username, String password) {
|
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.setJdbcUrl("jdbc:mysql://" + address + ":" + port + "/" + databaseName);
|
||||||
config.setUsername(username);
|
config.setUsername(username);
|
||||||
config.setPassword(password);
|
config.setPassword(password);
|
||||||
|
Loading…
Reference in New Issue
Block a user