Bugfixes and code cleanup

Fix batch execution for uuid converter
Fix last update for SQLite
This commit is contained in:
GeorgH93 2018-08-05 21:59:03 +02:00
parent 86ced09103
commit eef444d0bd
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
6 changed files with 20 additions and 24 deletions

View File

@ -112,12 +112,9 @@ private void checkFiles()
} }
} }
} }
else // Use name-based saving else if(len > 16) // Use name-based saving, we only have to rename it if it's name is more than 16 chars (minecraft max player name length)
{ {
if(len > 16) // We only have to rename it if it's name is more than 16 chars (minecraft max player name length) file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + EXT));
{
file.renameTo(new File(saveFolder, UUIDConverter.getNameFromUUID(file.getName().substring(0, len)) + EXT));
}
} }
} }
} }

View File

@ -28,9 +28,9 @@
public class MySQL extends SQL public class MySQL extends SQL
{ {
//TODO add cooldown sync table //TODO add cooldown sync table
public MySQL(Minepacks mp) public MySQL(Minepacks plugin)
{ {
super(mp); // Load Settings super(plugin); // Load Settings
} }
@Override @Override

View File

@ -31,9 +31,9 @@ public class MySQLShared extends MySQL
{ {
private DatabaseConnectionPool pool; private DatabaseConnectionPool pool;
protected MySQLShared(Minepacks minepacks, DatabaseConnectionPool pool) protected MySQLShared(Minepacks plugin, DatabaseConnectionPool pool)
{ {
super(minepacks); super(plugin);
this.pool = pool; this.pool = pool;
} }
@ -44,8 +44,7 @@ protected HikariConfig getPoolConfig()
} }
@Override @Override
@NotNull public @NotNull Connection getConnection() throws SQLException
public Connection getConnection() throws SQLException
{ {
return pool.getConnection(); return pool.getConnection();
} }

View File

@ -35,7 +35,10 @@
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public abstract class SQL extends Database public abstract class SQL extends Database
{ {
@ -47,9 +50,9 @@ public abstract class SQL extends Database
@Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys @Language("SQL") protected String queryDeleteOldCooldowns, querySyncCooldown, queryGetCooldown; // DB Querys
protected boolean updatePlayer, syncCooldown; protected boolean updatePlayer, syncCooldown;
public SQL(Minepacks mp) public SQL(Minepacks plugin)
{ {
super(mp); super(plugin);
HikariConfig poolConfig = getPoolConfig(); HikariConfig poolConfig = getPoolConfig();
if(poolConfig != null) if(poolConfig != null)
@ -178,8 +181,8 @@ public UpdateData(String uuid, int id)
ps.setString(1, updateData.uuid); ps.setString(1, updateData.uuid);
ps.setInt(2, updateData.id); ps.setInt(2, updateData.id);
ps.addBatch(); ps.addBatch();
ps.executeBatch();
} }
ps.executeBatch();
} }
plugin.getLogger().info(String.format(UUIDS_UPDATED, toUpdate.size())); plugin.getLogger().info(String.format(UUIDS_UPDATED, toUpdate.size()));
} }
@ -190,7 +193,7 @@ public UpdateData(String uuid, int id)
} }
} }
protected Connection getConnection() throws SQLException public Connection getConnection() throws SQLException
{ {
return dataSource.getConnection(); return dataSource.getConnection();
} }

View File

@ -33,9 +33,9 @@
public class SQLite extends SQL public class SQLite extends SQL
{ {
//TODO add cooldown sync table //TODO add cooldown sync table
public SQLite(Minepacks mp) public SQLite(Minepacks plugin)
{ {
super(mp); super(plugin);
} }
@Override @Override
@ -84,10 +84,7 @@ protected HikariConfig getPoolConfig()
@Override @Override
protected void updateQuerysForDialect() protected void updateQuerysForDialect()
{ {
if(maxAge > 0) queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", ",{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')");
{
queryInsertBp = queryInsertBp.replaceAll("\\) VALUES \\(\\?,\\?,\\?", "{FieldBPLastUpdate}) VALUES (?,?,?,DATE('now')");
}
queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')"; queryDeleteOldBackpacks = "DELETE FROM {TableBackpacks} WHERE {FieldBPLastUpdate} < DATE('now', '-{VarMaxAge} days')";
queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "DATE('now')"); queryUpdateBp = queryUpdateBp.replaceAll("\\{NOW}", "DATE('now')");
if(useUUIDs) if(useUUIDs)

View File

@ -32,9 +32,9 @@ public class SQLiteShared extends SQLite
{ {
private DatabaseConnectionPool pool; private DatabaseConnectionPool pool;
protected SQLiteShared(Minepacks minepacks, DatabaseConnectionPool pool) protected SQLiteShared(Minepacks plugin, DatabaseConnectionPool pool)
{ {
super(minepacks); super(plugin);
this.pool = pool; this.pool = pool;
} }