use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class NicknameQueries method fetchAllNicknameData.
/**
* Query database for all nickname data.
*
* @return Multimap: Server UUID - (Player UUID - List of nicknames)
*/
public static Query<Map<ServerUUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME;
return new QueryAllStatement<Map<ServerUUID, Map<UUID, List<Nickname>>>>(sql, 5000) {
@Override
public Map<ServerUUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
Map<UUID, List<Nickname>> serverMap = map.computeIfAbsent(serverUUID, Maps::create);
List<Nickname> nicknames = serverMap.computeIfAbsent(uuid, Lists::create);
nicknames.add(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
}
return map;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class ServerQueries method fetchServerNames.
public static Query<Map<ServerUUID, String>> fetchServerNames() {
String sql = Select.from(ServerTable.TABLE_NAME, ServerTable.SERVER_ID, ServerTable.SERVER_UUID, ServerTable.NAME).toString();
return new QueryAllStatement<Map<ServerUUID, String>>(sql) {
@Override
public Map<ServerUUID, String> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, String> names = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
names.put(serverUUID, Server.getIdentifiableName(set.getString(ServerTable.NAME), set.getInt(ServerTable.SERVER_ID)));
}
return names;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class WorldTimesTable method addSessionWorldTimesToBatch.
public static void addSessionWorldTimesToBatch(PreparedStatement statement, FinishedSession session, String[] gms) throws SQLException {
UUID uuid = session.getPlayerUUID();
ServerUUID serverUUID = session.getServerUUID();
Optional<WorldTimes> worldTimes = session.getExtraData().get(WorldTimes.class);
if (!worldTimes.isPresent())
return;
for (Map.Entry<String, GMTimes> worldTimesEntry : worldTimes.get().getWorldTimes().entrySet()) {
String worldName = worldTimesEntry.getKey();
GMTimes gmTimes = worldTimesEntry.getValue();
// Session ID select statement
statement.setString(1, uuid.toString());
statement.setString(2, serverUUID.toString());
statement.setLong(3, session.getStart());
statement.setLong(4, session.getEnd());
// World ID select statement
statement.setString(5, worldName);
statement.setString(6, serverUUID.toString());
statement.setString(7, uuid.toString());
statement.setString(8, serverUUID.toString());
statement.setLong(9, gmTimes.getTime(gms[0]));
statement.setLong(10, gmTimes.getTime(gms[1]));
statement.setLong(11, gmTimes.getTime(gms[2]));
statement.setLong(12, gmTimes.getTime(gms[3]));
statement.addBatch();
}
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class TPSQueries method fetchTPSDataOfAllServersBut.
public static Query<Map<ServerUUID, List<TPS>>> fetchTPSDataOfAllServersBut(long after, long before, ServerUUID leaveOut) {
String sql = SELECT + '*' + FROM + TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID + '=' + SERVER_ID + WHERE + ServerTable.SERVER_UUID + "!=?" + AND + ServerTable.INSTALLED + "=?" + AND + DATE + "<?" + AND + DATE + ">?";
return new QueryStatement<Map<ServerUUID, List<TPS>>>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
if (leaveOut != null) {
statement.setString(1, leaveOut.toString());
} else {
statement.setNull(1, Types.VARCHAR);
}
statement.setBoolean(2, true);
statement.setLong(3, before);
statement.setLong(4, after);
}
@Override
public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, List<TPS>> byServer = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
List<TPS> ofServer = byServer.computeIfAbsent(serverUUID, Lists::create);
ofServer.add(extractTPS(set));
}
return byServer;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class BukkitImporter method processUserData.
private void processUserData() {
List<UserImportData> userImportData = getUserImportData();
if (userImportData == null || userImportData.isEmpty()) {
return;
}
BukkitUserImportRefiner userImportRefiner = new BukkitUserImportRefiner(userImportData);
userImportData = userImportRefiner.refineData();
Database db = dbSystem.getDatabase();
Set<UUID> existingUUIDs = db.query(UserIdentifierQueries.fetchAllPlayerUUIDs());
Set<UUID> existingUserInfoTableUUIDs = db.query(UserIdentifierQueries.fetchPlayerUUIDsOfServer(serverUUID.get()));
Map<UUID, BaseUser> users = new HashMap<>();
List<UserInfo> userInfo = new ArrayList<>();
Map<UUID, List<Nickname>> nickNames = new HashMap<>();
List<FinishedSession> sessions = new ArrayList<>();
Map<UUID, List<GeoInfo>> geoInfo = new HashMap<>();
userImportData.parallelStream().forEach(data -> {
UUID uuid = data.getUuid();
if (!existingUUIDs.contains(uuid)) {
users.put(uuid, toBaseUser(data));
}
if (!existingUserInfoTableUUIDs.contains(uuid)) {
userInfo.add(toUserInfo(data));
}
nickNames.put(uuid, data.getNicknames());
geoInfo.put(uuid, convertGeoInfo(data));
sessions.add(toSession(data));
});
db.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(LargeStoreQueries.storeAllCommonUserInformation(users.values()));
execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
Map<ServerUUID, List<UserInfo>> userInformation = Collections.singletonMap(serverUUID.get(), userInfo);
execute(LargeStoreQueries.storePerServerUserInformation(userInformation));
execute(LargeStoreQueries.storeAllNicknameData(Collections.singletonMap(serverUUID.get(), nickNames)));
execute(LargeStoreQueries.storeAllGeoInformation(geoInfo));
}
});
}
Aggregations