Update to V1.15

Add config option for max MySQL connections
Bugfix for SQLite when used with UUIDs
This commit is contained in:
GeorgH93 2016-03-06 20:29:12 +01:00
parent d7aeac4feb
commit 271da25236
6 changed files with 49 additions and 16 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId> <groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId> <artifactId>MinePacks</artifactId>
<version>1.14</version> <version>1.15</version>
<scm> <scm>
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection> <connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>

View File

@ -55,6 +55,8 @@ Database:
Database: minecraft Database: minecraft
User: minecraft User: minecraft
Password: minecraft Password: minecraft
#The max amount of connections to the database the connection pool will open
MaxConnections: 4
# Tables settings for shared tables when using MySQL - Advanced MySQL Settings # Tables settings for shared tables when using MySQL - Advanced MySQL Settings
# Use these settings only if you know what you are doing!!!! # 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 knowlage!!! # Do only change this settings if you know what you are doing and have some basic MySQL knowlage!!!
@ -82,4 +84,4 @@ Database:
auto-update: true auto-update: true
# Config file version. Don't touch it! # Config file version. Don't touch it!
Version: 9 Version: 10

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2014-2015 GeorgH93 * Copyright (C) 2014-2016 GeorgH93
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -27,11 +27,11 @@
public class Config extends Configuration public class Config extends Configuration
{ {
private static final int CONFIG_VERSION = 9; private static final int CONFIG_VERSION = 10;
public Config(JavaPlugin plugin) public Config(JavaPlugin plugin)
{ {
super(plugin, CONFIG_VERSION, 9); super(plugin, CONFIG_VERSION, 10);
} }
@Override @Override
@ -108,6 +108,11 @@ public String getMySQLPassword()
return config.getString("Database.MySQL.Password", ""); return config.getString("Database.MySQL.Password", "");
} }
public int getMySQLMaxConnections()
{
return config.getInt("Database.MySQL.MaxConnections", 4);
}
public String getUserTable() public String getUserTable()
{ {
return config.getString("Database.Tables.User", "backpack_players"); return config.getString("Database.Tables.User", "backpack_players");

View File

@ -41,7 +41,7 @@ protected HikariConfig getPoolConfig()
poolConfig.setUsername(plugin.config.getMySQLUser()); poolConfig.setUsername(plugin.config.getMySQLUser());
poolConfig.setPassword(plugin.config.getMySQLPassword()); poolConfig.setPassword(plugin.config.getMySQLPassword());
poolConfig.setMinimumIdle(1); poolConfig.setMinimumIdle(1);
poolConfig.setMaximumPoolSize(8); poolConfig.setMaximumPoolSize(plugin.config.getMySQLMaxConnections());
return poolConfig; return poolConfig;
} }

View File

@ -203,7 +203,7 @@ protected final void buildQuerys()
protected abstract void updateQuerysForDialect(); protected abstract void updateQuerysForDialect();
private void runStatementAsync(final String query, final Object... args) protected void runStatementAsync(final String query, final Object... args)
{ {
Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable()
{ {
@ -215,7 +215,7 @@ public void run()
}); });
} }
private void runStatement(final String query, final Object... args) protected void runStatement(final String query, final Object... args)
{ {
try(Connection connection = getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query)) try(Connection connection = getConnection(); PreparedStatement preparedStatement = connection.prepareStatement(query))
{ {

View File

@ -21,6 +21,9 @@
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -79,33 +82,36 @@ protected void updateQuerysForDialect()
} }
Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')"; Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')";
Query_UpdateBP = Query_UpdateBP.replaceAll("\\{NOW\\}", "DATE('now')"); Query_UpdateBP = Query_UpdateBP.replaceAll("\\{NOW\\}", "DATE('now')");
if(useUUIDs)
{
Query_UpdatePlayerAdd = "INSERT OR IGNORE INTO `{TablePlayers}` (`{FieldName}`,`{FieldUUID}`) VALUES (?,?);";
}
else
{
Query_UpdatePlayerAdd = Query_UpdatePlayerAdd.replaceAll("INSERT IGNORE INTO", "INSERT OR IGNORE INTO"); Query_UpdatePlayerAdd = Query_UpdatePlayerAdd.replaceAll("INSERT IGNORE INTO", "INSERT OR IGNORE INTO");
} }
}
@Override @Override
protected void checkDB() protected void checkDB()
{ {
try(Connection connection = getConnection(); Statement stmt = connection.createStatement()) try(Connection connection = getConnection(); Statement stmt = connection.createStatement())
{ {
stmt.execute("CREATE TABLE IF NOT EXISTS `backpack_players` (`player_id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` CHAR(16) NOT NULL UNIQUE" + ((useUUIDs) ? ", `uuid` CHAR(32) UNIQUE" : "") + ");"); stmt.execute("CREATE TABLE IF NOT EXISTS `backpack_players` (`player_id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` CHAR(16) NOT NULL" + ((useUUIDs) ? " , `uuid` CHAR(32) UNIQUE" : " UNIQUE") + ");");
if(useUUIDs) if(useUUIDs)
{ {
try try
{ {
stmt.execute("ALTER TABLE `backpack_players` ADD COLUMN `uuid` CHAR(32);"); stmt.execute("ALTER TABLE `backpack_players` ADD COLUMN `uuid` CHAR(32);");
} }
catch(SQLException ignored) catch(SQLException ignored) {}
{
}
} }
stmt.execute("CREATE TABLE IF NOT EXISTS `backpacks` (`owner` INT UNSIGNED PRIMARY KEY, `itemstacks` BLOB, `version` INT DEFAULT 0);"); stmt.execute("CREATE TABLE IF NOT EXISTS `backpacks` (`owner` INT UNSIGNED PRIMARY KEY, `itemstacks` BLOB, `version` INT DEFAULT 0);");
try try
{ {
stmt.execute("ALTER TABLE `backpacks` ADD COLUMN `version` INT DEFAULT 0;"); stmt.execute("ALTER TABLE `backpacks` ADD COLUMN `version` INT DEFAULT 0;");
} }
catch(SQLException ignored) catch(SQLException ignored) {}
{
}
if(maxAge > 0) if(maxAge > 0)
{ {
try try
@ -124,4 +130,24 @@ protected void checkDB()
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override
public void updatePlayer(final Player player)
{
if(useUUIDs)
{
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run()
{
runStatement(Query_UpdatePlayerAdd, player.getName(), getPlayerFormattedUUID(player));
runStatement("UPDATE `" + Table_Players + "` SET `" + Field_Name + "`=? WHERE `" + Field_UUID + "`=?;", player.getName(), getPlayerFormattedUUID(player));
}
});
}
else
{
runStatementAsync(Query_UpdatePlayerAdd, player.getName());
}
}
} }