mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 03:57:33 +01:00
Merge branch '3.7.0' of https://github.com/Rsl1122/Plan-PlayerAnalytics
This commit is contained in:
commit
c615d9f9a2
12
Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java
Normal file
12
Plan/src/main/java/com/djrapitops/plan/database/sql/Sql.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package main.java.com.djrapitops.plan.database.sql;
|
||||||
|
|
||||||
|
public class Sql {
|
||||||
|
public static final String INT = "integer";
|
||||||
|
public static final String DOUBLE = "double";
|
||||||
|
public static final String LONG = "bigint";
|
||||||
|
public static final String BOOL = "boolean";
|
||||||
|
|
||||||
|
public static String VARCHAR(int length) {
|
||||||
|
return "varchar("+length+")";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package main.java.com.djrapitops.plan.database.sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for parsing different SQL strings.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
* @since 3.7.0
|
||||||
|
*/
|
||||||
|
public class SqlParser {
|
||||||
|
|
||||||
|
private StringBuilder s;
|
||||||
|
|
||||||
|
public SqlParser() {
|
||||||
|
s = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlParser(String start) {
|
||||||
|
s = new StringBuilder(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlParser addSpace() {
|
||||||
|
s.append(" ");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlParser append(String string) {
|
||||||
|
s.append(string);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return s.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package main.java.com.djrapitops.plan.database.sql;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SqlParser Class for parsing table creation, removal & modification statements.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
* @since 3.7.0
|
||||||
|
*/
|
||||||
|
public class TableSqlParser extends SqlParser {
|
||||||
|
|
||||||
|
private int columns = 0;
|
||||||
|
|
||||||
|
public TableSqlParser(String start) {
|
||||||
|
super(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TableSqlParser createTable(String tableName) {
|
||||||
|
return new TableSqlParser("CREATE TABLE IF NOT EXISTS " + tableName + " (");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dropTable(String tableName) {
|
||||||
|
return "DROP TABLE IF EXISTS " + tableName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser column(String column, String type) {
|
||||||
|
if (columns > 0) {
|
||||||
|
append(", ");
|
||||||
|
}
|
||||||
|
append(column).addSpace();
|
||||||
|
append(type);
|
||||||
|
|
||||||
|
columns++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public TableSqlParser foreignKey(String column, String refrencedTable, String referencedColumn) {
|
||||||
|
if (columns > 0) {
|
||||||
|
append(", ");
|
||||||
|
}
|
||||||
|
append("FOREIGN KEY(")
|
||||||
|
.append(column)
|
||||||
|
.append(") REFERENCES ")
|
||||||
|
.append(refrencedTable)
|
||||||
|
.append("(")
|
||||||
|
.append(referencedColumn)
|
||||||
|
.append(")");
|
||||||
|
columns++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser notNull() {
|
||||||
|
addSpace();
|
||||||
|
append("NOT NULL");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser unique() {
|
||||||
|
addSpace();
|
||||||
|
append("UNIQUE");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser defaultValue(boolean value) {
|
||||||
|
return defaultValue(value ? "1" : "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser defaultValue(String value) {
|
||||||
|
addSpace();
|
||||||
|
append("DEFAULT ").append(value);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser primaryKeyIDColumn(boolean mySQL, String column, String type) {
|
||||||
|
if (columns > 0) {
|
||||||
|
append(", ");
|
||||||
|
}
|
||||||
|
append(column).addSpace();
|
||||||
|
append(type).addSpace();
|
||||||
|
append((mySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY");
|
||||||
|
columns++;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TableSqlParser primaryKey(boolean mySQL, String column) {
|
||||||
|
if (mySQL) {
|
||||||
|
if (columns > 0) {
|
||||||
|
append(", ");
|
||||||
|
}
|
||||||
|
append("PRIMARY KEY (").append(column).append(")");
|
||||||
|
columns++;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
append(")");
|
||||||
|
return super.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -35,10 +37,10 @@ public class CommandUseTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnCommand + " varchar(20) NOT NULL, "
|
.column(columnCommand, Sql.VARCHAR(20)).notNull()
|
||||||
+ columnTimesUsed + " integer NOT NULL"
|
.column(columnTimesUsed, Sql.INT).notNull()
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -6,6 +6,8 @@ import main.java.com.djrapitops.plan.data.time.GMTimes;
|
|||||||
import main.java.com.djrapitops.plan.database.Container;
|
import main.java.com.djrapitops.plan.database.Container;
|
||||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -52,14 +54,14 @@ public class GMTimesTable extends UserIDTable {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUserID + " integer NOT NULL, "
|
.column(columnUserID, Sql.INT).notNull()
|
||||||
+ columnSurvivalTime + " bigint NOT NULL, "
|
.column(columnSurvivalTime, Sql.LONG).notNull()
|
||||||
+ columnCreativeTime + " bigint NOT NULL, "
|
.column(columnCreativeTime, Sql.LONG).notNull()
|
||||||
+ columnAdventureTime + " bigint NOT NULL, "
|
.column(columnAdventureTime, Sql.LONG).notNull()
|
||||||
+ columnSpectatorTime + " bigint NOT NULL, "
|
.column(columnSpectatorTime, Sql.LONG).notNull()
|
||||||
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
|
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@ -36,11 +38,11 @@ public class IPsTable extends UserIDTable {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUserID + " integer NOT NULL, "
|
.column(columnUserID, Sql.INT).notNull()
|
||||||
+ columnIP + " varchar(20) NOT NULL, "
|
.column(columnIP, Sql.VARCHAR(20)).notNull()
|
||||||
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
|
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -4,6 +4,8 @@ import com.djrapitops.plugin.utilities.Verify;
|
|||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.data.KillData;
|
import main.java.com.djrapitops.plan.data.KillData;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -40,14 +42,14 @@ public class KillsTable extends Table {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnKillerUserID + " integer NOT NULL, "
|
.column(columnKillerUserID, Sql.INT).notNull()
|
||||||
+ columnVictimUserID + " integer NOT NULL, "
|
.column(columnVictimUserID, Sql.INT).notNull()
|
||||||
+ columnWeapon + " varchar(30) NOT NULL, "
|
.column(columnWeapon, Sql.VARCHAR(30)).notNull()
|
||||||
+ columnDate + " bigint NOT NULL, "
|
.column(columnDate, Sql.LONG).notNull()
|
||||||
+ "FOREIGN KEY(" + columnKillerUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + "), "
|
.foreignKey(columnKillerUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ "FOREIGN KEY(" + columnVictimUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
|
.foreignKey(columnVictimUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -36,12 +38,12 @@ public class NicknamesTable extends UserIDTable {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUserID + " integer NOT NULL, "
|
.column(columnUserID, Sql.INT).notNull()
|
||||||
+ columnNick + " varchar(75) NOT NULL, "
|
.column(columnNick, Sql.VARCHAR(75)).notNull()
|
||||||
+ columnCurrent + " boolean NOT NULL DEFAULT 0, "
|
.column(columnCurrent, Sql.BOOL).notNull().defaultValue(false)
|
||||||
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
|
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (getVersion() < 3) {
|
if (getVersion() < 3) {
|
||||||
|
@ -8,6 +8,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.data.WebUser;
|
import main.java.com.djrapitops.plan.data.WebUser;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -34,10 +36,11 @@ public class SecurityTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUser + " varchar(100) NOT NULL UNIQUE, "
|
.column(columnUser, Sql.VARCHAR(100)).notNull().unique()
|
||||||
+ columnSaltedHash + " varchar(100) NOT NULL UNIQUE, "
|
.column(columnSaltedHash, Sql.VARCHAR(100)).notNull().unique()
|
||||||
+ columnPermLevel + " integer NOT NULL)"
|
.column(columnPermLevel, Sql.INT).notNull()
|
||||||
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -4,6 +4,8 @@ import main.java.com.djrapitops.plan.Log;
|
|||||||
import main.java.com.djrapitops.plan.data.SessionData;
|
import main.java.com.djrapitops.plan.data.SessionData;
|
||||||
import main.java.com.djrapitops.plan.database.Container;
|
import main.java.com.djrapitops.plan.database.Container;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -37,12 +39,12 @@ public class SessionsTable extends UserIDTable {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUserID + " integer NOT NULL, "
|
.column(columnUserID, Sql.INT).notNull()
|
||||||
+ columnSessionStart + " bigint NOT NULL, "
|
.column(columnSessionStart, Sql.LONG).notNull()
|
||||||
+ columnSessionEnd + " bigint NOT NULL, "
|
.column(columnSessionEnd, Sql.LONG).notNull()
|
||||||
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + ")"
|
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -5,6 +5,8 @@ import main.java.com.djrapitops.plan.Log;
|
|||||||
import main.java.com.djrapitops.plan.data.TPS;
|
import main.java.com.djrapitops.plan.data.TPS;
|
||||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||||
|
|
||||||
@ -48,15 +50,15 @@ public class TPSTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnDate + " bigint NOT NULL, "
|
.column(columnDate, Sql.LONG).notNull()
|
||||||
+ columnTPS + " double NOT NULL, "
|
.column(columnTPS, Sql.DOUBLE).notNull()
|
||||||
+ columnPlayers + " integer NOT NULL, "
|
.column(columnPlayers, Sql.INT).notNull()
|
||||||
+ columnCPUUsage + " double NOT NULL, "
|
.column(columnCPUUsage, Sql.DOUBLE).notNull()
|
||||||
+ columnRAMUsage + " bigint NOT NULL, "
|
.column(columnRAMUsage, Sql.LONG).notNull()
|
||||||
+ columnEntities + " integer NOT NULL, "
|
.column(columnEntities, Sql.INT).notNull()
|
||||||
+ columnChunksLoaded + " integer NOT NULL"
|
.column(columnChunksLoaded, Sql.INT).notNull()
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
int version = getVersion();
|
int version = getVersion();
|
||||||
if (version < 6) {
|
if (version < 6) {
|
||||||
|
@ -8,6 +8,8 @@ import main.java.com.djrapitops.plan.data.time.GMTimes;
|
|||||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
import main.java.com.djrapitops.plan.database.DBUtils;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||||
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
import main.java.com.djrapitops.plan.utilities.uuid.UUIDUtility;
|
||||||
|
|
||||||
@ -95,26 +97,26 @@ public class UsersTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnID + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
|
.primaryKeyIDColumn(usingMySQL, columnID, Sql.INT)
|
||||||
+ columnUUID + " varchar(36) NOT NULL UNIQUE, "
|
.column(columnUUID, Sql.VARCHAR(36)).notNull().unique()
|
||||||
+ columnGeolocation + " varchar(50) NOT NULL, "
|
.column(columnGeolocation, Sql.VARCHAR(50)).notNull()
|
||||||
+ columnLastGM + " varchar(15) NOT NULL, "
|
.column(columnLastGM, Sql.VARCHAR(15)).notNull()
|
||||||
+ columnLastGMSwapTime + " bigint NOT NULL, "
|
.column(columnLastGMSwapTime, Sql.LONG).notNull()
|
||||||
+ columnPlayTime + " bigint NOT NULL, "
|
.column(columnPlayTime, Sql.LONG).notNull()
|
||||||
+ columnLoginTimes + " integer NOT NULL, "
|
.column(columnLoginTimes, Sql.INT).notNull()
|
||||||
+ columnLastPlayed + " bigint NOT NULL, "
|
.column(columnLastPlayed, Sql.LONG).notNull()
|
||||||
+ columnDeaths + " int NOT NULL, "
|
.column(columnDeaths, Sql.INT).notNull()
|
||||||
+ columnMobKills + " int NOT NULL, "
|
.column(columnMobKills, Sql.INT).notNull()
|
||||||
+ columnRegistered + " bigint NOT NULL, "
|
.column(columnRegistered, Sql.LONG).notNull()
|
||||||
+ columnOP + " boolean NOT NULL DEFAULT 0, "
|
.column(columnOP, Sql.BOOL).notNull().defaultValue(false)
|
||||||
+ columnName + " varchar(16) NOT NULL, "
|
.column(columnName, Sql.VARCHAR(16)).notNull()
|
||||||
+ columnBanned + " boolean NOT NULL DEFAULT 0, "
|
.column(columnBanned, Sql.BOOL).notNull().defaultValue(false)
|
||||||
+ columnContainsBukkitData + " boolean NOT NULL DEFAULT 0, "
|
.column(columnContainsBukkitData, Sql.BOOL).notNull().defaultValue(false)
|
||||||
+ columnLastWorld + " varchar(255) NOT NULL, "
|
.column(columnLastWorld, Sql.VARCHAR(255)).notNull()
|
||||||
+ columnLastWorldSwapTime + " bigint NOT NULL"
|
.column(columnLastWorldSwapTime, Sql.LONG).notNull()
|
||||||
+ (usingMySQL ? ", PRIMARY KEY (" + columnID + ")" : "")
|
.primaryKey(usingMySQL, columnID)
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
int version = getVersion();
|
int version = getVersion();
|
||||||
if (version < 3) {
|
if (version < 3) {
|
||||||
|
@ -2,6 +2,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
|
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -26,9 +28,9 @@ public class VersionTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ "version integer NOT NULL"
|
.column("version", Sql.INT).notNull()
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -39,11 +41,11 @@ public class WorldTable extends Table {
|
|||||||
@Override
|
@Override
|
||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnWorldId + " integer " + ((usingMySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY") + ", "
|
.primaryKeyIDColumn(usingMySQL, columnWorldId, Sql.INT)
|
||||||
+ columnWorldName + " varchar(100) NOT NULL"
|
.column(columnWorldName, Sql.VARCHAR(100)).notNull()
|
||||||
+ (usingMySQL ? ", PRIMARY KEY (" + columnWorldId + ")" : "")
|
.primaryKey(usingMySQL, columnWorldId)
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
@ -3,6 +3,8 @@ package main.java.com.djrapitops.plan.database.tables;
|
|||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
import main.java.com.djrapitops.plan.Log;
|
||||||
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
import main.java.com.djrapitops.plan.database.databases.SQLDB;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.Sql;
|
||||||
|
import main.java.com.djrapitops.plan.database.sql.TableSqlParser;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@ -50,13 +52,13 @@ public class WorldTimesTable extends UserIDTable {
|
|||||||
public boolean createTable() {
|
public boolean createTable() {
|
||||||
UsersTable usersTable = db.getUsersTable();
|
UsersTable usersTable = db.getUsersTable();
|
||||||
try {
|
try {
|
||||||
execute("CREATE TABLE IF NOT EXISTS " + tableName + " ("
|
execute(TableSqlParser.createTable(tableName)
|
||||||
+ columnUserID + " integer NOT NULL, "
|
.column(columnUserID, Sql.INT).notNull()
|
||||||
+ columnWorldId + " integer NOT NULL, "
|
.column(columnWorldId, Sql.INT).notNull()
|
||||||
+ columnPlaytime + " bigint NOT NULL, "
|
.column(columnPlaytime, Sql.LONG).notNull()
|
||||||
+ "FOREIGN KEY(" + columnUserID + ") REFERENCES " + usersTable.getTableName() + "(" + usersTable.getColumnID() + "), "
|
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||||
+ "FOREIGN KEY(" + columnWorldId + ") REFERENCES " + worldTable.getTableName() + "(" + worldTable.getColumnID() + ")"
|
.foreignKey(columnWorldId, worldTable.getTableName(), worldTable.getColumnID())
|
||||||
+ ")"
|
.toString()
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
|
Loading…
Reference in New Issue
Block a user