use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DatabaseTest method registerDateIsMinimized.
@Test
default void registerDateIsMinimized() {
executeTransactions(new PlayerServerRegisterTransaction(playerUUID, () -> 1000, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME), new Transaction() {
@Override
protected void performOperations() {
execute("UPDATE " + UserInfoTable.TABLE_NAME + " SET " + UserInfoTable.REGISTERED + "=0" + WHERE + UserInfoTable.USER_UUID + "='" + playerUUID + "'");
}
});
// Check test assumptions
Map<UUID, Long> registerDates = db().query(UserInfoQueries.fetchRegisterDates(0L, System.currentTimeMillis(), serverUUID()));
assertEquals(0L, registerDates.get(playerUUID));
Optional<BaseUser> baseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
assertEquals(1000L, baseUser.isPresent() ? baseUser.get().getRegistered() : null);
RegisterDateMinimizationPatch testedPatch = new RegisterDateMinimizationPatch();
executeTransactions(testedPatch);
// Test expected result
Optional<BaseUser> updatedBaseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
assertEquals(0L, updatedBaseUser.isPresent() ? updatedBaseUser.get().getRegistered() : null);
assertTrue(testedPatch.isApplied());
}
use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DBPreparer method prepareMySQL.
public Optional<Database> prepareMySQL() {
PlanConfig config = dependencies.config();
Optional<String> formattedDB = setUpMySQLSettings(config);
if (formattedDB.isPresent()) {
String formattedDatabase = formattedDB.get();
SQLDB mysql = prepareDBByName(DBType.MYSQL.getName());
mysql.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute("DROP DATABASE " + formattedDatabase);
execute("CREATE DATABASE " + formattedDatabase);
execute("USE " + formattedDatabase);
}
});
return Optional.of(mysql);
}
return Optional.empty();
}
use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class SessionQueriesTest method worldTimesAreSavedWithAllSessionSave.
@Test
default void worldTimesAreSavedWithAllSessionSave() {
prepareForSessionSave();
WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
session.getExtraData().put(WorldTimes.class, worldTimes);
List<FinishedSession> sessions = Collections.singletonList(session);
db().executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
}
});
Map<ServerUUID, WorldTimes> saved = db().query(WorldTimesQueries.fetchPlayerWorldTimesOnServers(playerUUID));
WorldTimes savedWorldTimes = saved.get(serverUUID());
assertEquals(worldTimes, savedWorldTimes);
}
Aggregations