Removed Table#createTable()

This commit is contained in:
Rsl1122 2019-01-24 15:34:50 +02:00
parent e75fb76906
commit 0ad7caa0a9
26 changed files with 49 additions and 165 deletions

View File

@ -16,7 +16,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;
@ -41,29 +40,25 @@ public class GeoInfoOptimizationPatch extends Patch {
@Override
protected void applyPatch() {
try {
tempOldTable();
db.getGeoInfoTable().createTable();
tempOldTable();
execute(GeoInfoTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
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), " +
GeoInfoTable.IP + ", " +
GeoInfoTable.IP_HASH + ", " +
GeoInfoTable.LAST_USED + ", " +
GeoInfoTable.GEOLOCATION +
" FROM " + tempTableName
);
execute("INSERT INTO " + tableName + " (" +
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), " +
GeoInfoTable.IP + ", " +
GeoInfoTable.IP_HASH + ", " +
GeoInfoTable.LAST_USED + ", " +
GeoInfoTable.GEOLOCATION +
" FROM " + tempTableName
);
dropTable(tempTableName);
} catch (Exception e) {
throw new DBOpException(GeoInfoOptimizationPatch.class.getSimpleName() + " failed.", e);
}
dropTable(tempTableName);
}
private void tempOldTable() {

View File

@ -16,8 +16,6 @@
*/
package com.djrapitops.plan.db.patches;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement;
@ -114,25 +112,21 @@ public class IPAnonPatch extends Patch {
}
private void groupHashedIPs() {
try {
if (!hasTable(tempTableName)) {
tempOldTable();
}
db.getGeoInfoTable().createTable();
boolean hasUserIdColumn = hasColumn(tempTableName, "user_id");
String identifiers = hasUserIdColumn ? "user_id" : "id, uuid";
execute("INSERT INTO plan_ips (" +
identifiers + ", ip, ip_hash, geolocation, last_used" +
") SELECT " +
identifiers + ", ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, " +
(hasUserIdColumn ? "user_id" : "uuid") +
", ip, geolocation");
dropTable(tempTableName);
} catch (DBInitException e) {
throw new DBOpException(e.getMessage(), e);
if (!hasTable(tempTableName)) {
tempOldTable();
}
execute(GeoInfoTable.createTableSQL(dbType));
boolean hasUserIdColumn = hasColumn(tempTableName, "user_id");
String identifiers = hasUserIdColumn ? "user_id" : "id, uuid";
execute("INSERT INTO plan_ips (" +
identifiers + ", ip, ip_hash, geolocation, last_used" +
") SELECT " +
identifiers + ", ip, ip_hash, geolocation, MAX(last_used) FROM plan_ips_temp GROUP BY ip_hash, " +
(hasUserIdColumn ? "user_id" : "uuid") +
", ip, geolocation");
dropTable(tempTableName);
}
private void tempOldTable() {

View File

@ -46,7 +46,7 @@ public class KillsOptimizationPatch extends Patch {
protected void applyPatch() {
try {
tempOldTable();
db.getKillsTable().createTable();
execute(KillsTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
KillsTable.VICTIM_UUID + ", " +

View File

@ -44,7 +44,7 @@ public class NicknamesOptimizationPatch extends Patch {
protected void applyPatch() {
try {
tempOldTable();
db.getNicknamesTable().createTable();
execute(NicknamesTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
NicknamesTable.USER_UUID + ", " +

View File

@ -44,7 +44,7 @@ public class PingOptimizationPatch extends Patch {
protected void applyPatch() {
try {
tempOldTable();
db.getPingTable().createTable();
execute(PingTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
PingTable.USER_UUID + ", " +

View File

@ -48,7 +48,7 @@ public class SessionsOptimizationPatch extends Patch {
tempOldTable();
db.getSessionsTable().createTable();
execute(SessionsTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
SessionsTable.USER_UUID + ", " +

View File

@ -44,7 +44,7 @@ public class UserInfoOptimizationPatch extends Patch {
protected void applyPatch() {
try {
tempOldTable();
db.getUserInfoTable().createTable();
execute(UserInfoTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
UserInfoTable.USER_UUID + ", " +

View File

@ -59,11 +59,11 @@ public class Version10Patch extends Patch {
copyUsers();
dropTable("plan_ips");
db.getGeoInfoTable().createTable();
execute(GeoInfoTable.createTableSQL(dbType));
dropTable("plan_world_times");
dropTable("plan_worlds");
db.getWorldTable().createTable();
db.getWorldTimesTable().createTable();
execute(WorldTable.createTableSQL(dbType));
execute(WorldTimesTable.createTableSQL(dbType));
dropTable("plan_gamemodetimes");
dropTable("temp_nicks");
@ -73,7 +73,6 @@ public class Version10Patch extends Patch {
private void copyUsers() throws DBInitException {
String tempTableName = "temp_users";
UsersTable usersTable = db.getUsersTable();
renameTable("plan_users", tempTableName);
String tempNickTableName = "temp_nicks";
@ -81,17 +80,15 @@ public class Version10Patch extends Patch {
renameTable(nicknamesTable.toString(), tempNickTableName);
String tempKillsTableName = "temp_kills";
KillsTable killsTable = db.getKillsTable();
renameTable(killsTable.toString(), tempKillsTableName);
renameTable(KillsTable.TABLE_NAME, tempKillsTableName);
usersTable.createTable();
nicknamesTable.createTable();
execute(UsersTable.createTableSQL(dbType));
execute(NicknamesTable.createTableSQL(dbType));
dropTable("plan_sessions");
db.getSessionsTable().createTable();
killsTable.createTable();
execute(SessionsTable.createTableSQL(dbType));
execute(KillsTable.createTableSQL(dbType));
UserInfoTable userInfoTable = db.getUserInfoTable();
userInfoTable.createTable();
execute(UserInfoTable.createTableSQL(dbType));
String statement = "INSERT INTO plan_users " +
"(id, uuid, registered, name)" +
@ -117,11 +114,10 @@ public class Version10Patch extends Patch {
private void copyCommandUsage() throws DBInitException {
String tempTableName = "temp_cmdusg";
CommandUseTable commandUseTable = db.getCommandUseTable();
renameTable("plan_commandusages", tempTableName);
commandUseTable.createTable();
execute(CommandUseTable.createTableSQL(dbType));
String statement = "INSERT INTO plan_commandusages " +
"(command, times_used, server_id)" +
@ -138,7 +134,7 @@ public class Version10Patch extends Patch {
renameTable(tpsTable.toString(), tempTableName);
tpsTable.createTable();
execute(TPSTable.createTableSQL(dbType));
String statement = "INSERT INTO plan_tps " +
"(date, tps, players_online, cpu_usage, ram_usage, entities, chunks_loaded, server_id)" +

View File

@ -45,7 +45,7 @@ public class WorldTimesOptimizationPatch extends Patch {
protected void applyPatch() {
try {
tempOldTable();
db.getWorldTimesTable().createTable();
execute(WorldTimesTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
WorldTimesTable.USER_UUID + ", " +

View File

@ -46,7 +46,7 @@ public class WorldsOptimizationPatch extends Patch {
ensureNoForeignKeyConstraints(tableName);
tempOldTable();
db.getWorldTable().createTable();
execute(WorldTable.createTableSQL(dbType));
execute("INSERT INTO " + tableName + " (" +
WorldTable.ID + ", " +

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement;
@ -72,11 +71,6 @@ public class CommandUseTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
/**
* Used to get all commands used in a server.
*

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.GeoInfo;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
@ -26,7 +25,6 @@ import com.djrapitops.plan.db.patches.*;
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;
@ -85,20 +83,6 @@ public class GeoInfoTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(TableSqlParser.createTable(tableName)
.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<GeoInfo> getGeoInfo(UUID uuid) {
String sql = "SELECT DISTINCT * FROM " + tableName +
" WHERE " + USER_UUID + "=?";

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.PlayerDeath;
import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session;
@ -96,11 +95,6 @@ public class KillsTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public void addKillsToSessions(UUID uuid, Map<Integer, Session> sessions) {
String usersUUIDColumn = usersTable + "." + UsersTable.USER_UUID;
String usersNameColumn = usersTable + "." + UsersTable.USER_NAME + " as victim_name";

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.store.objects.Nickname;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
@ -84,11 +83,6 @@ public class NicknamesTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
/**
* Get nicknames of the user on a server.
*

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.Ping;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
@ -81,11 +80,6 @@ public class PingTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public void clean() {
String sql = "DELETE FROM " + tableName +
" WHERE (" + DATE + "<?)" +

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
@ -67,11 +66,6 @@ public class SecurityTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public void removeUser(String user) {
String sql = "DELETE FROM " + tableName + " WHERE (" + USERNAME + "=?)";

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement;
@ -77,11 +76,6 @@ public class ServerTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
private void updateServerInfo(Server info) {
String sql = Update.values(tableName,
SERVER_UUID,

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.db.DBType;
@ -91,11 +90,6 @@ public class SessionsTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
/**
* Used to get the sessionID of a newly inserted row.
*

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement;
@ -63,11 +62,6 @@ public class SettingsTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
/**
* Place a config in the database for this server.
* <p>

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.container.builders.TPSBuilder;
import com.djrapitops.plan.db.DBType;
@ -95,11 +94,6 @@ public class TPSTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public List<TPS> getTPSData(UUID serverUUID) {
String sql = Select.all(tableName)
.where(SERVER_ID + "=" + serverTable.statementSelectServerID)

View File

@ -51,8 +51,6 @@ public abstract class Table {
this.supportsMySQLQueries = db != null && db.getType().supportsMySQLQueries();
}
public abstract void createTable() throws DBInitException;
protected void createTable(String sql) throws DBInitException {
try {
db.execute(sql);

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
@ -86,11 +85,6 @@ public class UserInfoTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public void registerUserInfo(UUID uuid, long registered) {
execute(new ExecStatement(insertStatement) {
@Override

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.UserInfo;
import com.djrapitops.plan.data.store.Key;
import com.djrapitops.plan.data.store.containers.DataContainer;
@ -73,11 +72,6 @@ public class UsersTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
/**
* @return a {@link Set} of the saved UUIDs.
*/

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.db.DBType;
import com.djrapitops.plan.db.SQLDB;
import com.djrapitops.plan.db.access.ExecStatement;
@ -73,11 +72,6 @@ public class WorldTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public List<String> getWorlds() {
return getWorlds(getServerUUID());
}

View File

@ -16,7 +16,6 @@
*/
package com.djrapitops.plan.db.sql.tables;
import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.keys.SessionKeys;
import com.djrapitops.plan.data.time.GMTimes;
@ -105,11 +104,6 @@ public class WorldTimesTable extends Table {
.toString();
}
@Override
public void createTable() throws DBInitException {
createTable(createTableSQL(db.getType()));
}
public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) {
String worldIDColumn = worldTable + "." + WorldTable.ID;
String worldNameColumn = worldTable + "." + WorldTable.NAME + " as world_name";

View File

@ -57,11 +57,6 @@ public class BatchOperationTable extends Table {
}
}
@Override
public void createTable() {
throw new IllegalStateException("Method not supposed to be used on this table.");
}
public void clearTable(Table table) {
table.removeAllData();
}