mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-05 15:02:26 +01:00
Refactored ServerTable#getBungeeInfo to a query:
This commit is contained in:
parent
062ab088b3
commit
606844c92d
@ -20,6 +20,7 @@ import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
@ -48,7 +49,7 @@ public class OptionalFetchQueries {
|
||||
return new QueryStatement<Optional<Server>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, identifier);
|
||||
statement.setInt(1, NumberUtils.isParsable(identifier) ? Integer.parseInt(identifier) : -1);
|
||||
statement.setString(2, identifier);
|
||||
statement.setString(3, identifier);
|
||||
statement.setBoolean(4, true);
|
||||
@ -70,4 +71,8 @@ public class OptionalFetchQueries {
|
||||
};
|
||||
}
|
||||
|
||||
public static Query<Optional<Server>> proxyServerInformation() {
|
||||
return db -> db.query(matchingServerIdentifier("BungeeCord"));
|
||||
}
|
||||
|
||||
}
|
@ -205,38 +205,6 @@ public class ServerTable extends Table {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to get BungeeCord WebServer info if present.
|
||||
*
|
||||
* @return information about Bungee server.
|
||||
*/
|
||||
public Optional<Server> getBungeeInfo() {
|
||||
String sql = Select.from(tableName, "*")
|
||||
.where(Col.NAME + "=?")
|
||||
.toString();
|
||||
|
||||
return query(new QueryStatement<Optional<Server>>(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, "BungeeCord");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Server> processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return Optional.of(new Server(
|
||||
set.getInt(Col.SERVER_ID.get()),
|
||||
UUID.fromString(set.getString(Col.SERVER_UUID.get())),
|
||||
set.getString(Col.NAME.get()),
|
||||
set.getString(Col.WEBSERVER_ADDRESS.get()),
|
||||
set.getInt(Col.MAX_PLAYERS.get())));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<UUID> getServerUUIDs() {
|
||||
String sql = Select.from(tableName, Col.SERVER_UUID)
|
||||
.toString();
|
||||
|
@ -27,6 +27,7 @@ import com.djrapitops.plan.db.sql.parsing.Column;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
import com.djrapitops.plan.db.sql.parsing.TableSqlParser;
|
||||
import com.djrapitops.plan.db.sql.queries.single.OptionalFetchQueries;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
@ -266,11 +267,11 @@ public class TPSTable extends Table {
|
||||
}
|
||||
|
||||
public List<TPS> getNetworkOnlineData() {
|
||||
Optional<Server> bungeeInfo = serverTable.getBungeeInfo();
|
||||
if (!bungeeInfo.isPresent()) {
|
||||
Optional<Server> proxyInfo = db.query(OptionalFetchQueries.proxyServerInformation());
|
||||
if (!proxyInfo.isPresent()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
UUID bungeeUUID = bungeeInfo.get().getUuid();
|
||||
UUID bungeeUUID = proxyInfo.get().getUuid();
|
||||
|
||||
String sql = "SELECT " +
|
||||
Col.DATE + ", " +
|
||||
|
@ -28,6 +28,7 @@ import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries;
|
||||
import com.djrapitops.plan.db.sql.queries.single.OptionalFetchQueries;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.databases.operation.FetchOperations;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
@ -54,12 +55,12 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
}
|
||||
|
||||
private ServerContainer getBungeeServerContainer() {
|
||||
Optional<Server> bungeeInfo = serverTable.getBungeeInfo();
|
||||
if (!bungeeInfo.isPresent()) {
|
||||
Optional<Server> proxyInformation = db.query(OptionalFetchQueries.proxyServerInformation());
|
||||
if (!proxyInformation.isPresent()) {
|
||||
return new ServerContainer();
|
||||
}
|
||||
|
||||
ServerContainer container = getServerContainer(bungeeInfo.get().getUuid());
|
||||
ServerContainer container = getServerContainer(proxyInformation.get().getUuid());
|
||||
container.putCachingSupplier(ServerKeys.PLAYERS, this::getAllPlayerContainers);
|
||||
container.putCachingSupplier(ServerKeys.TPS, tpsTable::getNetworkOnlineData);
|
||||
container.putSupplier(ServerKeys.WORLD_TIMES, null); // Additional Session information not supported
|
||||
@ -458,7 +459,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
|
||||
@Override
|
||||
public Optional<Server> getBungeeInformation() {
|
||||
return serverTable.getBungeeInfo();
|
||||
return db.query(OptionalFetchQueries.proxyServerInformation());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.db;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries;
|
||||
import com.djrapitops.plan.db.sql.queries.single.OptionalFetchQueries;
|
||||
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import org.junit.BeforeClass;
|
||||
@ -56,7 +57,7 @@ public class SQLiteTest extends CommonDBTest {
|
||||
public void testServerTableBungeeSave() throws DBInitException {
|
||||
ServerTable serverTable = db.getServerTable();
|
||||
|
||||
Optional<Server> bungeeInfo = serverTable.getBungeeInfo();
|
||||
Optional<Server> bungeeInfo = db.query(OptionalFetchQueries.proxyServerInformation());
|
||||
assertFalse(bungeeInfo.isPresent());
|
||||
|
||||
UUID bungeeUUID = UUID.randomUUID();
|
||||
@ -67,7 +68,7 @@ public class SQLiteTest extends CommonDBTest {
|
||||
|
||||
bungeeCord.setId(2);
|
||||
|
||||
bungeeInfo = serverTable.getBungeeInfo();
|
||||
bungeeInfo = db.query(OptionalFetchQueries.proxyServerInformation());
|
||||
assertTrue(bungeeInfo.isPresent());
|
||||
assertEquals(bungeeCord, bungeeInfo.get());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user