Search in sources :

Example 16 with Database

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

the class DatabaseCommands method onHotswap.

public void onHotswap(CMDSender sender, Arguments arguments) {
    DBType toDB = arguments.get(0).flatMap(DBType::getForName).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_INCORRECT_DB, arguments.get(0).orElse("<MySQL/SQLite>"))));
    try {
        Database database = dbSystem.getActiveDatabaseByType(toDB);
        database.init();
        if (database.getState() == Database.State.CLOSED) {
            return;
        }
        config.set(DatabaseSettings.TYPE, toDB.getName());
        config.save();
    } catch (DBOpException | IOException e) {
        errorLogger.warn(e, ErrorContext.builder().related(toDB).build());
        sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
        return;
    }
    statusCommands.onReload(sender);
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) Database(com.djrapitops.plan.storage.database.Database) DBType(com.djrapitops.plan.storage.database.DBType) IOException(java.io.IOException)

Example 17 with Database

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

the class DatabaseCommands method performBackup.

public void performBackup(CMDSender sender, Arguments arguments, String dbName, Database fromDB) {
    Database toDB = null;
    try {
        String timeStamp = timestamp.apply(System.currentTimeMillis());
        String fileName = dbName + "-backup-" + timeStamp;
        sender.send(locale.getString(CommandLang.DB_BACKUP_CREATE, fileName, dbName));
        toDB = sqliteFactory.usingFileCalled(fileName);
        toDB.init();
        toDB.executeTransaction(new BackupCopyTransaction(fromDB, toDB)).get();
    } catch (DBOpException | ExecutionException e) {
        errorLogger.error(e, ErrorContext.builder().related(sender, arguments).build());
    } catch (InterruptedException e) {
        toDB.close();
        Thread.currentThread().interrupt();
    } finally {
        if (toDB != null) {
            toDB.close();
        }
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) Database(com.djrapitops.plan.storage.database.Database) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Example 18 with Database

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

the class DatabaseCommands method performClear.

private void performClear(CMDSender sender, DBType fromDB) {
    try {
        Database fromDatabase = dbSystem.getActiveDatabaseByType(fromDB);
        fromDatabase.init();
        sender.send(locale.getString(CommandLang.DB_REMOVAL, fromDB.getName()));
        fromDatabase.executeTransaction(new RemoveEverythingTransaction()).get();
        queryService.dataCleared();
        sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
        // Reload plugin to register the server into the database
        // Otherwise errors will start.
        statusCommands.onReload(sender);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (DBOpException | ExecutionException e) {
        sender.send(locale.getString(CommandLang.PROGRESS_FAIL, e.getMessage()));
        errorLogger.error(e, ErrorContext.builder().related(sender, fromDB.getName()).build());
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) Database(com.djrapitops.plan.storage.database.Database) ExecutionException(java.util.concurrent.ExecutionException)

Example 19 with Database

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

the class PluginStatusCommands method onInfo.

public void onInfo(CMDSender sender) {
    String yes = locale.getString(GenericLang.YES);
    String no = locale.getString(GenericLang.NO);
    Database database = dbSystem.getDatabase();
    String updateAvailable = versionChecker.isNewVersionAvailable() ? yes : no;
    String proxyAvailable = database.query(ServerQueries.fetchProxyServerInformation()).isPresent() ? yes : no;
    String[] messages = { locale.getString(CommandLang.HEADER_INFO), "", locale.getString(CommandLang.INFO_VERSION, pluginInformation.getVersion()), locale.getString(CommandLang.INFO_UPDATE, updateAvailable), locale.getString(CommandLang.INFO_DATABASE, database.getType().getName() + " (" + database.getState().name() + ")"), locale.getString(CommandLang.INFO_PROXY_CONNECTION, proxyAvailable), "", ">" };
    sender.send(messages);
}
Also used : Database(com.djrapitops.plan.storage.database.Database)

Example 20 with Database

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

the class RegistrationCommands method registerUser.

private void registerUser(User user, CMDSender sender, int permissionLevel) {
    String username = user.getUsername();
    user.setPermissionLevel(permissionLevel);
    try {
        Database database = dbSystem.getDatabase();
        boolean userExists = database.query(WebUserQueries.fetchUser(username)).isPresent();
        if (userExists)
            throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_WEB_USER_EXISTS));
        database.executeTransaction(new RegisterWebUserTransaction(user)).get();
        sender.send(locale.getString(CommandLang.WEB_USER_REGISTER_SUCCESS, username));
        logger.info(locale.getString(CommandLang.WEB_USER_REGISTER_NOTIFY, username, permissionLevel));
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (DBOpException | ExecutionException e) {
        errorLogger.warn(e, ErrorContext.builder().related(sender, user, permissionLevel).build());
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) Database(com.djrapitops.plan.storage.database.Database) ExecutionException(java.util.concurrent.ExecutionException)

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