use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ServerShutdownSave method saveActiveSessions.
private Future<?> saveActiveSessions(Collection<FinishedSession> finishedSessions) {
Database database = dbSystem.getDatabase();
if (database.getState() == Database.State.CLOSED) {
// Ensure that database is not closed when performing the transaction.
startedDatabase = true;
database.init();
}
return saveSessions(finishedSessions, database);
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PluginBooleanGroupFilter method getOptionList.
private List<String> getOptionList() {
Database database = dbSystem.getDatabase();
List<PluginBooleanOption> pluginBooleanOptions = database.query(pluginBooleanOptionsQuery());
List<String> options = new ArrayList<>();
for (PluginBooleanOption pluginBooleanOption : pluginBooleanOptions) {
String names = pluginBooleanOption.format();
options.add(names + ": true");
options.add(names + ": false");
}
return options;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class PluginBooleanGroupFilter method getMatchingUUIDs.
@Override
public Set<UUID> getMatchingUUIDs(InputFilterDto query) {
Map<PluginBooleanOption, SelectedBoolean> selectedBooleanOptions = new HashMap<>();
for (String selected : getSelected(query)) {
String[] optionAndBoolean = StringUtils.split(selected, ":", 2);
PluginBooleanOption pluginBooleanOption = PluginBooleanOption.parse(optionAndBoolean[0].trim());
String selectedBoolean = optionAndBoolean[1].trim().toUpperCase();
selectedBooleanOptions.computeIfPresent(pluginBooleanOption, (key, existing) -> SelectedBoolean.BOTH);
selectedBooleanOptions.computeIfAbsent(pluginBooleanOption, key -> SelectedBoolean.valueOf(selectedBoolean));
}
Database db = dbSystem.getDatabase();
Map<String, ServerUUID> namesToUUIDs = db.query(ServerQueries.fetchServerNamesToUUIDs());
return db.query(playersInGroups(selectedBooleanOptions, namesToUUIDs));
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GeolocationQueriesTest method storeSpecificGeolocations.
default UUID[] storeSpecificGeolocations() {
UUID firstUuid = UUID.randomUUID();
UUID secondUuid = UUID.randomUUID();
UUID thirdUuid = UUID.randomUUID();
UUID fourthUuid = UUID.randomUUID();
UUID fifthUuid = UUID.randomUUID();
UUID sixthUuid = UUID.randomUUID();
UUID[] uuids = { firstUuid, secondUuid, thirdUuid, fourthUuid, fifthUuid, sixthUuid };
Database db = db();
for (UUID uuid : uuids) {
db.executeTransaction(new PlayerServerRegisterTransaction(uuid, () -> 0L, "", serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
}
save(firstUuid, new GeoInfo("Norway", 0));
save(firstUuid, new GeoInfo("Finland", 5));
save(secondUuid, new GeoInfo("Sweden", 0));
save(thirdUuid, new GeoInfo("Denmark", 0));
save(fourthUuid, new GeoInfo("Denmark", 0));
save(fifthUuid, new GeoInfo("Not Known", 0));
save(sixthUuid, new GeoInfo("Local Machine", 0));
return uuids;
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GeolocationQueriesTest method pingIsGroupedByGeolocationAppropriately.
@Test
default void pingIsGroupedByGeolocationAppropriately() {
UUID[] uuids = storeSpecificGeolocations();
Database db = db();
long time = System.currentTimeMillis();
List<DateObj<Integer>> ping = Collections.singletonList(new DateObj<>(time, 5));
for (UUID uuid : uuids) {
db.executeTransaction(new PingStoreTransaction(uuid, serverUUID(), ping));
}
Map<String, Ping> got = db.query(PingQueries.fetchPingDataOfServerByGeolocation(serverUUID()));
Map<String, Ping> expected = new HashMap<>();
// first user has a more recent connection from Finland so their country should be counted as Finland.
Ping expectedPing = new Ping(time, serverUUID(), 5, 5, 5);
expected.put("Finland", expectedPing);
expected.put("Sweden", expectedPing);
expected.put("Not Known", expectedPing);
expected.put("Local Machine", expectedPing);
expected.put("Denmark", expectedPing);
assertEquals(expected, got);
}
Aggregations