From 167a204c2ad0c5eefa87d54fbf65e94feba7320a Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Fri, 9 Jun 2017 02:32:10 +0200 Subject: [PATCH] Add option to set SQL connection properties, e.g. disable SSL --- resources/config.yml | 5 ++++- .../Minepacks/Bukkit/Database/Config.java | 16 ++++++++++++++-- .../Minepacks/Bukkit/Database/MySQL.java | 4 ++-- .../Minepacks/Bukkit/Database/SQL.java | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/resources/config.yml b/resources/config.yml index e591756..5493be7 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -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!!! diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index b3e44c5..9ca5af4 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -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 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() diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java index 73f6653..8b228e1 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java @@ -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); diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java index c61014d..77ff587 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java @@ -54,6 +54,7 @@ public SQL(Minepacks mp) if(poolConfig != null) { poolConfig.setPoolName("Minepacks-Connection-Pool"); + poolConfig.addDataSourceProperty("cachePrepStmts", "true"); dataSource = new HikariDataSource(poolConfig); }