Search in sources :

Example 1 with ExecStatement

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

the class SessionQueriesTest method worldTimesAreSavedWithSessionWithoutWorlds.

@Test
default void worldTimesAreSavedWithSessionWithoutWorlds() {
    prepareForSessionSave();
    // Remove the worlds from the database so that they need to also be saved.
    execute(new ExecStatement("DELETE FROM " + WorldTable.TABLE_NAME) {

        @Override
        public void prepare(PreparedStatement statement) {
        // Nothing needed
        }
    });
    WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
    session.getExtraData().put(WorldTimes.class, worldTimes);
    List<FinishedSession> sessions = new ArrayList<>();
    sessions.add(session);
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
    assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
}
Also used : PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PreparedStatement(java.sql.PreparedStatement) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 2 with ExecStatement

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

the class RemoveOldExtensionsTransaction method removeProviders.

private void removeProviders() {
    execute(new ExecStatement(DELETE_FROM + ExtensionProviderTable.TABLE_NAME + WHERE + ExtensionProviderTable.PLUGIN_ID + " IN (" + SELECT + ExtensionPluginTable.ID + FROM + ExtensionPluginTable.TABLE_NAME + WHERE + ExtensionPluginTable.LAST_UPDATED + "<?" + AND + ExtensionPluginTable.SERVER_UUID + "=?)") {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setLong(1, deleteOlder);
            statement.setString(2, serverUUID.toString());
        }
    });
    execute(new ExecStatement(DELETE_FROM + ExtensionTableProviderTable.TABLE_NAME + WHERE + ExtensionTableProviderTable.PLUGIN_ID + " IN (" + SELECT + ExtensionPluginTable.ID + FROM + ExtensionPluginTable.TABLE_NAME + WHERE + ExtensionPluginTable.LAST_UPDATED + "<?" + AND + ExtensionPluginTable.SERVER_UUID + "=?)") {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setLong(1, deleteOlder);
            statement.setString(2, serverUUID.toString());
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement)

Example 3 with ExecStatement

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

the class CookieChangeTransaction method performOperations.

@Override
protected void performOperations() {
    if (username == null) {
        execute(new ExecStatement(CookieTable.DELETE_ALL_STATEMENT) {

            @Override
            public void prepare(PreparedStatement statement) {
            // No parameters
            }
        });
    } else if (cookie == null) {
        execute(new ExecStatement(CookieTable.DELETE_BY_USER_STATEMENT) {

            @Override
            public void prepare(PreparedStatement statement) throws SQLException {
                statement.setString(1, username);
            }
        });
        // Perform cleanup at the same time
        execute(new ExecStatement(CookieTable.DELETE_OLDER_STATEMENT) {

            @Override
            public void prepare(PreparedStatement statement) throws SQLException {
                statement.setLong(1, System.currentTimeMillis());
            }
        });
    } else {
        execute(new ExecStatement(CookieTable.INSERT_STATEMENT) {

            @Override
            public void prepare(PreparedStatement statement) throws SQLException {
                statement.setString(1, username);
                statement.setString(2, cookie);
                statement.setLong(3, expires);
            }
        });
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement)

Example 4 with ExecStatement

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

the class ServerIsProxyPatch method applyPatch.

@Override
protected void applyPatch() {
    addColumn(ServerTable.TABLE_NAME, ServerTable.PROXY + ' ' + Sql.BOOL + " DEFAULT 0");
    String populateFieldSql = "UPDATE " + ServerTable.TABLE_NAME + " SET " + ServerTable.PROXY + "=?" + WHERE + ServerTable.NAME + "=?";
    execute(new ExecStatement(populateFieldSql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setBoolean(1, true);
            statement.setString(2, "BungeeCord");
        }
    });
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement)

Example 5 with ExecStatement

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

the class UserInfoHostnameAllowNullPatch method applyPatch.

@Override
protected void applyPatch() {
    tempOldTable();
    execute(UserInfoTable.createTableSQL(dbType));
    execute(new ExecStatement("INSERT INTO " + tableName + " (" + UserInfoTable.ID + ',' + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID + ',' + UserInfoTable.REGISTERED + ',' + UserInfoTable.OP + ',' + UserInfoTable.BANNED + ',' + UserInfoTable.JOIN_ADDRESS + ") SELECT " + UserInfoTable.ID + ',' + UserInfoTable.USER_UUID + ',' + UserInfoTable.SERVER_UUID + ',' + UserInfoTable.REGISTERED + ',' + UserInfoTable.OP + ',' + UserInfoTable.BANNED + ',' + "?" + FROM + tempTableName) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setNull(1, Types.VARCHAR);
        }
    });
    dropTable(tempTableName);
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement)

Aggregations

ExecStatement (com.djrapitops.plan.storage.database.transactions.ExecStatement)11 PreparedStatement (java.sql.PreparedStatement)11 SQLException (java.sql.SQLException)9 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)1 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)1 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)1 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)1 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)1 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1 Test (org.junit.jupiter.api.Test)1