Since queries are now allowed, delegated Patch#shouldBeExecuted

This commit is contained in:
Rsl1122 2019-01-30 19:34:47 +02:00
parent 3ab30f8b9f
commit 87d77240fa
4 changed files with 17 additions and 44 deletions

View File

@ -44,13 +44,16 @@ public abstract class Patch extends OperationCriticalTransaction {
protected abstract void applyPatch(); protected abstract void applyPatch();
@Override
protected boolean shouldBeExecuted() {
return !hasBeenApplied();
}
@Override @Override
protected void performOperations() { protected void performOperations() {
// if (!hasBeenApplied()) { TODO Uncomment after moving patches to the execution service
if (dbType == DBType.MYSQL) disableForeignKeyChecks(); if (dbType == DBType.MYSQL) disableForeignKeyChecks();
applyPatch(); applyPatch();
if (dbType == DBType.MYSQL) enableForeignKeyChecks(); if (dbType == DBType.MYSQL) enableForeignKeyChecks();
// }
} }
@Deprecated @Deprecated

View File

@ -23,13 +23,9 @@ import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction;
import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction;
import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.db.access.transactions.Transaction;
import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.db.patches.Patch;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.DatabaseSettings; import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.TestPluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -116,15 +112,9 @@ public class DBPatchH2RegressionTest extends DBPatchRegressionTest {
@Test @Test
public void h2PatchTaskWorksWithoutErrors() { public void h2PatchTaskWorksWithoutErrors() {
PatchTask patchTask = new PatchTask(underTest.patches(), new Locale(), new TestPluginLogger(), new ErrorHandler() { for (Patch patch : underTest.patches()) {
@Override underTest.executeTransaction(patch);
public void log(L l, Class aClass, Throwable throwable) { }
throw new AssertionError(throwable);
}
});
// Patching might fail due to exception.
patchTask.run();
assertPatchesHaveBeenApplied(underTest); assertPatchesHaveBeenApplied(underTest);

View File

@ -24,15 +24,11 @@ import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction;
import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction;
import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.db.access.transactions.Transaction;
import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.db.patches.Patch;
import com.djrapitops.plan.system.PlanSystem; import com.djrapitops.plan.system.PlanSystem;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plan.system.settings.config.PlanConfig; import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.DatabaseSettings; import com.djrapitops.plan.system.settings.paths.DatabaseSettings;
import com.djrapitops.plan.system.settings.paths.WebserverSettings; import com.djrapitops.plan.system.settings.paths.WebserverSettings;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.TestPluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.junit.*; import org.junit.*;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import rules.PluginComponentMocker; import rules.PluginComponentMocker;
@ -144,15 +140,9 @@ public class DBPatchMySQLRegressionTest extends DBPatchRegressionTest {
@Test @Test
public void mysqlPatchTaskWorksWithoutErrors() { public void mysqlPatchTaskWorksWithoutErrors() {
PatchTask patchTask = new PatchTask(underTest.patches(), new Locale(), new TestPluginLogger(), new ErrorHandler() { for (Patch patch : underTest.patches()) {
@Override underTest.executeTransaction(patch);
public void log(L l, Class aClass, Throwable throwable) { }
throw new AssertionError(throwable);
}
});
// Patching might fail due to exception.
patchTask.run();
assertPatchesHaveBeenApplied(underTest); assertPatchesHaveBeenApplied(underTest);

View File

@ -23,11 +23,7 @@ import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction; import com.djrapitops.plan.db.access.transactions.CreateTablesTransaction;
import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction; import com.djrapitops.plan.db.access.transactions.RemoveEverythingTransaction;
import com.djrapitops.plan.db.access.transactions.Transaction; import com.djrapitops.plan.db.access.transactions.Transaction;
import com.djrapitops.plan.db.tasks.PatchTask; import com.djrapitops.plan.db.patches.Patch;
import com.djrapitops.plan.system.locale.Locale;
import com.djrapitops.plugin.logging.L;
import com.djrapitops.plugin.logging.console.TestPluginLogger;
import com.djrapitops.plugin.logging.error.ErrorHandler;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -109,15 +105,9 @@ public class DBPatchSQLiteRegressionTest extends DBPatchRegressionTest {
@Test @Test
public void sqlitePatchTaskWorksWithoutErrors() { public void sqlitePatchTaskWorksWithoutErrors() {
PatchTask patchTask = new PatchTask(underTest.patches(), new Locale(), new TestPluginLogger(), new ErrorHandler() { for (Patch patch : underTest.patches()) {
@Override underTest.executeTransaction(patch);
public void log(L l, Class aClass, Throwable throwable) { }
throw new AssertionError(throwable);
}
});
// Patching might fail due to exception.
patchTask.run();
assertPatchesHaveBeenApplied(underTest); assertPatchesHaveBeenApplied(underTest);