use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DBPatchMySQLRegressionTest method dropAllTables.
private void dropAllTables() {
String dbName = System.getenv(CIProperties.MYSQL_DATABASE);
underTest.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute("DROP DATABASE " + dbName);
execute("CREATE DATABASE " + dbName);
execute("USE " + dbName);
}
});
}
use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DBPatchMySQLRegressionTest method setUpDBWithOldSchema.
@BeforeEach
void setUpDBWithOldSchema() {
Optional<Database> db = dbPreparer.prepareMySQL();
assumeTrue(db.isPresent());
underTest = (MySQLDB) db.get();
dropAllTables();
// Initialize database with the old table schema
underTest.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(serverTable);
execute(usersTable);
execute(userInfoTable);
execute(geoInfoTable);
execute(nicknameTable);
execute(sessionsTable);
execute(killsTable);
execute(pingTable);
execute(commandUseTable);
execute(tpsTable);
execute(worldsTable);
execute(worldTimesTable);
execute(securityTable);
execute(transferTable);
}
});
underTest.executeTransaction(new CreateTablesTransaction());
insertData(underTest);
}
use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DBPatchSQLiteRegressionTest method setUpDBWithOldSchema.
@BeforeEach
void setUpDBWithOldSchema(@TempDir Path tempDir) throws Exception {
component = new PluginMockComponent(tempDir);
underTest = this.component.getPlanSystem().getDatabaseSystem().getSqLiteFactory().usingFileCalled("test");
underTest.setTransactionExecutorServiceProvider(MoreExecutors::newDirectExecutorService);
underTest.init();
// Initialize database with the old table schema
dropAllTables(underTest);
underTest.executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(serverTable);
execute(usersTable);
execute(userInfoTable);
execute(geoInfoTable);
execute(nicknameTable);
execute(sessionsTable);
execute(killsTable);
execute(pingTable);
execute(commandUseTable);
execute(tpsTable);
execute(worldsTable);
execute(worldTimesTable);
execute(securityTable);
execute(transferTable);
}
});
underTest.executeTransaction(new CreateTablesTransaction());
insertData(underTest);
}
use of com.djrapitops.plan.storage.database.transactions.Transaction in project Plan by plan-player-analytics.
the class DatabaseTest method indexCreationWorksWithoutErrors.
@Test
default void indexCreationWorksWithoutErrors() throws Exception {
Transaction transaction = new CreateIndexTransaction();
// get to ensure transaction is finished
db().executeTransaction(transaction).get();
assertTrue(transaction.wasSuccessful());
}
use of com.djrapitops.plan.storage.database.transactions.Transaction 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));
}
});
}
Aggregations