Add option to set SQL connection properties, e.g. disable SSL

This commit is contained in:
GeorgH93 2017-06-09 02:32:10 +02:00
parent 58de4fec7d
commit 167a204c2a
4 changed files with 21 additions and 5 deletions

View File

@ -60,8 +60,11 @@ Database:
Database: minecraft
User: minecraft
Password: minecraft
#The max amount of connections to the database the connection pool will open
# The max amount of connections to the database the connection pool will open
MaxConnections: 2
# List of properties for your SQL connection. Can be used to disable SSL.
# Properties: ["useSSL=false"]
Properties: []
# Tables settings for shared tables when using MySQL - Advanced MySQL Settings
# Use these settings only if you know what you are doing!!!!
# Do only change this settings if you know what you are doing and have some basic MySQL knowledge!!!

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 GeorgH93
* Copyright (C) 2016, 2017 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -110,7 +110,19 @@ public String getSQLPassword()
public int getSQLMaxConnections()
{
return config.getInt("Database.SQL.MaxConnections", 4);
return config.getInt("Database.SQL.MaxConnections", 2);
}
public String getSQLProperties()
{
List<String> list = config.getStringList("Database.MySQL.Properties", null);
StringBuilder str = new StringBuilder();
if(list == null) return "";
for(String s : list)
{
str.append("&").append(s);
}
return str.toString();
}
public String getUserTable()

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2016 GeorgH93
* Copyright (C) 2016, 2017 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -37,7 +37,7 @@ public MySQL(Minepacks mp)
protected HikariConfig getPoolConfig()
{
HikariConfig poolConfig = new HikariConfig();
poolConfig.setJdbcUrl("jdbc:mysql://" + plugin.config.getSQLHost() + "/" + plugin.config.getSQLDatabase() + "?allowMultiQueries=true&autoReconnect=true");
poolConfig.setJdbcUrl("jdbc:mysql://" + plugin.config.getSQLHost() + "/" + plugin.config.getSQLDatabase() + "?allowMultiQueries=true&autoReconnect=true" + plugin.config.getSQLProperties());
poolConfig.setUsername(plugin.config.getSQLUser());
poolConfig.setPassword(plugin.config.getSQLPassword());
poolConfig.setMinimumIdle(1);

View File

@ -54,6 +54,7 @@ public SQL(Minepacks mp)
if(poolConfig != null)
{
poolConfig.setPoolName("Minepacks-Connection-Pool");
poolConfig.addDataSourceProperty("cachePrepStmts", "true");
dataSource = new HikariDataSource(poolConfig);
}