diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoLastUsedPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoLastUsedPatch.java index 93adf4a47..23a475615 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoLastUsedPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoLastUsedPatch.java @@ -27,13 +27,13 @@ public class GeoInfoLastUsedPatch extends Patch { @Override public boolean hasBeenApplied() { - return hasColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.Col.LAST_USED.get()); + return hasColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.LAST_USED); } @Override protected void applyPatch() { addColumn(GeoInfoTable.TABLE_NAME, - GeoInfoTable.Col.LAST_USED + " bigint NOT NULL DEFAULT 0" + GeoInfoTable.LAST_USED + " bigint NOT NULL DEFAULT 0" ); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoOptimizationPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoOptimizationPatch.java index 6fc3f2130..45f4090c5 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoOptimizationPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/GeoInfoOptimizationPatch.java @@ -19,7 +19,6 @@ package com.djrapitops.plan.db.patches; import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.sql.tables.GeoInfoTable; -import com.djrapitops.plan.db.sql.tables.GeoInfoTable.Col; public class GeoInfoOptimizationPatch extends Patch { @@ -34,8 +33,8 @@ public class GeoInfoOptimizationPatch extends Patch { @Override public boolean hasBeenApplied() { - return hasColumn(tableName, Col.ID.get()) - && hasColumn(tableName, Col.UUID.get()) + return hasColumn(tableName, GeoInfoTable.ID) + && hasColumn(tableName, GeoInfoTable.USER_UUID) && !hasColumn(tableName, "user_id") && !hasTable(tempTableName); // If this table exists the patch has failed to finish. } @@ -47,17 +46,17 @@ public class GeoInfoOptimizationPatch extends Patch { db.getGeoInfoTable().createTable(); execute("INSERT INTO " + tableName + " (" + - Col.UUID + ", " + - Col.IP + ", " + - Col.IP_HASH + ", " + - Col.LAST_USED + ", " + - Col.GEOLOCATION + + GeoInfoTable.USER_UUID + ", " + + GeoInfoTable.IP + ", " + + GeoInfoTable.IP_HASH + ", " + + GeoInfoTable.LAST_USED + ", " + + GeoInfoTable.GEOLOCATION + ") SELECT " + "(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " + - Col.IP + ", " + - Col.IP_HASH + ", " + - Col.LAST_USED + ", " + - Col.GEOLOCATION + + GeoInfoTable.IP + ", " + + GeoInfoTable.IP_HASH + ", " + + GeoInfoTable.LAST_USED + ", " + + GeoInfoTable.GEOLOCATION + " FROM " + tempTableName ); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java index 85f71e518..5979c895c 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java @@ -53,7 +53,7 @@ public class IPAnonPatch extends Patch { private Boolean containsUnAnonymizedIPs() { String sql = "SELECT * FROM " + tableName + - " WHERE " + GeoInfoTable.Col.IP + " NOT LIKE ? LIMIT 1"; + " WHERE " + GeoInfoTable.IP + " NOT LIKE ? LIMIT 1"; return query(new QueryStatement(sql) { @Override @@ -77,9 +77,9 @@ public class IPAnonPatch extends Patch { private void anonymizeIPs(Map> allGeoInfo) { String sql = "UPDATE " + GeoInfoTable.TABLE_NAME + " SET " + - GeoInfoTable.Col.IP + "=?, " + - GeoInfoTable.Col.IP_HASH + "=? " + - "WHERE " + GeoInfoTable.Col.IP + "=?"; + GeoInfoTable.IP + "=?, " + + GeoInfoTable.IP_HASH + "=? " + + "WHERE " + GeoInfoTable.IP + "=?"; executeBatch(new ExecStatement(sql) { @Override diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPHashPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPHashPatch.java index bea271f25..e54503796 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPHashPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPHashPatch.java @@ -27,11 +27,11 @@ public class IPHashPatch extends Patch { @Override public boolean hasBeenApplied() { - return hasColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.Col.IP_HASH.get()); + return hasColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.IP_HASH); } @Override protected void applyPatch() { - addColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.Col.IP_HASH.get() + " varchar(200) DEFAULT ''"); + addColumn(GeoInfoTable.TABLE_NAME, GeoInfoTable.IP_HASH + " varchar(200) DEFAULT ''"); } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java index 431eb56a4..5fdf83397 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java @@ -23,7 +23,10 @@ import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.patches.*; -import com.djrapitops.plan.db.sql.parsing.*; +import com.djrapitops.plan.db.sql.parsing.CreateTableParser; +import com.djrapitops.plan.db.sql.parsing.Select; +import com.djrapitops.plan.db.sql.parsing.Sql; +import com.djrapitops.plan.db.sql.parsing.TableSqlParser; import com.djrapitops.plan.db.sql.queries.LargeFetchQueries; import com.djrapitops.plan.utilities.comparators.GeoInfoComparator; import com.djrapitops.plugin.utilities.Verify; @@ -61,11 +64,11 @@ public class GeoInfoTable extends UserUUIDTable { public GeoInfoTable(SQLDB db) { super(TABLE_NAME, db); insertStatement = "INSERT INTO " + tableName + " (" - + Col.UUID + ", " - + Col.IP + ", " - + Col.IP_HASH + ", " - + Col.GEOLOCATION + ", " - + Col.LAST_USED + + USER_UUID + ", " + + IP + ", " + + IP_HASH + ", " + + GEOLOCATION + ", " + + LAST_USED + ") VALUES (?, ?, ?, ?, ?)"; } @@ -85,20 +88,20 @@ public class GeoInfoTable extends UserUUIDTable { @Override public void createTable() throws DBInitException { createTable(TableSqlParser.createTable(tableName) - .primaryKeyIDColumn(supportsMySQLQueries, Col.ID) - .column(Col.UUID, Sql.varchar(36)).notNull() - .column(Col.IP, Sql.varchar(39)).notNull() - .column(Col.GEOLOCATION, Sql.varchar(50)).notNull() - .column(Col.IP_HASH, Sql.varchar(200)) - .column(Col.LAST_USED, Sql.LONG).notNull().defaultValue("0") - .primaryKey(supportsMySQLQueries, Col.ID) + .primaryKeyIDColumn(supportsMySQLQueries, ID) + .column(USER_UUID, Sql.varchar(36)).notNull() + .column(IP, Sql.varchar(39)).notNull() + .column(GEOLOCATION, Sql.varchar(50)).notNull() + .column(IP_HASH, Sql.varchar(200)) + .column(LAST_USED, Sql.LONG).notNull().defaultValue("0") + .primaryKey(supportsMySQLQueries, ID) .toString() ); } public List getGeoInfo(UUID uuid) { String sql = "SELECT DISTINCT * FROM " + tableName + - " WHERE " + Col.UUID + "=?"; + " WHERE " + USER_UUID + "=?"; return query(new QueryStatement>(sql, 100) { @Override @@ -110,10 +113,10 @@ public class GeoInfoTable extends UserUUIDTable { public List processResults(ResultSet set) throws SQLException { List geoInfo = new ArrayList<>(); while (set.next()) { - String ip = set.getString(Col.IP.get()); - String geolocation = set.getString(Col.GEOLOCATION.get()); - String ipHash = set.getString(Col.IP_HASH.get()); - long lastUsed = set.getLong(Col.LAST_USED.get()); + String ip = set.getString(IP); + String geolocation = set.getString(GEOLOCATION); + String ipHash = set.getString(IP_HASH); + long lastUsed = set.getLong(LAST_USED); geoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash)); } return geoInfo; @@ -123,10 +126,10 @@ public class GeoInfoTable extends UserUUIDTable { private void updateGeoInfo(UUID uuid, GeoInfo info) { String sql = "UPDATE " + tableName + " SET " - + Col.LAST_USED + "=?" + - " WHERE " + Col.UUID + "=?" + - " AND " + Col.IP_HASH + "=?" + - " AND " + Col.GEOLOCATION + "=?"; + + LAST_USED + "=?" + + " WHERE " + USER_UUID + "=?" + + " AND " + IP_HASH + "=?" + + " AND " + GEOLOCATION + "=?"; execute(new ExecStatement(sql) { @Override @@ -162,8 +165,8 @@ public class GeoInfoTable extends UserUUIDTable { } public Optional getGeolocation(String ip) { - String sql = Select.from(tableName, Col.GEOLOCATION) - .where(Col.IP + "=?") + String sql = Select.from(tableName, GEOLOCATION) + .where(IP + "=?") .toString(); return query(new QueryStatement>(sql) { @@ -175,7 +178,7 @@ public class GeoInfoTable extends UserUUIDTable { @Override public Optional processResults(ResultSet set) throws SQLException { if (set.next()) { - return Optional.of(set.getString(Col.GEOLOCATION.get())); + return Optional.of(set.getString(GEOLOCATION)); } return Optional.empty(); } @@ -226,36 +229,4 @@ public class GeoInfoTable extends UserUUIDTable { } }); } - - @Deprecated - public enum Col implements Column { - @Deprecated - ID("id"), - @Deprecated - UUID(UserUUIDTable.Col.UUID.get()), - @Deprecated - IP("ip"), - @Deprecated - IP_HASH("ip_hash"), - @Deprecated - GEOLOCATION("geolocation"), - @Deprecated - LAST_USED("last_used"); - - private final String column; - - Col(String column) { - this.column = column; - } - - @Override - public String get() { - return toString(); - } - - @Override - public String toString() { - return column; - } - } }