Batch Operations copyEverything method

This commit is contained in:
Rsl1122 2017-09-03 11:46:46 +03:00
parent 01e65d2214
commit 02c86b75bb
3 changed files with 35 additions and 4 deletions

View File

@ -23,6 +23,7 @@ import java.util.UUID;
public abstract class SQLDB extends Database {
private final boolean usingMySQL;
private boolean open = false;
/**
* @param plugin
@ -68,6 +69,7 @@ public abstract class SQLDB extends Database {
setupDataSource();
setupDatabase();
scheduleClean(10L);
open = true;
} finally {
Benchmark.stop("Database", benchName);
Log.logDebug("Database");
@ -173,6 +175,7 @@ public abstract class SQLDB extends Database {
public void close() throws SQLException {
dataSource.close();
setStatus("Closed");
open = false;
Log.logDebug("Database"); // Log remaining Debug info if present
}
@ -307,4 +310,8 @@ public abstract class SQLDB extends Database {
public void endTransaction(Connection connection) throws SQLException {
connection.close();
}
public boolean isOpen() {
return open;
}
}

View File

@ -128,6 +128,7 @@ public class WorldTimesTable extends UserIDTable {
" JOIN " + worldTable + " on " + worldIDColumn + "=" + columnWorldId +
" WHERE " + columnUserID + "=" + usersTable.statementSelectID
);
statement.setFetchSize(2000);
statement.setString(1, uuid.toString());
set = statement.executeQuery();
String[] gms = GMTimes.getGMKeyArray();

View File

@ -12,9 +12,7 @@ import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
/**
* A Fake table used to store a lot of big table operations.
@ -35,8 +33,19 @@ import java.util.UUID;
* @since 4.0.0
*/
public class BatchOperationTable extends Table {
/**
* Constructor, call to access copy functionality.
*
* @param db
* @param usingMySQL
* @throws IllegalStateException if db.init has not been called.
*/
public BatchOperationTable(SQLDB db, boolean usingMySQL) {
super("", db, usingMySQL);
if (!db.isOpen()) {
throw new IllegalStateException("Given Database had not been initialized.");
}
}
@Override
@ -48,8 +57,22 @@ public class BatchOperationTable extends Table {
table.removeAllData();
}
public void clearTable(Collection<UUID> uuids, Table table) {
// TODO
public void copyEverything(BatchOperationTable toDB) throws SQLException {
if (toDB.equals(this)) {
return;
}
toDB.db.removeAllData();
copyServers(toDB);
copyUsers(toDB);
copyWorlds(toDB);
copyUserInfo(toDB);
copyActions(toDB);
copyCommandUse(toDB);
copyIPsAndGeolocs(toDB);
copyNicknames(toDB);
copyTPS(toDB);
copyWebUsers(toDB);
// TODO WorldTimes, Sessions, PlayerKills
}
public void copyActions(BatchOperationTable toDB) throws SQLException {