From 0f37da566362453e7810cc9f2a719254e7045cc6 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 18 Jan 2019 17:31:39 +0200 Subject: [PATCH] Made ForeignKeyConstraint inner class of MySQLSchemaQueries --- .../com/djrapitops/plan/db/patches/Patch.java | 7 +- .../db/sql/queries/MySQLSchemaQueries.java | 54 +++++++++++++- .../sql/objects/ForeignKeyConstraint.java | 71 ------------------- 3 files changed, 56 insertions(+), 76 deletions(-) delete mode 100644 Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/objects/ForeignKeyConstraint.java diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Patch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Patch.java index 5fafa4836..c50aef5ff 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Patch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/Patch.java @@ -23,7 +23,6 @@ import com.djrapitops.plan.db.access.QueryAllStatement; import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.sql.parsing.TableSqlParser; import com.djrapitops.plan.db.sql.queries.MySQLSchemaQueries; -import com.djrapitops.plan.system.database.databases.sql.objects.ForeignKeyConstraint; import com.djrapitops.plan.system.settings.paths.DatabaseSettings; import com.djrapitops.plugin.utilities.Verify; @@ -169,9 +168,9 @@ public abstract class Patch { } String schema = db.getConfig().get(DatabaseSettings.MYSQL_DATABASE); - List constraints = query(MySQLSchemaQueries.foreignKeyConstraintsOf(schema, referencedTable)); + List constraints = query(MySQLSchemaQueries.foreignKeyConstraintsOf(schema, referencedTable)); - for (ForeignKeyConstraint constraint : constraints) { + for (MySQLSchemaQueries.ForeignKeyConstraint constraint : constraints) { // Uses information from https://stackoverflow.com/a/34574758 db.execute("ALTER TABLE " + constraint.getTable() + " DROP FOREIGN KEY " + constraint.getConstraintName()); @@ -184,7 +183,7 @@ public abstract class Patch { } String schema = db.getConfig().get(DatabaseSettings.MYSQL_DATABASE); - List constraints = query(MySQLSchemaQueries.foreignKeyConstraintsOf(schema, table)); + List constraints = query(MySQLSchemaQueries.foreignKeyConstraintsOf(schema, table)); Verify.isTrue(constraints.isEmpty(), () -> new DBOpException("Table '" + table + "' has constraints '" + constraints + "'")); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/MySQLSchemaQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/MySQLSchemaQueries.java index 540d83fdb..16d2dceff 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/MySQLSchemaQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/MySQLSchemaQueries.java @@ -17,7 +17,6 @@ package com.djrapitops.plan.db.sql.queries; import com.djrapitops.plan.db.access.QueryStatement; -import com.djrapitops.plan.system.database.databases.sql.objects.ForeignKeyConstraint; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -87,4 +86,57 @@ public class MySQLSchemaQueries { }; } + /** + * Represents a FOREIGN KEY constraint in a MySQL database. + * + * @author Rsl1122 + */ + public static class ForeignKeyConstraint { + + private final String table; + private final String referencedTable; + private final String column; + private final String refrencedColumn; + private final String constraintName; + + public ForeignKeyConstraint( + String table, String referencedTable, + String column, String refrencedColumn, + String constraintName + ) { + this.table = table; + this.referencedTable = referencedTable; + this.column = column; + this.refrencedColumn = refrencedColumn; + this.constraintName = constraintName; + } + + public String getTable() { + return table; + } + + public String getReferencedTable() { + return referencedTable; + } + + public String getColumn() { + return column; + } + + public String getRefrencedColumn() { + return refrencedColumn; + } + + public String getConstraintName() { + return constraintName; + } + + @Override + public String toString() { + return "FK '" + constraintName + "' " + + table + "." + column + + " references " + + referencedTable + "." + refrencedColumn; + } + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/objects/ForeignKeyConstraint.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/objects/ForeignKeyConstraint.java deleted file mode 100644 index 0917cadff..000000000 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/objects/ForeignKeyConstraint.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 . - */ -package com.djrapitops.plan.system.database.databases.sql.objects; - -/** - * Represents a FOREIGN KEY constraint in a MySQL database. - * - * @author Rsl1122 - */ -public class ForeignKeyConstraint { - - private final String table; - private final String referencedTable; - private final String column; - private final String refrencedColumn; - private final String constraintName; - - public ForeignKeyConstraint( - String table, String referencedTable, - String column, String refrencedColumn, - String constraintName - ) { - this.table = table; - this.referencedTable = referencedTable; - this.column = column; - this.refrencedColumn = refrencedColumn; - this.constraintName = constraintName; - } - - public String getTable() { - return table; - } - - public String getReferencedTable() { - return referencedTable; - } - - public String getColumn() { - return column; - } - - public String getRefrencedColumn() { - return refrencedColumn; - } - - public String getConstraintName() { - return constraintName; - } - - @Override - public String toString() { - return "FK '" + constraintName + "' " + - table + "." + column + - " references " + - referencedTable + "." + refrencedColumn; - } -}