mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-28 02:54:20 +01:00
Fixed AlterTableV16 placing all worlds under the same server
This commit is contained in:
parent
8c2feb312c
commit
1e993ed0dd
@ -27,8 +27,10 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class SessionsTable extends UserIDTable {
|
public class SessionsTable extends UserIDTable {
|
||||||
|
|
||||||
|
public static final String TABLE_NAME = "plan_sessions";
|
||||||
|
|
||||||
public SessionsTable(SQLDB db) {
|
public SessionsTable(SQLDB db) {
|
||||||
super("plan_sessions", db);
|
super(TABLE_NAME, db);
|
||||||
serverTable = db.getServerTable();
|
serverTable = db.getServerTable();
|
||||||
insertStatement = "INSERT INTO " + tableName + " ("
|
insertStatement = "INSERT INTO " + tableName + " ("
|
||||||
+ Col.USER_ID + ", "
|
+ Col.USER_ID + ", "
|
||||||
|
@ -29,11 +29,12 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class WorldTable extends Table {
|
public class WorldTable extends Table {
|
||||||
|
|
||||||
|
public static final String TABLE_NAME = "plan_worlds";
|
||||||
public final String statementSelectID;
|
public final String statementSelectID;
|
||||||
private final ServerTable serverTable;
|
private final ServerTable serverTable;
|
||||||
|
|
||||||
public WorldTable(SQLDB db) {
|
public WorldTable(SQLDB db) {
|
||||||
super("plan_worlds", db);
|
super(TABLE_NAME, db);
|
||||||
serverTable = db.getServerTable();
|
serverTable = db.getServerTable();
|
||||||
statementSelectID = "(SELECT " + Col.ID + " FROM " + tableName +
|
statementSelectID = "(SELECT " + Col.ID + " FROM " + tableName +
|
||||||
" WHERE (" + Col.NAME + "=?)" +
|
" WHERE (" + Col.NAME + "=?)" +
|
||||||
@ -175,7 +176,7 @@ public class WorldTable extends Table {
|
|||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
for (String world : worldsToSave) {
|
for (String world : worldsToSave) {
|
||||||
statement.setString(1, world);
|
statement.setString(1, world);
|
||||||
statement.setString(2, ServerInfo.getServerUUID().toString());
|
statement.setString(2, serverUUID.toString());
|
||||||
statement.addBatch();
|
statement.addBatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,6 +293,7 @@ public class WorldTable extends Table {
|
|||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
Function.identity(),
|
Function.identity(),
|
||||||
oldWorld -> worldObjects.stream()
|
oldWorld -> worldObjects.stream()
|
||||||
|
.filter(worldObj -> worldObj.serverId != 0)
|
||||||
.filter(worldObj -> worldObj.equals(oldWorld))
|
.filter(worldObj -> worldObj.equals(oldWorld))
|
||||||
.collect(Collectors.toList()
|
.collect(Collectors.toList()
|
||||||
)));
|
)));
|
||||||
@ -346,7 +348,6 @@ public class WorldTable extends Table {
|
|||||||
public List<WorldObj> processResults(ResultSet set) throws SQLException {
|
public List<WorldObj> processResults(ResultSet set) throws SQLException {
|
||||||
List<WorldObj> objects = new ArrayList<>();
|
List<WorldObj> objects = new ArrayList<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
|
|
||||||
int worldID = set.getInt(Col.ID.get());
|
int worldID = set.getInt(Col.ID.get());
|
||||||
int serverID = set.getInt(Col.SERVER_ID.get());
|
int serverID = set.getInt(Col.SERVER_ID.get());
|
||||||
String worldName = set.getString(Col.NAME.get());
|
String worldName = set.getString(Col.NAME.get());
|
||||||
@ -403,4 +404,13 @@ class WorldObj {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(name);
|
return Objects.hashCode(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "{" +
|
||||||
|
"id=" + id +
|
||||||
|
", serverId=" + serverId +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,13 +35,14 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class WorldTimesTable extends UserIDTable {
|
public class WorldTimesTable extends UserIDTable {
|
||||||
|
|
||||||
|
public static final String TABLE_NAME = "plan_world_times";
|
||||||
private final ServerTable serverTable;
|
private final ServerTable serverTable;
|
||||||
private final WorldTable worldTable;
|
private final WorldTable worldTable;
|
||||||
private final SessionsTable sessionsTable;
|
private final SessionsTable sessionsTable;
|
||||||
private String insertStatement;
|
private String insertStatement;
|
||||||
|
|
||||||
public WorldTimesTable(SQLDB db) {
|
public WorldTimesTable(SQLDB db) {
|
||||||
super("plan_world_times", db);
|
super(TABLE_NAME, db);
|
||||||
worldTable = db.getWorldTable();
|
worldTable = db.getWorldTable();
|
||||||
sessionsTable = db.getSessionsTable();
|
sessionsTable = db.getSessionsTable();
|
||||||
serverTable = db.getServerTable();
|
serverTable = db.getServerTable();
|
||||||
|
@ -70,7 +70,7 @@ public class SQLiteTest {
|
|||||||
StaticHolder.saveInstance(SQLiteTest.class, Plan.class);
|
StaticHolder.saveInstance(SQLiteTest.class, Plan.class);
|
||||||
|
|
||||||
Log.setErrorManager(new TestErrorManager());
|
Log.setErrorManager(new TestErrorManager());
|
||||||
// Log.setDebugMode("console");
|
Log.setDebugMode("console");
|
||||||
// Settings.DEV_MODE.setTemporaryValue(true);
|
// Settings.DEV_MODE.setTemporaryValue(true);
|
||||||
|
|
||||||
db.init();
|
db.init();
|
||||||
@ -936,4 +936,96 @@ public class SQLiteTest {
|
|||||||
assertEquals(3, geolocations.size());
|
assertEquals(3, geolocations.size());
|
||||||
assertTrue(geolocations.contains(secondInfo.getGeolocation()));
|
assertTrue(geolocations.contains(secondInfo.getGeolocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWorldTableAlterV16() throws SQLException {
|
||||||
|
saveUserOne();
|
||||||
|
new Table("test", db) {
|
||||||
|
@Override
|
||||||
|
public void createTable() {
|
||||||
|
try {
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + WorldTable.TABLE_NAME + " (" +
|
||||||
|
WorldTable.Col.NAME + ", " +
|
||||||
|
WorldTable.Col.SERVER_ID +
|
||||||
|
") VALUES ('Test', '0')"
|
||||||
|
);
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + SessionsTable.TABLE_NAME + " (" +
|
||||||
|
SessionsTable.Col.SESSION_START + ", " +
|
||||||
|
SessionsTable.Col.SESSION_END + ", " +
|
||||||
|
SessionsTable.Col.AFK_TIME + ", " +
|
||||||
|
SessionsTable.Col.DEATHS + ", " +
|
||||||
|
SessionsTable.Col.MOB_KILLS + ", " +
|
||||||
|
SessionsTable.Col.SERVER_ID + ", " +
|
||||||
|
SessionsTable.Col.USER_ID +
|
||||||
|
") VALUES ('0', '0', '0', '0', '0', '1', '1')"
|
||||||
|
);
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + WorldTimesTable.TABLE_NAME + " (" +
|
||||||
|
WorldTimesTable.Col.SERVER_ID + ", " +
|
||||||
|
WorldTimesTable.Col.SESSION_ID + ", " +
|
||||||
|
WorldTimesTable.Col.USER_ID + ", " +
|
||||||
|
WorldTimesTable.Col.WORLD_ID + ", " +
|
||||||
|
WorldTimesTable.Col.SURVIVAL + ", " +
|
||||||
|
WorldTimesTable.Col.CREATIVE + ", " +
|
||||||
|
WorldTimesTable.Col.SPECTATOR + ", " +
|
||||||
|
WorldTimesTable.Col.ADVENTURE +
|
||||||
|
") VALUES ('1', '1', '1', '1', '0','0','0','0')"
|
||||||
|
);
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + ServerTable.TABLE_NAME + " (" +
|
||||||
|
ServerTable.Col.SERVER_UUID + ", " +
|
||||||
|
ServerTable.Col.SERVER_ID + ", " +
|
||||||
|
ServerTable.Col.MAX_PLAYERS + ", " +
|
||||||
|
ServerTable.Col.WEBSERVER_ADDRESS + ", " +
|
||||||
|
ServerTable.Col.INSTALLED + ", " +
|
||||||
|
ServerTable.Col.NAME +
|
||||||
|
") VALUES ('" + UUID.randomUUID() + "', '2', '0', '0', '1', '2')"
|
||||||
|
);
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + SessionsTable.TABLE_NAME + " (" +
|
||||||
|
SessionsTable.Col.SESSION_START + ", " +
|
||||||
|
SessionsTable.Col.SESSION_END + ", " +
|
||||||
|
SessionsTable.Col.AFK_TIME + ", " +
|
||||||
|
SessionsTable.Col.DEATHS + ", " +
|
||||||
|
SessionsTable.Col.MOB_KILLS + ", " +
|
||||||
|
SessionsTable.Col.SERVER_ID + ", " +
|
||||||
|
SessionsTable.Col.USER_ID +
|
||||||
|
") VALUES ('0', '0', '0', '0', '0', '2', '1')"
|
||||||
|
);
|
||||||
|
execute(
|
||||||
|
"INSERT INTO " + WorldTimesTable.TABLE_NAME + " (" +
|
||||||
|
WorldTimesTable.Col.SERVER_ID + ", " +
|
||||||
|
WorldTimesTable.Col.SESSION_ID + ", " +
|
||||||
|
WorldTimesTable.Col.USER_ID + ", " +
|
||||||
|
WorldTimesTable.Col.WORLD_ID + ", " +
|
||||||
|
WorldTimesTable.Col.SURVIVAL + ", " +
|
||||||
|
WorldTimesTable.Col.CREATIVE + ", " +
|
||||||
|
WorldTimesTable.Col.SPECTATOR + ", " +
|
||||||
|
WorldTimesTable.Col.ADVENTURE +
|
||||||
|
") VALUES ('2', '2', '1', '1', '0','0','0','0')"
|
||||||
|
);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
Log.toLog(this.getClass().getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.createTable();
|
||||||
|
|
||||||
|
WorldTable worldTable = db.getWorldTable();
|
||||||
|
Map<Integer, List<Integer>> before = worldTable.getWorldIDsByServerIDs();
|
||||||
|
System.out.println("\nBefore: " + before);
|
||||||
|
System.out.println("Before: " + worldTable.getWorldObjects() + "\n");
|
||||||
|
|
||||||
|
worldTable.alterTableV16();
|
||||||
|
|
||||||
|
Map<Integer, List<Integer>> after = worldTable.getWorldIDsByServerIDs();
|
||||||
|
System.out.println("\nAfter: " + after);
|
||||||
|
System.out.println("After: " + worldTable.getWorldObjects() + "\n");
|
||||||
|
assertNull(after.get(0));
|
||||||
|
assertNotNull(after.get(1));
|
||||||
|
assertEquals(1, after.get(1).size());
|
||||||
|
assertNotNull(after.get(2));
|
||||||
|
assertEquals(1, after.get(2).size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user