mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 09:00:28 +08:00
Split PlayerFetchQueries from OptionalFetchQueries
This commit is contained in:
parent
cb22c0f80a
commit
00c2c56717
@ -23,7 +23,6 @@ import com.djrapitops.plan.db.access.QueryStatement;
|
|||||||
import com.djrapitops.plan.db.sql.tables.SecurityTable;
|
import com.djrapitops.plan.db.sql.tables.SecurityTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.TPSTable;
|
import com.djrapitops.plan.db.sql.tables.TPSTable;
|
||||||
import com.djrapitops.plan.db.sql.tables.UsersTable;
|
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
import com.djrapitops.plan.system.info.server.Server;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
|
||||||
@ -80,26 +79,6 @@ public class OptionalFetchQueries {
|
|||||||
return db -> db.query(fetchMatchingServerIdentifier("BungeeCord"));
|
return db -> db.query(fetchMatchingServerIdentifier("BungeeCord"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query<Optional<String>> playerUserName(UUID playerUUID) {
|
|
||||||
String sql = "SELECT " + UsersTable.USER_NAME +
|
|
||||||
" FROM " + UsersTable.TABLE_NAME +
|
|
||||||
" WHERE " + UsersTable.USER_UUID + "=?";
|
|
||||||
return new QueryStatement<Optional<String>>(sql) {
|
|
||||||
@Override
|
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
|
||||||
statement.setString(1, playerUUID.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<String> processResults(ResultSet set) throws SQLException {
|
|
||||||
if (set.next()) {
|
|
||||||
return Optional.of(set.getString(UsersTable.USER_NAME));
|
|
||||||
}
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Query<Optional<WebUser>> fetchWebUser(String called) {
|
public static Query<Optional<WebUser>> fetchWebUser(String called) {
|
||||||
String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME +
|
String sql = "SELECT * FROM " + SecurityTable.TABLE_NAME +
|
||||||
" WHERE " + SecurityTable.USERNAME + "=? LIMIT 1";
|
" WHERE " + SecurityTable.USERNAME + "=? LIMIT 1";
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Player Analytics (Plan).
|
||||||
|
*
|
||||||
|
* Plan is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Plan is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.djrapitops.plan.db.access.queries;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.db.access.Query;
|
||||||
|
import com.djrapitops.plan.db.access.QueryStatement;
|
||||||
|
import com.djrapitops.plan.db.sql.tables.UsersTable;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static method class for queries that return information related to a single player.
|
||||||
|
*
|
||||||
|
* @author Rsl1122
|
||||||
|
*/
|
||||||
|
public class PlayerFetchQueries {
|
||||||
|
|
||||||
|
private PlayerFetchQueries() {
|
||||||
|
/* static method class */
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Query<Optional<String>> playerUserName(UUID playerUUID) {
|
||||||
|
String sql = "SELECT " + UsersTable.USER_NAME +
|
||||||
|
" FROM " + UsersTable.TABLE_NAME +
|
||||||
|
" WHERE " + UsersTable.USER_UUID + "=?";
|
||||||
|
return new QueryStatement<Optional<String>>(sql) {
|
||||||
|
@Override
|
||||||
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
|
statement.setString(1, playerUUID.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<String> processResults(ResultSet set) throws SQLException {
|
||||||
|
if (set.next()) {
|
||||||
|
return Optional.of(set.getString(UsersTable.USER_NAME));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@
|
|||||||
package com.djrapitops.plan.db.access.transactions;
|
package com.djrapitops.plan.db.access.transactions;
|
||||||
|
|
||||||
import com.djrapitops.plan.db.access.ExecStatement;
|
import com.djrapitops.plan.db.access.ExecStatement;
|
||||||
import com.djrapitops.plan.db.access.queries.OptionalFetchQueries;
|
import com.djrapitops.plan.db.access.queries.PlayerFetchQueries;
|
||||||
import com.djrapitops.plan.db.sql.tables.*;
|
import com.djrapitops.plan.db.sql.tables.*;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -44,7 +44,7 @@ public class RemovePlayerTransaction extends Transaction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void performOperations() {
|
protected void performOperations() {
|
||||||
query(OptionalFetchQueries.playerUserName(playerUUID)).ifPresent(this::deleteWebUser);
|
query(PlayerFetchQueries.playerUserName(playerUUID)).ifPresent(this::deleteWebUser);
|
||||||
|
|
||||||
deleteFromTable(GeoInfoTable.TABLE_NAME);
|
deleteFromTable(GeoInfoTable.TABLE_NAME);
|
||||||
deleteFromTable(NicknamesTable.TABLE_NAME);
|
deleteFromTable(NicknamesTable.TABLE_NAME);
|
||||||
|
Loading…
Reference in New Issue
Block a user