mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 09:00:28 +08:00
Refactored ServerTable#getServerNames to a query
This commit is contained in:
parent
240b6cb29e
commit
817d157065
@ -17,7 +17,9 @@
|
||||
package com.djrapitops.plan.db.access.queries.objects;
|
||||
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.Select;
|
||||
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
@ -112,4 +114,22 @@ public class ServerQueries {
|
||||
public static Query<Optional<Server>> fetchProxyServerInformation() {
|
||||
return db -> db.query(fetchServerMatchingIdentifier("BungeeCord"));
|
||||
}
|
||||
|
||||
public static Query<Map<UUID, String>> fetchServerNames() {
|
||||
String sql = Select.from(ServerTable.TABLE_NAME,
|
||||
ServerTable.SERVER_UUID, ServerTable.NAME)
|
||||
.toString();
|
||||
|
||||
return new QueryAllStatement<Map<UUID, String>>(sql) {
|
||||
@Override
|
||||
public Map<UUID, String> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, String> names = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(ServerTable.SERVER_UUID));
|
||||
names.put(serverUUID, set.getString(ServerTable.NAME));
|
||||
}
|
||||
return names;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -18,16 +18,9 @@ package com.djrapitops.plan.db.sql.tables;
|
||||
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.sql.parsing.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Table for managing multiple server's data in the database.
|
||||
* <p>
|
||||
@ -82,22 +75,4 @@ public class ServerTable extends Table {
|
||||
.column(MAX_PLAYERS, Sql.INT).notNull().defaultValue("-1")
|
||||
.toString();
|
||||
}
|
||||
|
||||
public Map<UUID, String> getServerNames() {
|
||||
String sql = Select.from(tableName,
|
||||
SERVER_UUID, NAME)
|
||||
.toString();
|
||||
|
||||
return query(new QueryAllStatement<Map<UUID, String>>(sql) {
|
||||
@Override
|
||||
public Map<UUID, String> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, String> names = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(SERVER_UUID));
|
||||
names.put(serverUUID, set.getString(NAME));
|
||||
}
|
||||
return names;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
|
||||
@Override
|
||||
public Map<UUID, String> getServerNames() {
|
||||
return serverTable.getServerNames();
|
||||
return db.query(ServerQueries.fetchServerNames());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,7 @@ import com.djrapitops.plan.api.exceptions.ParseException;
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.container.BaseUser;
|
||||
import com.djrapitops.plan.db.access.queries.objects.BaseUserQueries;
|
||||
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
@ -149,7 +150,7 @@ public class HtmlExport extends SpecificExport {
|
||||
|
||||
public void exportAvailableServerPages() {
|
||||
try {
|
||||
Map<UUID, String> serverNames = dbSystem.getDatabase().fetch().getServerNames();
|
||||
Map<UUID, String> serverNames = dbSystem.getDatabase().query(ServerQueries.fetchServerNames());
|
||||
|
||||
for (Map.Entry<UUID, String> entry : serverNames.entrySet()) {
|
||||
exportAvailableServerPage(entry.getKey(), entry.getValue());
|
||||
|
@ -22,6 +22,7 @@ import com.djrapitops.plan.data.store.containers.NetworkContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.queries.containers.ContainerFetchQueries;
|
||||
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
@ -132,7 +133,7 @@ public class PageFactory {
|
||||
public InspectPage inspectPage(UUID uuid) {
|
||||
Database db = dbSystem.get().getDatabase();
|
||||
PlayerContainer player = db.query(ContainerFetchQueries.fetchPlayerContainer(uuid));
|
||||
Map<UUID, String> serverNames = db.fetch().getServerNames();
|
||||
Map<UUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
|
||||
return new InspectPage(
|
||||
player, serverNames,
|
||||
versionCheckSystem.get(),
|
||||
|
Loading…
Reference in New Issue
Block a user