Fix shading settings

Cleanup
Chance MySQL table validation code
This commit is contained in:
GeorgH93 2018-04-27 20:58:13 +02:00
parent 2f72293b04
commit 1a6c664719
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 17 additions and 55 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>MinePacks</artifactId>
<version>1.17.7</version>
<version>1.17.8-SNAPSHOT</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
@ -117,6 +117,8 @@
<shadedPattern>at.pcgamingfreaks.MinePacks.libs.at.pcgamingfreaks</shadedPattern>
<excludes>
<exclude>at.pcgamingfreaks.MinePacks.*</exclude>
<exclude>at.pcgamingfreaks.MinePacks.Database.*</exclude>
<exclude>at.pcgamingfreaks.MinePacks.Updater.*</exclude>
</excludes>
</relocation>
<relocation>

View File

@ -17,6 +17,7 @@
package at.pcgamingfreaks.MinePacks.Database;
import at.pcgamingfreaks.Database.DBTools;
import at.pcgamingfreaks.MinePacks.MinePacks;
import com.zaxxer.hikari.HikariConfig;
@ -49,7 +50,7 @@ protected HikariConfig getPoolConfig()
protected void updateQuerysForDialect()
{
queryDeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` + INTERVAL {VarMaxAge} day < NOW()";
queryUpdateBP = queryUpdateBP.replaceAll("\\{NOW\\}", "NOW()");
queryUpdateBP = queryUpdateBP.replaceAll("\\{NOW}", "NOW()");
}
@Override
@ -57,58 +58,16 @@ protected void checkDB()
{
try(Connection connection = getConnection(); Statement stmt = connection.createStatement())
{
ResultSet res;
if(useUUIDs)
{
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL,`" + fieldUUID + "` CHAR(36) UNIQUE, PRIMARY KEY (`" + fieldPlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldUUID + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + tablePlayers + "` ADD COLUMN `" + fieldUUID + "` CHAR(36) UNIQUE;");
}
res.close();
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldName + "' AND COLUMN_KEY='UNI';");
if(res.next())
{
stmt.execute("ALTER TABLE `" + tablePlayers + "` DROP INDEX `" + fieldName + "_UNIQUE`;");
}
res.close();
if(useUUIDSeparators)
{
res = stmt.executeQuery("SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldUUID + "';");
if(res.next() && res.getInt(1) < 36)
{
stmt.execute("ALTER TABLE `" + tablePlayers + "` MODIFY `" + fieldUUID + "` CHAR(36) UNIQUE;");
}
res.close();
}
DBTools.updateDB(connection, "CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL,`" + fieldUUID + "` CHAR(36) UNIQUE, PRIMARY KEY (`" + fieldPlayerID + "`));");
}
else
{
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL, PRIMARY KEY (`" + fieldPlayerID + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tablePlayers + "' AND COLUMN_NAME = '" + fieldName + "' AND COLUMN_KEY='UNI';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + tablePlayers + "` ADD UNIQUE INDEX `" + fieldName + "_UNIQUE` (`" + fieldName + "` ASC);");
DBTools.updateDB(connection, "CREATE TABLE IF NOT EXISTS `" + tablePlayers + "` (`" + fieldPlayerID + "` INT UNSIGNED NOT NULL AUTO_INCREMENT,`" + fieldName + "` CHAR(16) NOT NULL UNIQUE, PRIMARY KEY (`" + fieldPlayerID + "`));");
}
res.close();
}
stmt.execute("CREATE TABLE IF NOT EXISTS `" + tableBackpacks + "` (`" + fieldBPOwner + "` INT UNSIGNED NOT NULL, `" + fieldBPITS + "` BLOB, `"
DBTools.updateDB(connection, "CREATE TABLE IF NOT EXISTS `" + tableBackpacks + "` (`" + fieldBPOwner + "` INT UNSIGNED NOT NULL, `" + fieldBPITS + "` BLOB, `"
+ fieldBPVersion + "` INT DEFAULT 0, " + ((maxAge > 0) ? "`" + fieldBPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " : "") + "PRIMARY KEY (`" + fieldBPOwner + "`));");
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tableBackpacks + "' AND COLUMN_NAME = '" + fieldBPVersion + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + tableBackpacks + "` ADD COLUMN `" + fieldBPVersion + "` INT DEFAULT 0;");
}
if(maxAge > 0)
{
res = stmt.executeQuery("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" + tableBackpacks + "' AND COLUMN_NAME = '" + fieldBPLastUpdate + "';");
if(!res.next())
{
stmt.execute("ALTER TABLE `" + tableBackpacks + "` ADD COLUMN `" + fieldBPLastUpdate + "` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;");
}
res.close();
}
}
catch (SQLException e)
{

View File

@ -208,14 +208,15 @@ protected final void buildQuerys()
updateQuerysForDialect();
// Replace the table and filed names with the names from the config
queryUpdatePlayerAdd = queryUpdatePlayerAdd.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryGetPlayerID = queryGetPlayerID.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryGetBP = queryGetBP.replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID);
queryInsertBP = queryInsertBP.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate);
queryUpdateBP = queryUpdateBP.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPOwner\\}", fieldBPOwner).replaceAll("\\{FieldBPITS\\}", fieldBPITS).replaceAll("\\{FieldBPVersion\\}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate);
queryDeleteOldBackpacks = queryDeleteOldBackpacks.replaceAll("\\{TableBackpacks\\}", tableBackpacks).replaceAll("\\{FieldBPLastUpdate\\}", fieldBPLastUpdate).replaceAll("\\{VarMaxAge\\}", maxAge + "");
queryGetUnsetOrInvalidUUIDs = queryGetUnsetOrInvalidUUIDs.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldName\\}", fieldName).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryFixUUIDs = queryFixUUIDs.replaceAll("\\{TablePlayers\\}", tablePlayers).replaceAll("\\{FieldUUID\\}", fieldUUID).replaceAll("\\{FieldPlayerID\\}", fieldPlayerID);
queryUpdatePlayerAdd = queryUpdatePlayerAdd.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldName}", fieldName).replaceAll("\\{FieldUUID}", fieldUUID).replaceAll("\\{FieldPlayerID}", fieldPlayerID);
queryGetPlayerID = queryGetPlayerID.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldName}", fieldName).replaceAll("\\{FieldUUID}", fieldUUID).replaceAll("\\{FieldPlayerID}", fieldPlayerID);
queryGetBP = queryGetBP.replaceAll("\\{FieldBPOwner}", fieldBPOwner).replaceAll("\\{FieldBPITS}", fieldBPITS).replaceAll("\\{FieldBPVersion}", fieldBPVersion).replaceAll("\\{TableBackpacks}", tableBackpacks)
.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldPlayerID}", fieldPlayerID).replaceAll("\\{FieldName}", fieldName).replaceAll("\\{FieldUUID}", fieldUUID);
queryInsertBP = queryInsertBP.replaceAll("\\{TableBackpacks}", tableBackpacks).replaceAll("\\{FieldBPOwner}", fieldBPOwner).replaceAll("\\{FieldBPITS}", fieldBPITS).replaceAll("\\{FieldBPVersion}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate}", fieldBPLastUpdate);
queryUpdateBP = queryUpdateBP.replaceAll("\\{TableBackpacks}", tableBackpacks).replaceAll("\\{FieldBPOwner}", fieldBPOwner).replaceAll("\\{FieldBPITS}", fieldBPITS).replaceAll("\\{FieldBPVersion}", fieldBPVersion).replaceAll("\\{FieldBPLastUpdate}", fieldBPLastUpdate);
queryDeleteOldBackpacks = queryDeleteOldBackpacks.replaceAll("\\{TableBackpacks}", tableBackpacks).replaceAll("\\{FieldBPLastUpdate}", fieldBPLastUpdate).replaceAll("\\{VarMaxAge}", maxAge + "");
queryGetUnsetOrInvalidUUIDs = queryGetUnsetOrInvalidUUIDs.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldName}", fieldName).replaceAll("\\{FieldUUID}", fieldUUID).replaceAll("\\{FieldPlayerID}", fieldPlayerID);
queryFixUUIDs = queryFixUUIDs.replaceAll("\\{TablePlayers}", tablePlayers).replaceAll("\\{FieldUUID}", fieldUUID).replaceAll("\\{FieldPlayerID}", fieldPlayerID);
}
protected abstract void updateQuerysForDialect();