mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +01:00
Removed GMTimesTable
This commit is contained in:
parent
7fd9960c8a
commit
67df66cc31
@ -12,11 +12,10 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
public class GMTimes extends TimeKeeper {
|
public class GMTimes extends TimeKeeper {
|
||||||
|
|
||||||
// TODO Make private once GMTimesTable is removed
|
private static final String SURVIVAL = "SURVIVAL";
|
||||||
public static final String SURVIVAL = "SURVIVAL";
|
private static final String CREATIVE = "CREATIVE";
|
||||||
public static final String CREATIVE = "CREATIVE";
|
private static final String ADVENTURE = "ADVENTURE";
|
||||||
public static final String ADVENTURE = "ADVENTURE";
|
private static final String SPECTATOR = "SPECTATOR";
|
||||||
public static final String SPECTATOR = "SPECTATOR";
|
|
||||||
|
|
||||||
public GMTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
public GMTimes(Map<String, Long> times, String lastState, long lastStateChange) {
|
||||||
super(times, lastState, lastStateChange);
|
super(times, lastState, lastStateChange);
|
||||||
@ -67,8 +66,8 @@ public class GMTimes extends TimeKeeper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTimes(long playtime) {
|
public void resetTimes(long time) {
|
||||||
resetState(SURVIVAL, playtime);
|
resetState(SURVIVAL, time);
|
||||||
resetState(CREATIVE);
|
resetState(CREATIVE);
|
||||||
resetState(ADVENTURE);
|
resetState(ADVENTURE);
|
||||||
resetState(SPECTATOR);
|
resetState(SPECTATOR);
|
||||||
|
@ -28,11 +28,6 @@ public abstract class Database {
|
|||||||
*/
|
*/
|
||||||
protected UsersTable usersTable;
|
protected UsersTable usersTable;
|
||||||
|
|
||||||
/**
|
|
||||||
* Table representing plan_gamemodetimes in the database.
|
|
||||||
*/
|
|
||||||
protected GMTimesTable gmTimesTable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table representing plan_kills in the database.
|
* Table representing plan_kills in the database.
|
||||||
*/
|
*/
|
||||||
@ -294,15 +289,6 @@ public abstract class Database {
|
|||||||
return sessionsTable;
|
return sessionsTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to get the gm times table.
|
|
||||||
*
|
|
||||||
* @return Table representing plan_gamemodetimes
|
|
||||||
*/
|
|
||||||
public GMTimesTable getGmTimesTable() {
|
|
||||||
return gmTimesTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get the kills table.
|
* Used to get the kills table.
|
||||||
*
|
*
|
||||||
|
@ -45,7 +45,6 @@ public abstract class SQLDB extends Database {
|
|||||||
usingMySQL = getName().equals("MySQL");
|
usingMySQL = getName().equals("MySQL");
|
||||||
|
|
||||||
usersTable = new UsersTable(this, usingMySQL);
|
usersTable = new UsersTable(this, usingMySQL);
|
||||||
gmTimesTable = new GMTimesTable(this, usingMySQL);
|
|
||||||
sessionsTable = new SessionsTable(this, usingMySQL);
|
sessionsTable = new SessionsTable(this, usingMySQL);
|
||||||
killsTable = new KillsTable(this, usingMySQL);
|
killsTable = new KillsTable(this, usingMySQL);
|
||||||
ipsTable = new IPsTable(this, usingMySQL);
|
ipsTable = new IPsTable(this, usingMySQL);
|
||||||
@ -226,7 +225,7 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
public Table[] getAllTables() {
|
public Table[] getAllTables() {
|
||||||
return new Table[]{
|
return new Table[]{
|
||||||
usersTable, gmTimesTable, ipsTable,
|
usersTable, ipsTable,
|
||||||
nicknamesTable, sessionsTable, killsTable,
|
nicknamesTable, sessionsTable, killsTable,
|
||||||
commandUseTable, tpsTable, worldTable,
|
commandUseTable, tpsTable, worldTable,
|
||||||
worldTimesTable, securityTable};
|
worldTimesTable, securityTable};
|
||||||
@ -237,7 +236,7 @@ public abstract class SQLDB extends Database {
|
|||||||
*/
|
*/
|
||||||
public Table[] getAllTablesInRemoveOrder() {
|
public Table[] getAllTablesInRemoveOrder() {
|
||||||
return new Table[]{
|
return new Table[]{
|
||||||
gmTimesTable, ipsTable,
|
ipsTable,
|
||||||
nicknamesTable, sessionsTable, killsTable,
|
nicknamesTable, sessionsTable, killsTable,
|
||||||
worldTimesTable, worldTable, usersTable,
|
worldTimesTable, worldTable, usersTable,
|
||||||
commandUseTable, tpsTable};
|
commandUseTable, tpsTable};
|
||||||
@ -320,7 +319,6 @@ public abstract class SQLDB extends Database {
|
|||||||
boolean success = userId != -1
|
boolean success = userId != -1
|
||||||
&& ipsTable.removeUserIPs(userId)
|
&& ipsTable.removeUserIPs(userId)
|
||||||
&& nicknamesTable.removeUserNicknames(userId)
|
&& nicknamesTable.removeUserNicknames(userId)
|
||||||
&& gmTimesTable.removeUserGMTimes(userId)
|
|
||||||
&& sessionsTable.removeUserSessions(userId)
|
&& sessionsTable.removeUserSessions(userId)
|
||||||
&& killsTable.removeUserKillsAndVictims(userId)
|
&& killsTable.removeUserKillsAndVictims(userId)
|
||||||
&& worldTimesTable.removeUserWorldTimes(userId)
|
&& worldTimesTable.removeUserWorldTimes(userId)
|
||||||
@ -369,9 +367,6 @@ public abstract class SQLDB extends Database {
|
|||||||
|
|
||||||
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
List<InetAddress> ips = ipsTable.getIPAddresses(userId);
|
||||||
data.addIpAddresses(ips);
|
data.addIpAddresses(ips);
|
||||||
|
|
||||||
Map<String, Long> gmTimes = gmTimesTable.getGMTimes(userId);
|
|
||||||
data.getGmTimes().setTimes(gmTimes);
|
|
||||||
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
Map<String, Long> worldTimes = worldTimesTable.getWorldTimes(userId);
|
||||||
WorldTimes worldT = data.getWorldTimes();
|
WorldTimes worldT = data.getWorldTimes();
|
||||||
// worldT.setTimes(worldTimes); //TODO
|
// worldT.setTimes(worldTimes); //TODO
|
||||||
@ -419,7 +414,6 @@ public abstract class SQLDB extends Database {
|
|||||||
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
Map<Integer, Set<InetAddress>> ipList = ipsTable.getIPList(ids);
|
||||||
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
Map<Integer, List<KillData>> playerKills = killsTable.getPlayerKills(ids, idUuidRel);
|
||||||
Map<Integer, List<SessionData>> sessionData = sessionsTable.getSessionData(ids);
|
Map<Integer, List<SessionData>> sessionData = sessionsTable.getSessionData(ids);
|
||||||
Map<Integer, Map<String, Long>> gmTimes = gmTimesTable.getGMTimes(ids);
|
|
||||||
Map<Integer, Map<String, Long>> worldTimes = worldTimesTable.getWorldTimes(ids);
|
Map<Integer, Map<String, Long>> worldTimes = worldTimesTable.getWorldTimes(ids);
|
||||||
|
|
||||||
Log.debug("Database",
|
Log.debug("Database",
|
||||||
@ -431,7 +425,6 @@ public abstract class SQLDB extends Database {
|
|||||||
" IPs: " + ipList.size(),
|
" IPs: " + ipList.size(),
|
||||||
" Kills: " + playerKills.size(),
|
" Kills: " + playerKills.size(),
|
||||||
" Sessions: " + sessionData.size(),
|
" Sessions: " + sessionData.size(),
|
||||||
" GM Times: " + gmTimes.size(),
|
|
||||||
" World Times: " + worldTimes.size()
|
" World Times: " + worldTimes.size()
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -446,7 +439,6 @@ public abstract class SQLDB extends Database {
|
|||||||
}
|
}
|
||||||
uData.addSessions(sessionData.get(id));
|
uData.addSessions(sessionData.get(id));
|
||||||
uData.setPlayerKills(playerKills.get(id));
|
uData.setPlayerKills(playerKills.get(id));
|
||||||
uData.getGmTimes().setTimes(gmTimes.get(id));
|
|
||||||
WorldTimes worldT = uData.getWorldTimes();
|
WorldTimes worldT = uData.getWorldTimes();
|
||||||
// worldT.setTimes(worldTimes.get(id)); //TODO
|
// worldT.setTimes(worldTimes.get(id)); //TODO
|
||||||
// if (worldT.getLastStateChange() == 0) {
|
// if (worldT.getLastStateChange() == 0) {
|
||||||
@ -526,7 +518,6 @@ public abstract class SQLDB extends Database {
|
|||||||
ipsTable.saveIPList(ips);
|
ipsTable.saveIPList(ips);
|
||||||
killsTable.savePlayerKills(kills, uuids);
|
killsTable.savePlayerKills(kills, uuids);
|
||||||
sessionsTable.saveSessionData(sessions);
|
sessionsTable.saveSessionData(sessions);
|
||||||
gmTimesTable.saveGMTimes(gmTimes);
|
|
||||||
// TODO worldTable.saveWorlds(worldNames);
|
// TODO worldTable.saveWorlds(worldNames);
|
||||||
worldTimesTable.saveWorldTimes(worldTimes);
|
worldTimesTable.saveWorldTimes(worldTimes);
|
||||||
commit();
|
commit();
|
||||||
@ -561,7 +552,6 @@ public abstract class SQLDB extends Database {
|
|||||||
nicknamesTable.saveNickList(userId, new HashSet<>(data.getNicknames()), data.getLastNick());
|
nicknamesTable.saveNickList(userId, new HashSet<>(data.getNicknames()), data.getLastNick());
|
||||||
ipsTable.saveIPList(userId, new HashSet<>(data.getIps()));
|
ipsTable.saveIPList(userId, new HashSet<>(data.getIps()));
|
||||||
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
killsTable.savePlayerKills(userId, new ArrayList<>(data.getPlayerKills()));
|
||||||
gmTimesTable.saveGMTimes(userId, data.getGmTimes().getTimes());
|
|
||||||
// TODO worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
// TODO worldTable.saveWorlds(new HashSet<>(data.getWorldTimes().getTimes().keySet()));
|
||||||
// worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
// worldTimesTable.saveWorldTimes(userId, data.getWorldTimes().getTimes());
|
||||||
data.stopAccessing();
|
data.stopAccessing();
|
||||||
|
@ -1,354 +0,0 @@
|
|||||||
package main.java.com.djrapitops.plan.database.tables;
|
|
||||||
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
import main.java.com.djrapitops.plan.Log;
|
|
||||||
import main.java.com.djrapitops.plan.data.time.GMTimes;
|
|
||||||
import main.java.com.djrapitops.plan.database.Container;
|
|
||||||
import main.java.com.djrapitops.plan.database.DBUtils;
|
|
||||||
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.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Rsl1122
|
|
||||||
* @deprecated GM Times moved to WorldTable
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class GMTimesTable extends UserIDTable {
|
|
||||||
|
|
||||||
private final String columnSurvivalTime;
|
|
||||||
private final String columnCreativeTime;
|
|
||||||
private final String columnAdventureTime;
|
|
||||||
private final String columnSpectatorTime;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param db
|
|
||||||
* @param usingMySQL
|
|
||||||
*/
|
|
||||||
public GMTimesTable(SQLDB db, boolean usingMySQL) {
|
|
||||||
super("plan_gamemodetimes", db, usingMySQL);
|
|
||||||
columnUserID = "user_id";
|
|
||||||
columnSurvivalTime = "SURVIVAL";
|
|
||||||
columnCreativeTime = "CREATIVE";
|
|
||||||
columnAdventureTime = "ADVENTURE";
|
|
||||||
columnSpectatorTime = "SPECTATOR";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean createTable() {
|
|
||||||
UsersTable usersTable = db.getUsersTable();
|
|
||||||
try {
|
|
||||||
execute(TableSqlParser.createTable(tableName)
|
|
||||||
.column(columnUserID, Sql.INT).notNull()
|
|
||||||
.column(columnSurvivalTime, Sql.LONG).notNull()
|
|
||||||
.column(columnCreativeTime, Sql.LONG).notNull()
|
|
||||||
.column(columnAdventureTime, Sql.LONG).notNull()
|
|
||||||
.column(columnSpectatorTime, Sql.LONG).notNull()
|
|
||||||
.foreignKey(columnUserID, usersTable.getTableName(), usersTable.getColumnID())
|
|
||||||
.toString()
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
Log.toLog(this.getClass().getName(), ex);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param userId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean removeUserGMTimes(int userId) {
|
|
||||||
return super.removeDataOf(userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param userId
|
|
||||||
* @return
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getGMTimes(int userId) throws SQLException {
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
ResultSet set = null;
|
|
||||||
try {
|
|
||||||
statement = prepareStatement("SELECT * FROM " + tableName + " WHERE (" + columnUserID + "=?)");
|
|
||||||
statement.setInt(1, userId);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
HashMap<String, Long> times = new HashMap<>();
|
|
||||||
|
|
||||||
while (set.next()) {
|
|
||||||
times.put(GMTimes.SURVIVAL, set.getLong(columnSurvivalTime));
|
|
||||||
times.put(GMTimes.CREATIVE, set.getLong(columnCreativeTime));
|
|
||||||
times.put(GMTimes.ADVENTURE, set.getLong(columnAdventureTime));
|
|
||||||
times.put(GMTimes.SPECTATOR, set.getLong(columnSpectatorTime));
|
|
||||||
}
|
|
||||||
|
|
||||||
return times;
|
|
||||||
} finally {
|
|
||||||
close(set);
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<Integer, Map<String, Long>> getGMTimes(Collection<Integer> userIds) throws SQLException {
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
ResultSet set = null;
|
|
||||||
Map<Integer, Map<String, Long>> times = new HashMap<>();
|
|
||||||
try {
|
|
||||||
statement = prepareStatement("SELECT * FROM " + tableName);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
|
|
||||||
while (set.next()) {
|
|
||||||
Map<String, Long> gmTimes = new HashMap<>();
|
|
||||||
int id = set.getInt(columnUserID);
|
|
||||||
if (!userIds.contains(id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
gmTimes.put(GMTimes.SURVIVAL, set.getLong(columnSurvivalTime));
|
|
||||||
gmTimes.put(GMTimes.CREATIVE, set.getLong(columnCreativeTime));
|
|
||||||
gmTimes.put(GMTimes.ADVENTURE, set.getLong(columnAdventureTime));
|
|
||||||
gmTimes.put(GMTimes.SPECTATOR, set.getLong(columnSpectatorTime));
|
|
||||||
times.put(id, gmTimes);
|
|
||||||
}
|
|
||||||
|
|
||||||
return times;
|
|
||||||
} finally {
|
|
||||||
close(set);
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param userId
|
|
||||||
* @param gamemodeTimes
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
public void saveGMTimes(int userId, Map<String, Long> gamemodeTimes) throws SQLException {
|
|
||||||
if (Verify.isEmpty(gamemodeTimes)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String[] gms = GMTimes.getGMKeyArray();
|
|
||||||
|
|
||||||
int update;
|
|
||||||
try {
|
|
||||||
statement = prepareStatement(
|
|
||||||
"UPDATE " + tableName + " SET "
|
|
||||||
+ columnSurvivalTime + "=?, "
|
|
||||||
+ columnCreativeTime + "=?, "
|
|
||||||
+ columnAdventureTime + "=?, "
|
|
||||||
+ columnSpectatorTime + "=? "
|
|
||||||
+ " WHERE (" + columnUserID + "=?)");
|
|
||||||
statement.setInt(5, userId);
|
|
||||||
|
|
||||||
for (int i = 0; i < gms.length; i++) {
|
|
||||||
Long time = gamemodeTimes.get(gms[i]);
|
|
||||||
statement.setLong(i + 1, time != null ? time : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
update = statement.executeUpdate();
|
|
||||||
} finally {
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (update == 0) {
|
|
||||||
addNewGMTimesRow(userId, gamemodeTimes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<Integer> getSavedIDs() throws SQLException {
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
ResultSet set = null;
|
|
||||||
try {
|
|
||||||
statement = prepareStatement("SELECT " + columnUserID + " FROM " + tableName);
|
|
||||||
set = statement.executeQuery();
|
|
||||||
Set<Integer> ids = new HashSet<>();
|
|
||||||
while (set.next()) {
|
|
||||||
ids.add(set.getInt(columnUserID));
|
|
||||||
}
|
|
||||||
return ids;
|
|
||||||
} finally {
|
|
||||||
close(set);
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveGMTimes(Map<Integer, Map<String, Long>> gamemodeTimes) throws SQLException {
|
|
||||||
if (Verify.isEmpty(gamemodeTimes)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Integer> savedIDs = getSavedIDs();
|
|
||||||
|
|
||||||
Map<Integer, GMTimes> gmTimes = new HashMap<>();
|
|
||||||
|
|
||||||
for (Map.Entry<Integer, Map<String, Long>> entrySet : gamemodeTimes.entrySet()) {
|
|
||||||
int userID = entrySet.getKey();
|
|
||||||
|
|
||||||
if (!savedIDs.contains(userID)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Long> gmTimesMap = entrySet.getValue();
|
|
||||||
gmTimes.put(userID, new GMTimes(gmTimesMap));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<List<Container<GMTimes>>> batches = DBUtils.splitIntoBatchesWithID(gmTimes);
|
|
||||||
|
|
||||||
batches.forEach(batch -> {
|
|
||||||
try {
|
|
||||||
saveGMTimesBatch(batch);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.toLog("GMTimesTable.saveGMTimes", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
gamemodeTimes.keySet().removeAll(savedIDs);
|
|
||||||
|
|
||||||
addNewGMTimesRows(gamemodeTimes);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveGMTimesBatch(List<Container<GMTimes>> batch) throws SQLException {
|
|
||||||
if (batch.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] gms = GMTimes.getGMKeyArray();
|
|
||||||
Set<Integer> savedIDs = getSavedIDs();
|
|
||||||
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
try {
|
|
||||||
statement = prepareStatement(
|
|
||||||
"UPDATE " + tableName + " SET "
|
|
||||||
+ columnSurvivalTime + "=?, "
|
|
||||||
+ columnCreativeTime + "=?, "
|
|
||||||
+ columnAdventureTime + "=?, "
|
|
||||||
+ columnSpectatorTime + "=? "
|
|
||||||
+ " WHERE (" + columnUserID + "=?)");
|
|
||||||
|
|
||||||
for (Container<GMTimes> data : batch) {
|
|
||||||
int id = data.getId();
|
|
||||||
|
|
||||||
if (!savedIDs.contains(id)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.setInt(5, id);
|
|
||||||
|
|
||||||
for (int i = 0; i < gms.length; i++) {
|
|
||||||
Map<String, Long> times = data.getObject().getTimes();
|
|
||||||
Long time = times.get(gms[i]);
|
|
||||||
|
|
||||||
statement.setLong(i + 1, time != null ? time : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.addBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.executeBatch();
|
|
||||||
} finally {
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNewGMTimesRows(Map<Integer, Map<String, Long>> gamemodeTimes) {
|
|
||||||
if (Verify.isEmpty(gamemodeTimes)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<Integer, GMTimes> gmTimes = new HashMap<>();
|
|
||||||
|
|
||||||
for (Map.Entry<Integer, Map<String, Long>> entrySet : gamemodeTimes.entrySet()) {
|
|
||||||
int userID = entrySet.getKey();
|
|
||||||
Map<String, Long> gmTimesMap = entrySet.getValue();
|
|
||||||
gmTimes.put(userID, new GMTimes(gmTimesMap));
|
|
||||||
}
|
|
||||||
|
|
||||||
List<List<Container<GMTimes>>> batches = DBUtils.splitIntoBatchesWithID(gmTimes);
|
|
||||||
|
|
||||||
batches.forEach(batch -> {
|
|
||||||
try {
|
|
||||||
addNewGMTimesBatch(batch);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Log.toLog("GMTimesTable.addNewGMTimesRows", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNewGMTimesBatch(List<Container<GMTimes>> batch) throws SQLException {
|
|
||||||
if (batch.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String[] gms = GMTimes.getGMKeyArray();
|
|
||||||
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
try {
|
|
||||||
statement = prepareStatement(
|
|
||||||
"INSERT INTO " + tableName + " ("
|
|
||||||
+ columnUserID + ", "
|
|
||||||
+ columnSurvivalTime + ", "
|
|
||||||
+ columnCreativeTime + ", "
|
|
||||||
+ columnAdventureTime + ", "
|
|
||||||
+ columnSpectatorTime
|
|
||||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
for (Container<GMTimes> data : batch) {
|
|
||||||
statement.setInt(1, data.getId());
|
|
||||||
|
|
||||||
for (int i = 0; i < gms.length; i++) {
|
|
||||||
Map<String, Long> times = data.getObject().getTimes();
|
|
||||||
Long time = times.get(gms[i]);
|
|
||||||
|
|
||||||
statement.setLong(i + 2, time != null ? time : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.addBatch();
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.executeBatch();
|
|
||||||
} finally {
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addNewGMTimesRow(int userId, Map<String, Long> gamemodeTimes) throws SQLException {
|
|
||||||
if (Verify.isEmpty(gamemodeTimes)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PreparedStatement statement = null;
|
|
||||||
String[] gms = GMTimes.getGMKeyArray();
|
|
||||||
try {
|
|
||||||
statement = prepareStatement("INSERT INTO " + tableName + " ("
|
|
||||||
+ columnUserID + ", "
|
|
||||||
+ columnSurvivalTime + ", "
|
|
||||||
+ columnCreativeTime + ", "
|
|
||||||
+ columnAdventureTime + ", "
|
|
||||||
+ columnSpectatorTime
|
|
||||||
+ ") VALUES (?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
statement.setInt(1, userId);
|
|
||||||
|
|
||||||
for (int i = 0; i < gms.length; i++) {
|
|
||||||
Long time = gamemodeTimes.get(gms[i]);
|
|
||||||
statement.setLong(i + 2, time != null ? time : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
statement.execute();
|
|
||||||
} finally {
|
|
||||||
close(statement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user