Search in sources :

Example 86 with Database

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);
}
Also used : Database(com.djrapitops.plan.storage.database.Database)

Example 87 with 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;
}
Also used : Database(com.djrapitops.plan.storage.database.Database)

Example 88 with Database

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));
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Database(com.djrapitops.plan.storage.database.Database)

Example 89 with Database

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;
}
Also used : Database(com.djrapitops.plan.storage.database.Database) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Example 90 with Database

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);
}
Also used : DateObj(com.djrapitops.plan.delivery.domain.DateObj) Ping(com.djrapitops.plan.gathering.domain.Ping) Database(com.djrapitops.plan.storage.database.Database) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

Database (com.djrapitops.plan.storage.database.Database)90 ServerUUID (com.djrapitops.plan.identification.ServerUUID)18 HashMap (java.util.HashMap)18 StoreIconTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction)12 ProviderInformation (com.djrapitops.plan.extension.implementation.ProviderInformation)11 UUID (java.util.UUID)10 StoreProviderTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction)9 DBSystem (com.djrapitops.plan.storage.database.DBSystem)9 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)7 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)7 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)6 ServerName (com.djrapitops.plan.delivery.domain.ServerName)6 Point (com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 ServerInfo (com.djrapitops.plan.identification.ServerInfo)6 InetAddress (java.net.InetAddress)6 Inject (javax.inject.Inject)6 DateObj (com.djrapitops.plan.delivery.domain.DateObj)5 LineGraphFactory (com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory)5 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)5