Fixed Backup functionality

This commit is contained in:
Rsl1122 2017-09-03 18:58:31 +03:00
parent 163a694988
commit 9da6ca4642
6 changed files with 32 additions and 13 deletions

View File

@ -83,7 +83,9 @@ public abstract class SQLDB extends Database {
@Override
public void run() {
try {
clean();
if (isOpen()) {
clean();
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
} finally {

View File

@ -210,16 +210,18 @@ public class KillsTable extends UserIDTable {
String[] gms = GMTimes.getGMKeyArray();
for (UUID serverUUID : allSessions.keySet()) {
for (Map.Entry<UUID, List<Session>> entry : allSessions.get(serverUUID).entrySet()) {
UUID uuid = entry.getKey();
UUID killer = entry.getKey();
List<Session> sessions = entry.getValue();
for (Session session : sessions) {
int sessionID = session.getSessionID();
System.out.println(usersTable.getSavedUUIDs());
for (PlayerKill kill : session.getPlayerKills()) {
System.out.println(kill);
UUID victim = kill.getVictim();
long date = kill.getTime();
String weapon = kill.getWeapon();
statement.setString(1, uuid.toString());
statement.setString(1, killer.toString());
statement.setString(2, victim.toString());
statement.setInt(3, sessionID);
statement.setLong(4, date);

View File

@ -557,7 +557,7 @@ public class SessionsTable extends UserIDTable {
String serverUUIDColumn = serverTable + "." + serverTable.getColumnUUID() + " as s_uuid";
statement = prepareStatement("SELECT " +
columnID + ", " +
tableName + "." + columnID + ", " +
columnSessionStart + ", " +
columnSessionEnd + ", " +
columnDeaths + ", " +

View File

@ -348,7 +348,7 @@ public class UsersTable extends UserIDTable {
statement.setFetchSize(5000);
set = statement.executeQuery();
Map<UUID, UserInfo> users = new HashMap<>();
if (set.next()) {
while (set.next()) {
UUID uuid = UUID.fromString(set.getString(columnUUID));
String name = set.getString(columnName);
long registered = set.getLong(columnRegistered);

View File

@ -6,6 +6,7 @@ package main.java.com.djrapitops.plan.database.tables.move;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.api.exceptions.DBCreateTableException;
import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.databases.SQLDB;
import main.java.com.djrapitops.plan.database.tables.ServerTable;
@ -15,6 +16,8 @@ import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* A Fake table used to store a lot of big table operations.
@ -72,9 +75,7 @@ public class BatchOperationTable extends Table {
toDB.removeAllData();
copyServers(toDB);
System.out.println(toDB.getDb().getServerTable().getBukkitServers().toString());
copyUsers(toDB);
System.out.println(toDB.getDb().getSavedUUIDs().toString());
copyWorlds(toDB);
copyTPS(toDB);
copyWebUsers(toDB);
@ -169,7 +170,8 @@ public class BatchOperationTable extends Table {
Log.debug("Batch Copy Users");
UsersTable fromTable = db.getUsersTable();
UsersTable toTable = toDB.getDb().getUsersTable();
toTable.insertUsers(fromTable.getUsers());
Map<UUID, UserInfo> users = fromTable.getUsers();
toTable.insertUsers(users);
toTable.updateKicked(fromTable.getAllTimesKicked());
}

View File

@ -224,11 +224,19 @@ public class DatabaseTest {
}
private void saveUserOne() throws SQLException {
db.getUsersTable().registerUser(uuid, 123456789L, "Test");
saveUserOne(db);
}
private void saveUserOne(Database database) throws SQLException {
database.getUsersTable().registerUser(uuid, 123456789L, "Test");
}
private void saveUserTwo() throws SQLException {
db.getUsersTable().registerUser(uuid2, 123456789L, "Test");
saveUserTwo(db);
}
private void saveUserTwo(Database database) throws SQLException {
database.getUsersTable().registerUser(uuid2, 123456789L, "Test");
}
@Test
@ -325,7 +333,11 @@ public class DatabaseTest {
}
private void saveTwoWorlds() throws SQLException {
db.getWorldTable().saveWorlds(worlds);
saveTwoWorlds(db);
}
private void saveTwoWorlds(Database database) throws SQLException {
database.getWorldTable().saveWorlds(worlds);
}
private WorldTimes createWorldTimes() {
@ -606,10 +618,11 @@ public class DatabaseTest {
TPSTable tpsTable = database.getTpsTable();
SecurityTable securityTable = database.getSecurityTable();
saveUserTwo();
saveUserOne(database);
saveUserTwo(database);
userInfoTable.registerUserInfo(uuid, 223456789L);
saveTwoWorlds();
saveTwoWorlds(database);
Session session = new Session(12345L, "", "");
session.endSession(22345L);