Search in sources :

Example 1 with StoreConfigTransaction

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

the class ServerSettingsManager method updateConfigInDB.

private void updateConfigInDB(File file) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
    if (!serverUUID.isPresent()) {
        return;
    }
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config read = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID.get(), read, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) ConfigReader(com.djrapitops.plan.settings.config.ConfigReader) Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with StoreConfigTransaction

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

the class ConfigStoreTask method run.

@Override
public void run() {
    long lastModified = files.getConfigFile().lastModified();
    dbSystem.getDatabase().executeTransaction(new StoreConfigTransaction(serverInfo.getServerUUID(), config, lastModified));
    cancel();
}
Also used : StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction)

Example 3 with StoreConfigTransaction

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

the class NetworkSettingManager method updateConfigInDB.

public void updateConfigInDB(File file, ServerUUID serverUUID) {
    if (!file.exists()) {
        return;
    }
    Database database = dbSystem.getDatabase();
    try (ConfigReader reader = new ConfigReader(file.toPath())) {
        Config config = reader.read();
        database.executeTransaction(new StoreConfigTransaction(serverUUID, config, file.lastModified()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Database(com.djrapitops.plan.storage.database.Database) UncheckedIOException(java.io.UncheckedIOException) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 4 with StoreConfigTransaction

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

the class DatabaseTest method configIsStoredInTheDatabase.

@Test
default void configIsStoredInTheDatabase() {
    PlanConfig config = config();
    db().executeTransaction(new StoreConfigTransaction(serverUUID(), config, System.currentTimeMillis()));
    Optional<Config> foundConfig = db().query(new NewerConfigQuery(serverUUID(), 0));
    assertTrue(foundConfig.isPresent());
    assertEquals(config, foundConfig.get());
}
Also used : PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Config(com.djrapitops.plan.settings.config.Config) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Example 5 with StoreConfigTransaction

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

the class DatabaseTest method unchangedConfigDoesNotUpdateInDatabase.

@Test
default void unchangedConfigDoesNotUpdateInDatabase() {
    configIsStoredInTheDatabase();
    long savedMs = System.currentTimeMillis();
    PlanConfig config = config();
    db().executeTransaction(new StoreConfigTransaction(serverUUID(), config, System.currentTimeMillis()));
    assertFalse(db().query(new NewerConfigQuery(serverUUID(), savedMs)).isPresent());
}
Also used : StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) Test(org.junit.jupiter.api.Test)

Aggregations

StoreConfigTransaction (com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction)5 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 Config (com.djrapitops.plan.settings.config.Config)2 Database (com.djrapitops.plan.storage.database.Database)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 Test (org.junit.jupiter.api.Test)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 ConfigReader (com.djrapitops.plan.settings.config.ConfigReader)1