From 405d4f643bfa36c71800323d8307dfbec8e64367 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 18 Mar 2019 19:56:16 +0200 Subject: [PATCH] Extension table create table statements --- .../init/CreateTablesTransaction.java | 7 ++++++ .../db/sql/tables/ExtensionIconTable.java | 14 +++++++++++ ...es.java => ExtensionPlayerValueTable.java} | 21 +++++++++++++++- .../db/sql/tables/ExtensionPluginTable.java | 15 ++++++++++++ .../db/sql/tables/ExtensionProviderTable.java | 24 +++++++++++++++++++ .../plan/db/sql/tables/ExtensionTabTable.java | 18 ++++++++++++++ .../RemoveInvalidResultsTransaction.java | 6 ++--- .../StorePlayerBooleanResultTransaction.java | 2 +- .../StorePlayerDoubleResultTransaction.java | 2 +- .../StorePlayerNumberResultTransaction.java | 2 +- ...torePlayerPercentageResultTransaction.java | 2 +- .../StorePlayerStringResultTransaction.java | 2 +- 12 files changed, 106 insertions(+), 9 deletions(-) rename Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/{ExtensionPlayerValues.java => ExtensionPlayerValueTable.java} (61%) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/init/CreateTablesTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/init/CreateTablesTransaction.java index 63c3bdd72..01f1dc2b3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/init/CreateTablesTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/transactions/init/CreateTablesTransaction.java @@ -45,5 +45,12 @@ public class CreateTablesTransaction extends OperationCriticalTransaction { execute(WorldTimesTable.createTableSQL(dbType)); execute(SecurityTable.createTableSQL(dbType)); execute(SettingsTable.createTableSQL(dbType)); + + // DataExtension tables + execute(ExtensionIconTable.createTableSQL(dbType)); + execute(ExtensionPluginTable.createTableSQL(dbType)); + execute(ExtensionTabTable.createTableSQL(dbType)); + execute(ExtensionProviderTable.createTableSQL(dbType)); + execute(ExtensionPlayerValueTable.createTableSQL(dbType)); } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionIconTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionIconTable.java index a64955ad3..b59544e12 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionIconTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionIconTable.java @@ -16,6 +16,11 @@ */ package com.djrapitops.plan.db.sql.tables; +import com.djrapitops.plan.db.DBType; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Sql; +import com.djrapitops.plan.extension.icon.Color; +import com.djrapitops.plan.extension.icon.Family; import com.djrapitops.plan.extension.icon.Icon; import java.sql.PreparedStatement; @@ -52,4 +57,13 @@ public class ExtensionIconTable { statement.setString(parameterIndex + 1, icon.getFamily().name()); statement.setString(parameterIndex + 2, icon.getColor().name()); } + + public static String createTableSQL(DBType dbType) { + return CreateTableParser.create(TABLE_NAME, dbType) + .column(ID, INT).primaryKey() + .column(ICON_NAME, Sql.varchar(50)).notNull().defaultValue("'question'") + .column(FAMILY, Sql.varchar(15)).notNull().defaultValue(Family.SOLID.name()) + .column(COLOR, Sql.varchar(25)).notNull().defaultValue(Color.NONE.name()) + .build(); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValues.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValueTable.java similarity index 61% rename from Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValues.java rename to Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValueTable.java index 309161d9e..c237582ce 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValues.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPlayerValueTable.java @@ -16,12 +16,16 @@ */ package com.djrapitops.plan.db.sql.tables; +import com.djrapitops.plan.db.DBType; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Sql; + /** * Table information about 'plan_extension_user_values'. * * @author Rsl1122 */ -public class ExtensionPlayerValues { +public class ExtensionPlayerValueTable { public static final String TABLE_NAME = "plan_extension_user_values"; @@ -36,4 +40,19 @@ public class ExtensionPlayerValues { public static final String STRING_VALUE = "string_value"; public static final String GROUP_VALUE = "group_value"; + public static String createTableSQL(DBType dbType) { + return CreateTableParser.create(TABLE_NAME, dbType) + .column(ID, Sql.INT).primaryKey() + .column(BOOLEAN_VALUE, Sql.BOOL) + .column(DOUBLE_VALUE, Sql.DOUBLE) + .column(PERCENTAGE_VALUE, Sql.DOUBLE) + .column(LONG_VALUE, Sql.LONG) + .column(STRING_VALUE, Sql.varchar(50)) + .column(GROUP_VALUE, Sql.varchar(50)) + .column(USER_UUID, Sql.varchar(36)).notNull() + .column(PROVIDER_ID, Sql.INT).notNull() + .foreignKey(PROVIDER_ID, ExtensionProviderTable.TABLE_NAME, ExtensionProviderTable.ID) + .build(); + } + } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPluginTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPluginTable.java index 3701136d2..030828bc2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPluginTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionPluginTable.java @@ -16,6 +16,10 @@ */ package com.djrapitops.plan.db.sql.tables; +import com.djrapitops.plan.db.DBType; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Sql; + import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.UUID; @@ -46,4 +50,15 @@ public class ExtensionPluginTable { statement.setString(parameterIndex, pluginName); statement.setString(parameterIndex + 1, serverUUID.toString()); } + + public static String createTableSQL(DBType dbType) { + return CreateTableParser.create(TABLE_NAME, dbType) + .column(ID, INT).primaryKey() + .column(PLUGIN_NAME, Sql.varchar(50)).notNull() + .column(LAST_UPDATED, LONG).notNull() + .column(SERVER_UUID, Sql.varchar(36)).notNull() + .column(ICON_ID, INT).notNull() + .foreignKey(ICON_ID, ExtensionIconTable.TABLE_NAME, ExtensionIconTable.ID) + .build(); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionProviderTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionProviderTable.java index 06e23ca8c..ea86b2825 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionProviderTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionProviderTable.java @@ -16,6 +16,10 @@ */ package com.djrapitops.plan.db.sql.tables; +import com.djrapitops.plan.db.DBType; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Sql; + import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.UUID; @@ -55,4 +59,24 @@ public class ExtensionProviderTable { ExtensionPluginTable.set2PluginValuesToStatement(statement, parameterIndex + 1, pluginName, serverUUID); } + public static String createTableSQL(DBType dbType) { + return CreateTableParser.create(TABLE_NAME, dbType) + .column(ID, INT).primaryKey() + .column(PROVIDER_NAME, Sql.varchar(50)).notNull() + .column(TEXT, Sql.varchar(50)).notNull() + .column(DESCRIPTION, Sql.varchar(150)) + .column(PRIORITY, INT).notNull().defaultValue("0") + .column(GROUPABLE, BOOL).notNull().defaultValue(false) + .column(CONDITION, Sql.varchar(50)) + .column(PROVIDED_CONDITION, Sql.varchar(50)) + .column(FORMAT_TYPE, Sql.varchar(25)) + .column(IS_PLAYER_NAME, BOOL).notNull().defaultValue(false) + .column(PLUGIN_ID, INT).notNull() + .column(ICON_ID, INT).notNull() + .column(TAB_ID, INT).notNull() + .foreignKey(PLUGIN_ID, ExtensionPluginTable.TABLE_NAME, ExtensionPluginTable.ID) + .foreignKey(ICON_ID, ExtensionIconTable.TABLE_NAME, ExtensionIconTable.ID) + .foreignKey(TAB_ID, ExtensionTabTable.TABLE_NAME, ExtensionTabTable.ID) + .build(); + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionTabTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionTabTable.java index e4de6439b..6bcef7a77 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionTabTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/ExtensionTabTable.java @@ -16,6 +16,11 @@ */ package com.djrapitops.plan.db.sql.tables; +import com.djrapitops.plan.db.DBType; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Sql; +import com.djrapitops.plan.extension.ElementOrder; + import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.UUID; @@ -47,4 +52,17 @@ public class ExtensionTabTable { statement.setString(parameterIndex, tabName); ExtensionPluginTable.set2PluginValuesToStatement(statement, parameterIndex + 1, pluginName, serverUUID); } + + public static String createTableSQL(DBType dbType) { + return CreateTableParser.create(TABLE_NAME, dbType) + .column(ID, INT).primaryKey() + .column(TAB_NAME, Sql.varchar(50)).notNull() + .column(ELEMENT_ORDER, Sql.varchar(100)).notNull().defaultValue("'" + ElementOrder.serialize(ElementOrder.values()) + "'") + .column(TAB_PRIORITY, INT).notNull() + .column(PLUGIN_ID, INT).notNull() + .column(ICON_ID, INT).notNull() + .foreignKey(PLUGIN_ID, ExtensionPluginTable.TABLE_NAME, ExtensionPluginTable.ID) + .foreignKey(ICON_ID, ExtensionIconTable.TABLE_NAME, ExtensionIconTable.ID) + .build(); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/RemoveInvalidResultsTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/RemoveInvalidResultsTransaction.java index 023771d08..dc0aa5613 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/RemoveInvalidResultsTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/RemoveInvalidResultsTransaction.java @@ -19,7 +19,7 @@ package com.djrapitops.plan.extension.implementation.storage.transactions.result import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.Executable; import com.djrapitops.plan.db.access.transactions.Transaction; -import com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues; +import com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable; import com.djrapitops.plan.db.sql.tables.ExtensionPluginTable; import com.djrapitops.plan.db.sql.tables.ExtensionProviderTable; @@ -57,8 +57,8 @@ public class RemoveInvalidResultsTransaction extends Transaction { } private Executable deleteInvalidMethodResults(String invalidMethod) { - String sql = "DELETE FROM " + ExtensionPlayerValues.TABLE_NAME + - WHERE + ExtensionPlayerValues.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID; + String sql = "DELETE FROM " + ExtensionPlayerValueTable.TABLE_NAME + + WHERE + ExtensionPlayerValueTable.PROVIDER_ID + "=" + ExtensionProviderTable.STATEMENT_SELECT_PROVIDER_ID; return new ExecStatement(sql) { @Override public void prepare(PreparedStatement statement) throws SQLException { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerBooleanResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerBooleanResultTransaction.java index 89de8091a..fa02e7cca 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerBooleanResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerBooleanResultTransaction.java @@ -27,7 +27,7 @@ import java.util.UUID; import static com.djrapitops.plan.db.sql.parsing.Sql.AND; import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE; -import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues.*; +import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable.*; /** * Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.BooleanDataProvider}. diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerDoubleResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerDoubleResultTransaction.java index 8de0b579c..64e13a084 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerDoubleResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerDoubleResultTransaction.java @@ -27,7 +27,7 @@ import java.util.UUID; import static com.djrapitops.plan.db.sql.parsing.Sql.AND; import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE; -import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues.*; +import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable.*; /** * Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.DoubleDataProvider}. diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerNumberResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerNumberResultTransaction.java index 0bd597c9e..b80a348dd 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerNumberResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerNumberResultTransaction.java @@ -27,7 +27,7 @@ import java.util.UUID; import static com.djrapitops.plan.db.sql.parsing.Sql.AND; import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE; -import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues.*; +import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable.*; /** * Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.NumberDataProvider}. diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerPercentageResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerPercentageResultTransaction.java index 5e624d0dc..7a4cae6fa 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerPercentageResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerPercentageResultTransaction.java @@ -27,7 +27,7 @@ import java.util.UUID; import static com.djrapitops.plan.db.sql.parsing.Sql.AND; import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE; -import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues.*; +import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable.*; /** * Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.PercentageDataProvider}. diff --git a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerStringResultTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerStringResultTransaction.java index 83b4667cf..140b44e1d 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerStringResultTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/extension/implementation/storage/transactions/results/StorePlayerStringResultTransaction.java @@ -27,7 +27,7 @@ import java.util.UUID; import static com.djrapitops.plan.db.sql.parsing.Sql.AND; import static com.djrapitops.plan.db.sql.parsing.Sql.WHERE; -import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValues.*; +import static com.djrapitops.plan.db.sql.tables.ExtensionPlayerValueTable.*; /** * Transaction to store method result of a {@link com.djrapitops.plan.extension.implementation.providers.StringDataProvider}.