diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/BackupCopyTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/BackupCopyTransaction.java
new file mode 100644
index 000000000..d1e77f532
--- /dev/null
+++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/BackupCopyTransaction.java
@@ -0,0 +1,105 @@
+/*
+ * This file is part of Player Analytics (Plan).
+ *
+ * Plan is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License v3 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Plan is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Plan. If not, see
- * To use this table create a new BatchOperationTable with both SQLDB objects. - * {@code SQLDB from; SQLDB to;} - * {@code fromT = new BatchOperationTable(from);} - * {@code toT = new BatchOperationTable(to);} - * {@code fromT.copy(toT);} - *
- * The copy methods assume that the table has been cleared, or that no duplicate data will be entered for a user. - *
- * Server and User tables should be copied first. - * - * @author Rsl1122 - */ -public class BatchOperationTable extends Table { - - /** - * Constructor. - *
- * Call to access copy functionality. - * - * @param database Database to copy things from - * @throws IllegalStateException if database.init has not been called. - * @throws ClassCastException if database is not SQLDB. - */ - public BatchOperationTable(SQLDB database) { - super("", database); - if (!db.isOpen()) { - throw new IllegalStateException("Given Database had not been initialized."); - } - } - - public void copyEverything(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.executeTransaction(new RemoveEverythingTransaction()); - - copyServers(toDB); - copyUsers(toDB); - copyWorlds(toDB); - copyTPS(toDB); - copyWebUsers(toDB); - copyCommandUse(toDB); - copyIPsAndGeolocs(toDB); - copyNicknames(toDB); - copySessions(toDB); - copyUserInfo(toDB); - copyPings(toDB); - } - - public void copyPings(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getPingTable().insertAllPings(db.query(LargeFetchQueries.fetchAllPingData())); - } - - public void copyCommandUse(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getCommandUseTable().insertCommandUsage(db.query(LargeFetchQueries.fetchAllCommandUsageData())); - } - - public void copyIPsAndGeolocs(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getGeoInfoTable().insertAllGeoInfo(db.query(LargeFetchQueries.fetchAllGeoInfoData())); - } - - public void copyNicknames(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getNicknamesTable().insertNicknames(db.query(LargeFetchQueries.fetchAllNicknameData())); - } - - public void copyWebUsers(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getSecurityTable().addUsers(db.query(LargeFetchQueries.fetchAllPlanWebUsers())); - } - - public void copyServers(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getServerTable().insertAllServers(db.query(LargeFetchQueries.fetchPlanServerInformation()).values()); - } - - public void copyTPS(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getTpsTable().insertAllTPS(db.query(LargeFetchQueries.fetchAllTPSData())); - } - - public void copyUserInfo(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getUserInfoTable().insertUserInfo(db.query(LargeFetchQueries.fetchPerServerUserInformation())); - } - - public void copyWorlds(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getWorldTable().saveWorlds(db.query(LargeFetchQueries.fetchAllWorldNames())); - } - - public void copyUsers(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - UsersTable fromTable = db.getUsersTable(); - UsersTable toTable = toDB.db.getUsersTable(); - - toTable.insertUsers(db.query(LargeFetchQueries.fetchAllCommonUserInformation())); - toTable.updateKicked(fromTable.getAllTimesKicked()); - } - - public void copySessions(BatchOperationTable toDB) { - if (toDB.equals(this)) { - return; - } - toDB.db.getSessionsTable().insertSessions(db.query(LargeFetchQueries.fetchAllSessionsWithKillAndWorldData()), true); - } -} diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLBackupOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLBackupOps.java index d13d08b8d..c0cb6b67c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLBackupOps.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLBackupOps.java @@ -18,7 +18,7 @@ package com.djrapitops.plan.system.database.databases.sql.operation; import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.SQLDB; -import com.djrapitops.plan.db.sql.tables.move.BatchOperationTable; +import com.djrapitops.plan.db.access.transactions.BackupCopyTransaction; import com.djrapitops.plan.system.database.databases.operation.BackupOperations; public class SQLBackupOps extends SQLOps implements BackupOperations { @@ -29,18 +29,11 @@ public class SQLBackupOps extends SQLOps implements BackupOperations { @Override public void backup(Database toDatabase) { - if (toDatabase instanceof SQLDB) { - BatchOperationTable toDB = new BatchOperationTable((SQLDB) toDatabase); - BatchOperationTable fromDB = new BatchOperationTable(db); - - fromDB.copyEverything(toDB); - } else { - throw new IllegalArgumentException("Database was not a SQL database - backup not implemented."); - } + toDatabase.executeTransaction(new BackupCopyTransaction(db)); } @Override public void restore(Database fromDatabase) { - fromDatabase.backup().backup(db); + db.executeTransaction(new BackupCopyTransaction(fromDatabase)); } }