DB Formatting

This commit is contained in:
Rsl1122 2017-08-23 12:31:34 +03:00
parent 3c8d8bc8a8
commit 75d1a3e88c
4 changed files with 36 additions and 16 deletions

View File

@ -27,6 +27,11 @@ public abstract class Database {
*/
protected UsersTable usersTable;
/**
* Table representing plan_actions in the database.
*/
protected ActionsTable actionsTable;
/**
* Table representing plan_kills in the database.
*/

View File

@ -37,16 +37,19 @@ public abstract class SQLDB extends Database {
this.supportsModification = supportsModification;
usingMySQL = getName().equals("MySQL");
versionTable = new VersionTable(this, usingMySQL);
serverTable = new ServerTable(this, usingMySQL);
securityTable = new SecurityTable(this, usingMySQL);
commandUseTable = new CommandUseTable(this, usingMySQL);
tpsTable = new TPSTable(this, usingMySQL);
usersTable = new UsersTable(this, usingMySQL);
sessionsTable = new SessionsTable(this, usingMySQL);
killsTable = new KillsTable(this, usingMySQL);
actionsTable = new ActionsTable(this, usingMySQL);
ipsTable = new IPsTable(this, usingMySQL);
nicknamesTable = new NicknamesTable(this, usingMySQL);
commandUseTable = new CommandUseTable(this, usingMySQL);
versionTable = new VersionTable(this, usingMySQL);
tpsTable = new TPSTable(this, usingMySQL);
securityTable = new SecurityTable(this, usingMySQL);
sessionsTable = new SessionsTable(this, usingMySQL);
killsTable = new KillsTable(this, usingMySQL);
worldTable = new WorldTable(this, usingMySQL);
worldTimesTable = new WorldTimesTable(this, usingMySQL);
@ -185,19 +188,23 @@ public abstract class SQLDB extends Database {
return new Table[]{
serverTable, usersTable, ipsTable,
nicknamesTable, sessionsTable, killsTable,
commandUseTable, tpsTable, worldTable,
worldTimesTable, securityTable};
commandUseTable, actionsTable, tpsTable,
worldTable, worldTimesTable, securityTable
};
}
/**
* @return
* Get all tables except securityTable for removal of user data.
*
* @return Tables in the order the data should be removed in.
*/
public Table[] getAllTablesInRemoveOrder() {
return new Table[]{
ipsTable,
nicknamesTable, killsTable, worldTimesTable,
sessionsTable, worldTable, usersTable,
commandUseTable, tpsTable, serverTable};
ipsTable, nicknamesTable, killsTable,
worldTimesTable, sessionsTable, actionsTable,
worldTable, usersTable, commandUseTable,
tpsTable, serverTable
};
}
/**

View File

@ -40,8 +40,8 @@ public class ActionsTable extends UserIDTable {
private final String columnActionID = "action_id";
private final String columnAdditionalInfo = "additional_info";
public ActionsTable(String name, SQLDB db, boolean usingMySQL) {
super(name, db, usingMySQL);
public ActionsTable(SQLDB db, boolean usingMySQL) {
super("plan_actions", db, usingMySQL);
}
@Override

View File

@ -20,7 +20,7 @@ import java.util.UUID;
* Table class representing database table plan_world_times.
*
* @author Rsl1122
* @since 3.6.0 / Database version 7
* @since 4.0.0
*/
public class WorldTimesTable extends UserIDTable {
@ -77,6 +77,7 @@ public class WorldTimesTable extends UserIDTable {
if (Verify.isEmpty(worldTimes.getWorldTimes())) {
return;
}
PreparedStatement statement = null;
try {
statement = prepareStatement("INSERT INTO " + tableName + " (" +
@ -91,6 +92,7 @@ public class WorldTimesTable extends UserIDTable {
usersTable.statementSelectID + ", " +
worldTable.statementSelectID + ", " +
"?, ?, ?, ?, ?)");
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
String worldName = entry.getKey();
GMTimes gmTimes = entry.getValue();
@ -105,6 +107,7 @@ public class WorldTimesTable extends UserIDTable {
statement.setLong(7, gmTimes.getTime(gms[3]));
statement.addBatch();
}
statement.executeBatch();
} finally {
close(statement);
@ -131,19 +134,24 @@ public class WorldTimesTable extends UserIDTable {
statement.setString(1, uuid.toString());
set = statement.executeQuery();
String[] gms = GMTimes.getGMKeyArray();
while (set.next()) {
long sessionID = set.getLong(columnSessionID);
Session session = sessions.get(sessionID);
if (session == null) {
continue;
}
String worldName = set.getString("world_name");
Map<String, Long> gmMap = new HashMap<>();
gmMap.put(gms[0], set.getLong(columnSurvival));
gmMap.put(gms[1], set.getLong(columnCreative));
gmMap.put(gms[2], set.getLong(columnAdventure));
gmMap.put(gms[3], set.getLong(columnSpectator));
GMTimes gmTimes = new GMTimes(gmMap);
session.getWorldTimes().setGMTimesForWorld(worldName, gmTimes);
}
} finally {