Search in sources :

Example 41 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class DataValueGatherer method storeNumber.

private void storeNumber(Parameters parameters, Conditions conditions, NumberDataValue data) {
    ProviderInformation information = data.getInformation();
    Long value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    db.executeTransaction(new StoreIconTransaction(information.getIcon()));
    db.executeTransaction(new StoreProviderTransaction(information, parameters));
    db.executeTransaction(new StoreServerNumberResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) StoreProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreProviderTransaction) Database(com.djrapitops.plan.storage.database.Database) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation)

Example 42 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class DataValueGatherer method storePlayerTable.

private void storePlayerTable(Parameters parameters, Conditions conditions, TableDataValue data) {
    ProviderInformation information = data.getInformation();
    Table value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    for (Icon icon : value.getIcons()) {
        if (icon != null)
            db.executeTransaction(new StoreIconTransaction(icon));
    }
    db.executeTransaction(new StoreTableProviderTransaction(information, parameters, value));
    db.executeTransaction(new StorePlayerTableResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) Table(com.djrapitops.plan.extension.table.Table) Database(com.djrapitops.plan.storage.database.Database) Icon(com.djrapitops.plan.extension.icon.Icon) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation) StoreTableProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction)

Example 43 with Database

use of com.djrapitops.plan.storage.database.Database 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));
        }
    });
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) BukkitUserImportRefiner(com.djrapitops.plan.gathering.importing.data.BukkitUserImportRefiner) UserImportData(com.djrapitops.plan.gathering.importing.data.UserImportData)

Example 44 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class PlayerOnlineListener method actOnLogin.

private void actOnLogin(PostLoginEvent event) {
    ProxiedPlayer player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    InetAddress address = player.getAddress().getAddress();
    long time = System.currentTimeMillis();
    ActiveSession session = new ActiveSession(playerUUID, serverInfo.getServerUUID(), time, null, null);
    session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
    session.getExtraData().put(ServerName.class, new ServerName("Proxy Server"));
    sessionCache.cacheSession(playerUUID, session);
    Database database = dbSystem.getDatabase();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerName(com.djrapitops.plan.delivery.domain.ServerName) Database(com.djrapitops.plan.storage.database.Database) GeoInfoStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 45 with Database

use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.

the class JSONFactory method networkSessionsAsJSONMap.

public List<Map<String, Object>> networkSessionsAsJSONMap() {
    Database db = dbSystem.getDatabase();
    Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
    List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessions(perPageLimit));
    // Add online sessions
    if (serverInfo.getServer().isProxy()) {
        addActiveSessions(sessions);
        sessions.sort(new SessionStartComparator());
        while (true) {
            int size = sessions.size();
            if (size <= perPageLimit)
                break;
            // Remove last until it fits.
            sessions.remove(size - 1);
        }
    }
    List<Map<String, Object>> sessionMaps = new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
    // Add network_server property so that sessions have a server page link
    sessionMaps.forEach(map -> map.put("network_server", map.get("server_name")));
    return sessionMaps;
}
Also used : Database(com.djrapitops.plan.storage.database.Database) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)

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