mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Change Session ID to Integer so that Sqlite Primary key works.
This commit is contained in:
parent
63cc2b2b0e
commit
db935fb981
@ -26,7 +26,7 @@ import java.util.List;
|
||||
*/
|
||||
public class Session {
|
||||
|
||||
private Long sessionID;
|
||||
private Integer sessionID;
|
||||
private WorldTimes worldTimes;
|
||||
private final long sessionStart;
|
||||
private long sessionEnd;
|
||||
@ -54,7 +54,7 @@ public class Session {
|
||||
* @param sessionStart Epoch millisecond the session was started.
|
||||
* @param sessionEnd Epoch millisecond the session ended.
|
||||
*/
|
||||
public Session(long id, long sessionStart, long sessionEnd, int mobKills, int deaths) {
|
||||
public Session(int id, long sessionStart, long sessionEnd, int mobKills, int deaths) {
|
||||
this.sessionID = id;
|
||||
this.sessionStart = sessionStart;
|
||||
this.sessionEnd = sessionEnd;
|
||||
@ -195,11 +195,11 @@ public class Session {
|
||||
* @return ID if present.
|
||||
* @throws NullPointerException if Session was not fetched from DB. Check using {@code isFetchedFromDB}
|
||||
*/
|
||||
public long getSessionID() {
|
||||
public int getSessionID() {
|
||||
return sessionID;
|
||||
}
|
||||
|
||||
public void setSessionID(long sessionID) {
|
||||
public void setSessionID(int sessionID) {
|
||||
this.sessionID = sessionID;
|
||||
}
|
||||
}
|
||||
|
@ -71,12 +71,12 @@ public class TableSqlParser extends SqlParser {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TableSqlParser primaryKeyIDColumn(boolean mySQL, String column, String type) {
|
||||
public TableSqlParser primaryKeyIDColumn(boolean mySQL, String column) {
|
||||
if (columns > 0) {
|
||||
append(", ");
|
||||
}
|
||||
append(column).addSpace();
|
||||
append(type).addSpace();
|
||||
append(Sql.INT).addSpace();
|
||||
append((mySQL) ? "NOT NULL AUTO_INCREMENT" : "PRIMARY KEY");
|
||||
columns++;
|
||||
return this;
|
||||
|
@ -43,7 +43,7 @@ public class CommandUseTable extends Table {
|
||||
public boolean createTable() {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnCommandId, Sql.INT)
|
||||
.primaryKeyIDColumn(usingMySQL, columnCommandId)
|
||||
.column(columnCommand, Sql.varchar(20)).notNull()
|
||||
.column(columnTimesUsed, Sql.INT).notNull()
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
|
@ -47,7 +47,7 @@ public class KillsTable extends UserIDTable {
|
||||
.column(columnVictimUserID, Sql.INT).notNull()
|
||||
.column(columnWeapon, Sql.varchar(30)).notNull()
|
||||
.column(columnDate, Sql.LONG).notNull()
|
||||
.column(columnSessionID, Sql.LONG).notNull()
|
||||
.column(columnSessionID, Sql.INT).notNull()
|
||||
.foreignKey(columnKillerUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.foreignKey(columnVictimUserID, usersTable.getTableName(), usersTable.getColumnID())
|
||||
.foreignKey(columnSessionID, sessionsTable.getTableName(), sessionsTable.getColumnID())
|
||||
@ -76,7 +76,7 @@ public class KillsTable extends UserIDTable {
|
||||
}
|
||||
}
|
||||
|
||||
public void savePlayerKills(UUID uuid, long sessionID, List<PlayerKill> playerKills) throws SQLException {
|
||||
public void savePlayerKills(UUID uuid, int sessionID, List<PlayerKill> playerKills) throws SQLException {
|
||||
if (Verify.isEmpty(playerKills)) {
|
||||
return;
|
||||
}
|
||||
@ -98,7 +98,7 @@ public class KillsTable extends UserIDTable {
|
||||
String weapon = kill.getWeapon();
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, victim.toString());
|
||||
statement.setLong(3, sessionID);
|
||||
statement.setInt(3, sessionID);
|
||||
statement.setLong(4, date);
|
||||
statement.setString(5, weapon);
|
||||
statement.addBatch();
|
||||
@ -111,7 +111,7 @@ public class KillsTable extends UserIDTable {
|
||||
}
|
||||
}
|
||||
|
||||
public void addKillsToSessions(UUID uuid, Map<Long, Session> sessions) throws SQLException {
|
||||
public void addKillsToSessions(UUID uuid, Map<Integer, Session> sessions) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -131,7 +131,7 @@ public class KillsTable extends UserIDTable {
|
||||
commit(statement.getConnection());
|
||||
|
||||
while (set.next()) {
|
||||
long sessionID = set.getLong(columnSessionID);
|
||||
int sessionID = set.getInt(columnSessionID);
|
||||
Session session = sessions.get(sessionID);
|
||||
if (session == null) {
|
||||
continue;
|
||||
|
@ -49,7 +49,7 @@ public class ServerTable extends Table {
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnServerID, Sql.INT)
|
||||
.primaryKeyIDColumn(usingMySQL, columnServerID)
|
||||
.column(columnServerUUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(columnServerName, Sql.varchar(100))
|
||||
.column(columnWebserverAddress, Sql.varchar(100))
|
||||
|
@ -45,7 +45,7 @@ public class SessionsTable extends UserIDTable {
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(this.tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID, Sql.LONG)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnServerID, Sql.INT).notNull()
|
||||
.column(columnSessionStart, Sql.LONG).notNull()
|
||||
@ -70,7 +70,7 @@ public class SessionsTable extends UserIDTable {
|
||||
*/
|
||||
public void saveSession(UUID uuid, Session session) throws SQLException {
|
||||
saveSessionInformation(uuid, session);
|
||||
long sessionID = getSessionID(uuid, session);
|
||||
int sessionID = getSessionID(uuid, session);
|
||||
if (sessionID == -1) {
|
||||
throw new IllegalStateException("Session was not Saved!");
|
||||
}
|
||||
@ -124,7 +124,7 @@ public class SessionsTable extends UserIDTable {
|
||||
* @param session session inserted.
|
||||
* @return ID of the inserted session or -1 if session has not been inserted.
|
||||
*/
|
||||
private long getSessionID(UUID uuid, Session session) throws SQLException {
|
||||
private int getSessionID(UUID uuid, Session session) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -137,9 +137,9 @@ public class SessionsTable extends UserIDTable {
|
||||
statement.setLong(3, session.getSessionEnd());
|
||||
set = statement.executeQuery();
|
||||
if (set.next()) {
|
||||
return set.getLong(columnID);
|
||||
return set.getInt(columnID);
|
||||
}
|
||||
return -1L;
|
||||
return -1;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
@ -168,7 +168,7 @@ public class SessionsTable extends UserIDTable {
|
||||
statement.setString(1, uuid.toString());
|
||||
set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
long id = set.getLong(columnID);
|
||||
int id = set.getInt(columnID);
|
||||
long start = set.getLong(columnSessionStart);
|
||||
long end = set.getLong(columnSessionEnd);
|
||||
String serverName = serverNames.get(set.getInt(columnServerID));
|
||||
@ -192,7 +192,7 @@ public class SessionsTable extends UserIDTable {
|
||||
|
||||
public Map<String, List<Session>> getSessions(UUID uuid) throws SQLException {
|
||||
Map<String, List<Session>> sessions = getSessionInformation(uuid);
|
||||
Map<Long, Session> allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(Session::getSessionID, Function.identity()));
|
||||
Map<Integer, Session> allSessions = sessions.values().stream().flatMap(Collection::stream).collect(Collectors.toMap(Session::getSessionID, Function.identity()));
|
||||
|
||||
db.getKillsTable().addKillsToSessions(uuid, allSessions);
|
||||
db.getWorldTimesTable().addWorldTimesToSessions(uuid, allSessions);
|
||||
|
@ -37,7 +37,7 @@ public class UsersTable extends UserIDTable {
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID, Sql.INT)
|
||||
.primaryKeyIDColumn(usingMySQL, columnID)
|
||||
.column(columnUUID, Sql.varchar(36)).notNull().unique()
|
||||
.column(columnRegistered, Sql.LONG).notNull()
|
||||
.column(columnName, Sql.varchar(16)).notNull()
|
||||
|
@ -42,7 +42,7 @@ public class WorldTable extends Table {
|
||||
@Override
|
||||
public boolean createTable() {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
.primaryKeyIDColumn(usingMySQL, columnWorldId, Sql.INT)
|
||||
.primaryKeyIDColumn(usingMySQL, columnWorldId)
|
||||
.column(columnWorldName, Sql.varchar(100)).notNull()
|
||||
.primaryKey(usingMySQL, columnWorldId)
|
||||
.toString()
|
||||
|
@ -51,7 +51,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
return createTable(TableSqlParser.createTable(tableName)
|
||||
.column(columnUserID, Sql.INT).notNull()
|
||||
.column(columnWorldId, Sql.INT).notNull()
|
||||
.column(columnSessionID, Sql.LONG).notNull()
|
||||
.column(columnSessionID, Sql.INT).notNull()
|
||||
.column(columnSurvival, Sql.LONG).notNull().defaultValue("0")
|
||||
.column(columnCreative, Sql.LONG).notNull().defaultValue("0")
|
||||
.column(columnAdventure, Sql.LONG).notNull().defaultValue("0")
|
||||
@ -63,7 +63,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
);
|
||||
}
|
||||
|
||||
public void saveWorldTimes(UUID uuid, long sessionID, WorldTimes worldTimes) throws SQLException {
|
||||
public void saveWorldTimes(UUID uuid, int sessionID, WorldTimes worldTimes) throws SQLException {
|
||||
Map<String, GMTimes> worldTimesMap = worldTimes.getWorldTimes();
|
||||
if (Verify.isEmpty(worldTimesMap)) {
|
||||
return;
|
||||
@ -92,7 +92,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, worldName);
|
||||
statement.setLong(3, sessionID);
|
||||
statement.setInt(3, sessionID);
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
statement.setLong(4, gmTimes.getTime(gms[0]));
|
||||
@ -109,7 +109,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
}
|
||||
}
|
||||
|
||||
public void addWorldTimesToSessions(UUID uuid, Map<Long, Session> sessions) throws SQLException {
|
||||
public void addWorldTimesToSessions(UUID uuid, Map<Integer, Session> sessions) throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
@ -131,7 +131,7 @@ public class WorldTimesTable extends UserIDTable {
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
while (set.next()) {
|
||||
long sessionID = set.getLong(columnSessionID);
|
||||
int sessionID = set.getInt(columnSessionID);
|
||||
Session session = sessions.get(sessionID);
|
||||
|
||||
if (session == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user