mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-03 01:10:17 +01:00
Refactored some methods in Extension queries
- Some Map management inside queries has now been delegated to QueriedTabData and QueriedTables to make the queries easier to read
This commit is contained in:
parent
9677de701a
commit
3afc168fec
@ -21,7 +21,7 @@ package com.djrapitops.plan.extension.implementation.results;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public interface ExtensionData {
|
||||
public interface DescribedExtensionData {
|
||||
|
||||
/**
|
||||
* Get Descriptive information about the data point.
|
@ -21,7 +21,7 @@ package com.djrapitops.plan.extension.implementation.results;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionBooleanData implements ExtensionData {
|
||||
public class ExtensionBooleanData implements DescribedExtensionData {
|
||||
|
||||
private ExtensionDescriptive descriptive;
|
||||
private boolean value;
|
||||
|
@ -23,7 +23,7 @@ import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionDoubleData implements ExtensionData {
|
||||
public class ExtensionDoubleData implements DescribedExtensionData {
|
||||
|
||||
private ExtensionDescriptive descriptive;
|
||||
private double value;
|
||||
|
@ -24,7 +24,7 @@ import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionNumberData implements ExtensionData {
|
||||
public class ExtensionNumberData implements DescribedExtensionData {
|
||||
|
||||
private final ExtensionDescriptive descriptive;
|
||||
private final FormatType formatType;
|
||||
|
@ -24,7 +24,7 @@ import com.djrapitops.plan.utilities.html.Html;
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ExtensionStringData implements ExtensionData {
|
||||
public class ExtensionStringData implements DescribedExtensionData {
|
||||
|
||||
private final ExtensionDescriptive descriptive;
|
||||
private final boolean playerName;
|
||||
|
@ -131,11 +131,11 @@ public class ExtensionTabData implements Comparable<ExtensionTabData> {
|
||||
}
|
||||
|
||||
private void createOrderingList() {
|
||||
booleanData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
doubleData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
percentageData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
numberData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
stringData.values().stream().map(ExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
booleanData.values().stream().map(DescribedExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
doubleData.values().stream().map(DescribedExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
percentageData.values().stream().map(DescribedExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
numberData.values().stream().map(DescribedExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
stringData.values().stream().map(DescribedExtensionData::getDescriptive).forEach(descriptives::add);
|
||||
|
||||
order = descriptives.stream().sorted()
|
||||
.map(ExtensionDescriptive::getName)
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.extension.implementation.results.server.ExtensionServ
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -117,30 +116,40 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return ExtensionServerDataQuery.flatMapToServerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toServerDataByPluginID();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
@ -169,23 +178,6 @@ public class ExtensionAggregateBooleansQuery implements Query<Map<Integer, Exten
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.extension.implementation.results.server.ExtensionServ
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -116,30 +115,40 @@ public class ExtensionAggregateDoublesQuery implements Query<Map<Integer, Extens
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return ExtensionServerDataQuery.flatMapToServerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toServerDataByPluginID();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
@ -165,23 +174,6 @@ public class ExtensionAggregateDoublesQuery implements Query<Map<Integer, Extens
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -34,7 +34,6 @@ import com.djrapitops.plan.extension.implementation.results.server.ExtensionServ
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -122,30 +121,40 @@ public class ExtensionAggregateNumbersQuery implements Query<Map<Integer, Extens
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return ExtensionServerDataQuery.flatMapToServerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toServerDataByPluginID();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
@ -172,23 +181,6 @@ public class ExtensionAggregateNumbersQuery implements Query<Map<Integer, Extens
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.extension.implementation.results.server.ExtensionServ
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -107,30 +106,40 @@ public class ExtensionAggregatePercentagesQuery implements Query<Map<Integer, Ex
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return ExtensionServerDataQuery.flatMapToServerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toServerDataByPluginID();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
@ -155,23 +164,6 @@ public class ExtensionAggregatePercentagesQuery implements Query<Map<Integer, Ex
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -149,43 +149,40 @@ public class ExtensionPlayerDataQuery implements Query<Map<UUID, List<ExtensionP
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionPlayerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return flatMapToPlayerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toPlayerDataByPluginID();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Map<Integer, ExtensionPlayerData.Factory> flatMapToPlayerData(Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID) {
|
||||
Map<Integer, ExtensionPlayerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : tabDataByPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
ExtensionPlayerData.Factory data = dataByPluginID.getOrDefault(pluginID, new ExtensionPlayerData.Factory(pluginID));
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
@ -235,23 +232,6 @@ public class ExtensionPlayerDataQuery implements Query<Map<UUID, List<ExtensionP
|
||||
return new ExtensionDescriptive(name, text, description, icon, priority);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.extension.implementation.results.player.ExtensionPlay
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -96,45 +95,42 @@ public class ExtensionPlayerGroupsQuery implements Query<Map<Integer, ExtensionP
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionPlayerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return flatMapToPlayerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toPlayerDataByPluginID();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Map<Integer, ExtensionPlayerData.Factory> flatMapToPlayerData(Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID) {
|
||||
Map<Integer, ExtensionPlayerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : tabDataByPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
ExtensionPlayerData.Factory data = dataByPluginID.getOrDefault(pluginID, new ExtensionPlayerData.Factory(pluginID));
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
|
||||
String groupName = set.getString(ExtensionGroupsTable.GROUP_NAME);
|
||||
extensionTab.putGroupData(new ExtensionStringData(extensionDescriptive, false, groupName));
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private ExtensionDescriptive extractDescriptive(ResultSet set) throws SQLException {
|
||||
@ -149,23 +145,6 @@ public class ExtensionPlayerGroupsQuery implements Query<Map<Integer, ExtensionP
|
||||
return new ExtensionDescriptive(name, text, null, icon, 0);
|
||||
}
|
||||
|
||||
private ExtensionTabData.Factory extractTab(String tabName, ResultSet set, Map<String, ExtensionTabData.Factory> tabData) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return tabData.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
)));
|
||||
}
|
||||
|
||||
private Icon extractTabIcon(ResultSet set) throws SQLException {
|
||||
Optional<String> iconName = Optional.ofNullable(set.getString("tab_icon_name"));
|
||||
if (iconName.isPresent()) {
|
||||
|
@ -27,9 +27,6 @@ import com.djrapitops.plan.extension.ElementOrder;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Family;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTableData;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionPlayerData;
|
||||
import com.djrapitops.plan.extension.table.Table;
|
||||
import com.djrapitops.plan.extension.table.TableAccessor;
|
||||
@ -65,63 +62,13 @@ public class ExtensionPlayerTablesQuery implements Query<Map<Integer, ExtensionP
|
||||
this.playerUUID = playerUUID;
|
||||
}
|
||||
|
||||
private static Map<Integer, ExtensionPlayerData.Factory> flatMapByPluginID(Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID) {
|
||||
Map<Integer, ExtensionPlayerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : tabDataByPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
ExtensionPlayerData.Factory data = dataByPluginID.getOrDefault(pluginID, new ExtensionPlayerData.Factory(pluginID));
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionPlayerData.Factory> executeQuery(SQLDB db) {
|
||||
Map<Integer, Map<Integer, Table.Factory>> tablesByPluginIDAndTableID = db.query(queryTableProviders());
|
||||
Map<Integer, Map<Integer, Table.Factory>> tablesWithValues = db.query(queryTableValues(tablesByPluginIDAndTableID));
|
||||
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = mapToTabsByPluginID(tablesWithValues);
|
||||
return flatMapByPluginID(tabDataByPluginID);
|
||||
QueriedTables tablesWithValues = db.query(placeValuesToTables(db.query(queryTableProviders())));
|
||||
return tablesWithValues.toQueriedTabs().toPlayerDataByPluginID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tablesByPluginIDAndTableID {@code <Plugin ID - <Table ID - Table.Factory>>}
|
||||
* @return {@code <Plugin ID - <Tab name - ExtensionTabData.Factory>}
|
||||
*/
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> mapToTabsByPluginID(Map<Integer, Map<Integer, Table.Factory>> tablesByPluginIDAndTableID) {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> byPluginID = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, Map<Integer, Table.Factory>> entry : tablesByPluginIDAndTableID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
Map<String, ExtensionTabData.Factory> byTabName = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
for (Table.Factory table : entry.getValue().values()) {
|
||||
// Extra Table information
|
||||
String tableName = TableAccessor.getTableName(table);
|
||||
Color tableColor = TableAccessor.getColor(table);
|
||||
|
||||
// Extra tab information
|
||||
String tabName = TableAccessor.getTabName(table);
|
||||
int tabPriority = TableAccessor.getTabPriority(table);
|
||||
ElementOrder[] tabOrder = TableAccessor.getTabOrder(table);
|
||||
Icon tabIcon = TableAccessor.getTabIcon(table);
|
||||
|
||||
ExtensionTabData.Factory tab = byTabName.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(tabName, tabIcon, tabOrder, tabPriority)));
|
||||
tab.putTableData(new ExtensionTableData(
|
||||
tableName, table.build(), tableColor
|
||||
));
|
||||
byTabName.put(tabName, tab);
|
||||
}
|
||||
byPluginID.put(pluginID, byTabName);
|
||||
}
|
||||
|
||||
return byPluginID;
|
||||
}
|
||||
|
||||
// Map: <Plugin ID - <Table ID - Table.Factory>>
|
||||
private Query<Map<Integer, Map<Integer, Table.Factory>>> queryTableValues(Map<Integer, Map<Integer, Table.Factory>> tables) {
|
||||
private Query<QueriedTables> placeValuesToTables(QueriedTables tables) {
|
||||
String selectTableValues = SELECT +
|
||||
ExtensionTableProviderTable.PLUGIN_ID + ',' +
|
||||
ExtensionPlayerTableValueTable.TABLE_ID + ',' +
|
||||
@ -133,37 +80,23 @@ public class ExtensionPlayerTablesQuery implements Query<Map<Integer, ExtensionP
|
||||
INNER_JOIN + ExtensionTableProviderTable.TABLE_NAME + " on " + ExtensionTableProviderTable.TABLE_NAME + '.' + ExtensionTableProviderTable.ID + '=' + ExtensionPlayerTableValueTable.TABLE_NAME + '.' + ExtensionPlayerTableValueTable.TABLE_ID +
|
||||
WHERE + ExtensionPlayerTableValueTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, Map<Integer, Table.Factory>>>(selectTableValues, 10000) {
|
||||
return new QueryStatement<QueriedTables>(selectTableValues, 10000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<Integer, Table.Factory>> processResults(ResultSet set) throws SQLException {
|
||||
public QueriedTables processResults(ResultSet set) throws SQLException {
|
||||
while (set.next()) {
|
||||
Table.Factory table = getTable(set);
|
||||
if (table == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object[] row = extractTableRow(set);
|
||||
if (row.length > 0) {
|
||||
table.addRow(row);
|
||||
}
|
||||
tables.addRow(
|
||||
set.getInt(ExtensionTableProviderTable.PLUGIN_ID),
|
||||
set.getInt(ExtensionPlayerTableValueTable.TABLE_ID),
|
||||
extractTableRow(set)
|
||||
);
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
private Table.Factory getTable(ResultSet set) throws SQLException {
|
||||
int pluginID = set.getInt(ExtensionTableProviderTable.PLUGIN_ID);
|
||||
Map<Integer, Table.Factory> byTableID = tables.get(pluginID);
|
||||
if (byTableID == null) {
|
||||
return null;
|
||||
}
|
||||
int tableID = set.getInt(ExtensionPlayerTableValueTable.TABLE_ID);
|
||||
return byTableID.get(tableID);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -180,8 +113,7 @@ public class ExtensionPlayerTablesQuery implements Query<Map<Integer, ExtensionP
|
||||
return row.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
// Map: <Plugin ID - <Table ID - Table.Factory>>
|
||||
private Query<Map<Integer, Map<Integer, Table.Factory>>> queryTableProviders() {
|
||||
private Query<QueriedTables> queryTableProviders() {
|
||||
String selectTables = SELECT +
|
||||
"p1." + ExtensionTableProviderTable.ID + " as table_id," +
|
||||
"p1." + ExtensionTableProviderTable.PLUGIN_ID + " as plugin_id," +
|
||||
@ -219,41 +151,41 @@ public class ExtensionPlayerTablesQuery implements Query<Map<Integer, ExtensionP
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i6 on i6." + ExtensionIconTable.ID + "=t1." + ExtensionTabTable.ICON_ID +
|
||||
WHERE + "v1." + ExtensionPlayerTableValueTable.USER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, Map<Integer, Table.Factory>>>(selectTables, 100) {
|
||||
return new QueryStatement<QueriedTables>(selectTables, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, playerUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<Integer, Table.Factory>> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<Integer, Table.Factory>> byPluginID = new HashMap<>();
|
||||
|
||||
public QueriedTables processResults(ResultSet set) throws SQLException {
|
||||
QueriedTables tables = new QueriedTables();
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<Integer, Table.Factory> byTableID = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
int tableID = set.getInt("table_id");
|
||||
Table.Factory table = Table.builder();
|
||||
|
||||
extractColumns(set, table);
|
||||
|
||||
TableAccessor.setColor(table, Color.getByName(set.getString("table_color")).orElse(Color.NONE));
|
||||
TableAccessor.setTableName(table, set.getString("table_name"));
|
||||
TableAccessor.setTabName(table, Optional.ofNullable(set.getString("tab_name")).orElse(""));
|
||||
TableAccessor.setTabPriority(table, Optional.of(set.getInt("tab_priority")).orElse(100));
|
||||
TableAccessor.setTabOrder(table, Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize).orElse(ElementOrder.values()));
|
||||
TableAccessor.setTabIcon(table, extractIcon(set, "tab_icon"));
|
||||
|
||||
byTableID.put(tableID, table);
|
||||
byPluginID.put(pluginID, byTableID);
|
||||
tables.put(
|
||||
set.getInt(ExtensionTableProviderTable.PLUGIN_ID),
|
||||
set.getInt(ExtensionPlayerTableValueTable.TABLE_ID),
|
||||
extractTable(set)
|
||||
);
|
||||
}
|
||||
|
||||
return byPluginID;
|
||||
return tables;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Table.Factory extractTable(ResultSet set) throws SQLException {
|
||||
Table.Factory table = Table.builder();
|
||||
|
||||
extractColumns(set, table);
|
||||
|
||||
TableAccessor.setColor(table, Color.getByName(set.getString("table_color")).orElse(Color.NONE));
|
||||
TableAccessor.setTableName(table, set.getString("table_name"));
|
||||
TableAccessor.setTabName(table, Optional.ofNullable(set.getString("tab_name")).orElse(""));
|
||||
TableAccessor.setTabPriority(table, Optional.of(set.getInt("tab_priority")).orElse(100));
|
||||
TableAccessor.setTabOrder(table, Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize).orElse(ElementOrder.values()));
|
||||
TableAccessor.setTabIcon(table, extractIcon(set, "tab_icon"));
|
||||
return table;
|
||||
}
|
||||
|
||||
private void extractColumns(ResultSet set, Table.Factory table) throws SQLException {
|
||||
String col1 = set.getString(ExtensionTableProviderTable.COL_1);
|
||||
if (col1 != null) {
|
||||
|
@ -61,19 +61,6 @@ public class ExtensionServerDataQuery implements Query<List<ExtensionServerData>
|
||||
this.serverUUID = serverUUID;
|
||||
}
|
||||
|
||||
static Map<Integer, ExtensionServerData.Factory> flatMapToServerData(Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID) {
|
||||
Map<Integer, ExtensionServerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : tabDataByPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
ExtensionServerData.Factory data = dataByPluginID.getOrDefault(pluginID, new ExtensionServerData.Factory(pluginID));
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ExtensionServerData> executeQuery(SQLDB db) {
|
||||
List<ExtensionInformation> extensionsOfServer = db.query(ExtensionInformationQueries.extensionsOfServer(serverUUID));
|
||||
@ -162,30 +149,40 @@ public class ExtensionServerDataQuery implements Query<List<ExtensionServerData>
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = extractTabDataByPluginID(set);
|
||||
return flatMapToServerData(tabDataByPluginID);
|
||||
return extractTabDataByPluginID(set).toServerDataByPluginID();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = new HashMap<>();
|
||||
private QueriedTabData extractTabDataByPluginID(ResultSet set) throws SQLException {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<String, ExtensionTabData.Factory> tabData = tabDataByPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
String tabName = Optional.ofNullable(set.getString("tab_name")).orElse("");
|
||||
ExtensionTabData.Factory inMap = tabData.get(tabName);
|
||||
ExtensionTabData.Factory extensionTab = inMap != null ? inMap : extractTab(tabName, set, tabData);
|
||||
ExtensionTabData.Factory extensionTab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(tabName, set));
|
||||
|
||||
ExtensionDescriptive extensionDescriptive = extractDescriptive(set);
|
||||
extractAndPutDataTo(extensionTab, extensionDescriptive, set);
|
||||
|
||||
tabData.put(tabName, extensionTab);
|
||||
tabDataByPluginID.put(pluginID, tabData);
|
||||
}
|
||||
return tabDataByPluginID;
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(String tabName, ResultSet set) throws SQLException {
|
||||
Optional<Integer> tabPriority = Optional.of(set.getInt("tab_priority"));
|
||||
if (set.wasNull()) {
|
||||
tabPriority = Optional.empty();
|
||||
}
|
||||
Optional<ElementOrder[]> elementOrder = Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize);
|
||||
|
||||
Icon tabIcon = extractTabIcon(set);
|
||||
|
||||
return new TabInformation(
|
||||
tabName,
|
||||
tabIcon,
|
||||
elementOrder.orElse(ElementOrder.values()),
|
||||
tabPriority.orElse(100)
|
||||
);
|
||||
}
|
||||
|
||||
private void extractAndPutDataTo(ExtensionTabData.Factory extensionTab, ExtensionDescriptive descriptive, ResultSet set) throws SQLException {
|
||||
|
@ -19,17 +19,11 @@ package com.djrapitops.plan.extension.implementation.storage.queries;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionIconTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionServerTableValueTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionTabTable;
|
||||
import com.djrapitops.plan.db.sql.tables.ExtensionTableProviderTable;
|
||||
import com.djrapitops.plan.db.sql.tables.*;
|
||||
import com.djrapitops.plan.extension.ElementOrder;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Family;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTableData;
|
||||
import com.djrapitops.plan.extension.implementation.results.server.ExtensionServerData;
|
||||
import com.djrapitops.plan.extension.table.Table;
|
||||
import com.djrapitops.plan.extension.table.TableAccessor;
|
||||
@ -67,48 +61,11 @@ public class ExtensionServerTablesQuery implements Query<Map<Integer, ExtensionS
|
||||
|
||||
@Override
|
||||
public Map<Integer, ExtensionServerData.Factory> executeQuery(SQLDB db) {
|
||||
Map<Integer, Map<Integer, Table.Factory>> tablesByPluginIDAndTableID = db.query(queryTableProviders());
|
||||
Map<Integer, Map<Integer, Table.Factory>> tablesWithValues = db.query(queryTableValues(tablesByPluginIDAndTableID));
|
||||
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> tabDataByPluginID = mapToTabsByPluginID(tablesWithValues);
|
||||
return ExtensionServerDataQuery.flatMapToServerData(tabDataByPluginID);
|
||||
QueriedTables tablesWithValues = db.query(queryTableValues(db.query(queryTableProviders())));
|
||||
return tablesWithValues.toQueriedTabs().toServerDataByPluginID();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tablesByPluginIDAndTableID {@code <Plugin ID - <Table ID - Table.Factory>>}
|
||||
* @return {@code <Plugin ID - <Tab name - ExtensionTabData.Factory>}
|
||||
*/
|
||||
private Map<Integer, Map<String, ExtensionTabData.Factory>> mapToTabsByPluginID(Map<Integer, Map<Integer, Table.Factory>> tablesByPluginIDAndTableID) {
|
||||
Map<Integer, Map<String, ExtensionTabData.Factory>> byPluginID = new HashMap<>();
|
||||
|
||||
for (Map.Entry<Integer, Map<Integer, Table.Factory>> entry : tablesByPluginIDAndTableID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
Map<String, ExtensionTabData.Factory> byTabName = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
for (Table.Factory table : entry.getValue().values()) {
|
||||
// Extra Table information
|
||||
String tableName = TableAccessor.getTableName(table);
|
||||
Color tableColor = TableAccessor.getColor(table);
|
||||
|
||||
// Extra tab information
|
||||
String tabName = TableAccessor.getTabName(table);
|
||||
int tabPriority = TableAccessor.getTabPriority(table);
|
||||
ElementOrder[] tabOrder = TableAccessor.getTabOrder(table);
|
||||
Icon tabIcon = TableAccessor.getTabIcon(table);
|
||||
|
||||
ExtensionTabData.Factory tab = byTabName.getOrDefault(tabName, new ExtensionTabData.Factory(new TabInformation(tabName, tabIcon, tabOrder, tabPriority)));
|
||||
tab.putTableData(new ExtensionTableData(
|
||||
tableName, table.build(), tableColor
|
||||
));
|
||||
byTabName.put(tabName, tab);
|
||||
}
|
||||
byPluginID.put(pluginID, byTabName);
|
||||
}
|
||||
|
||||
return byPluginID;
|
||||
}
|
||||
|
||||
// Map: <Plugin ID - <Table ID - Table.Factory>>
|
||||
private Query<Map<Integer, Map<Integer, Table.Factory>>> queryTableValues(Map<Integer, Map<Integer, Table.Factory>> tables) {
|
||||
private Query<QueriedTables> queryTableValues(QueriedTables tables) {
|
||||
String selectTableValues = SELECT +
|
||||
ExtensionTableProviderTable.PLUGIN_ID + ',' +
|
||||
ExtensionServerTableValueTable.TABLE_ID + ',' +
|
||||
@ -121,37 +78,23 @@ public class ExtensionServerTablesQuery implements Query<Map<Integer, ExtensionS
|
||||
INNER_JOIN + ExtensionTableProviderTable.TABLE_NAME + " on " + ExtensionTableProviderTable.TABLE_NAME + '.' + ExtensionTableProviderTable.ID + '=' + ExtensionServerTableValueTable.TABLE_NAME + '.' + ExtensionServerTableValueTable.TABLE_ID +
|
||||
WHERE + ExtensionServerTableValueTable.SERVER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, Map<Integer, Table.Factory>>>(selectTableValues, 10000) {
|
||||
return new QueryStatement<QueriedTables>(selectTableValues, 10000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<Integer, Table.Factory>> processResults(ResultSet set) throws SQLException {
|
||||
public QueriedTables processResults(ResultSet set) throws SQLException {
|
||||
while (set.next()) {
|
||||
Table.Factory table = getTable(set);
|
||||
if (table == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object[] row = extractTableRow(set);
|
||||
if (row.length > 0) {
|
||||
table.addRow(row);
|
||||
}
|
||||
tables.addRow(
|
||||
set.getInt(ExtensionTableProviderTable.PLUGIN_ID),
|
||||
set.getInt(ExtensionPlayerTableValueTable.TABLE_ID),
|
||||
extractTableRow(set)
|
||||
);
|
||||
}
|
||||
return tables;
|
||||
}
|
||||
|
||||
private Table.Factory getTable(ResultSet set) throws SQLException {
|
||||
int pluginID = set.getInt(ExtensionTableProviderTable.PLUGIN_ID);
|
||||
Map<Integer, Table.Factory> byTableID = tables.get(pluginID);
|
||||
if (byTableID == null) {
|
||||
return null;
|
||||
}
|
||||
int tableID = set.getInt(ExtensionServerTableValueTable.TABLE_ID);
|
||||
return byTableID.get(tableID);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -168,8 +111,7 @@ public class ExtensionServerTablesQuery implements Query<Map<Integer, ExtensionS
|
||||
return row.toArray(new Object[0]);
|
||||
}
|
||||
|
||||
// Map: <Plugin ID - <Table ID - Table.Factory>>
|
||||
private Query<Map<Integer, Map<Integer, Table.Factory>>> queryTableProviders() {
|
||||
private Query<QueriedTables> queryTableProviders() {
|
||||
String selectTables = SELECT +
|
||||
"p1." + ExtensionTableProviderTable.ID + " as table_id," +
|
||||
"p1." + ExtensionTableProviderTable.PLUGIN_ID + " as plugin_id," +
|
||||
@ -212,41 +154,43 @@ public class ExtensionServerTablesQuery implements Query<Map<Integer, ExtensionS
|
||||
LEFT_JOIN + ExtensionIconTable.TABLE_NAME + " i6 on i6." + ExtensionIconTable.ID + "=t1." + ExtensionTabTable.ICON_ID +
|
||||
WHERE + "v1." + ExtensionServerTableValueTable.SERVER_UUID + "=?";
|
||||
|
||||
return new QueryStatement<Map<Integer, Map<Integer, Table.Factory>>>(selectTables, 100) {
|
||||
return new QueryStatement<QueriedTables>(selectTables, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Map<Integer, Table.Factory>> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Map<Integer, Table.Factory>> byPluginID = new HashMap<>();
|
||||
public QueriedTables processResults(ResultSet set) throws SQLException {
|
||||
QueriedTables tables = new QueriedTables();
|
||||
|
||||
while (set.next()) {
|
||||
int pluginID = set.getInt("plugin_id");
|
||||
Map<Integer, Table.Factory> byTableID = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
int tableID = set.getInt("table_id");
|
||||
Table.Factory table = Table.builder();
|
||||
|
||||
extractColumns(set, table);
|
||||
|
||||
TableAccessor.setColor(table, Color.getByName(set.getString("table_color")).orElse(Color.NONE));
|
||||
TableAccessor.setTableName(table, set.getString("table_name"));
|
||||
TableAccessor.setTabName(table, Optional.ofNullable(set.getString("tab_name")).orElse(""));
|
||||
TableAccessor.setTabPriority(table, Optional.of(set.getInt("tab_priority")).orElse(100));
|
||||
TableAccessor.setTabOrder(table, Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize).orElse(ElementOrder.values()));
|
||||
TableAccessor.setTabIcon(table, extractIcon(set, "tab_icon"));
|
||||
|
||||
byTableID.put(tableID, table);
|
||||
byPluginID.put(pluginID, byTableID);
|
||||
tables.put(
|
||||
set.getInt(ExtensionTableProviderTable.PLUGIN_ID),
|
||||
set.getInt(ExtensionPlayerTableValueTable.TABLE_ID),
|
||||
extractTable(set)
|
||||
);
|
||||
}
|
||||
|
||||
return byPluginID;
|
||||
return tables;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Table.Factory extractTable(ResultSet set) throws SQLException {
|
||||
Table.Factory table = Table.builder();
|
||||
|
||||
extractColumns(set, table);
|
||||
|
||||
TableAccessor.setColor(table, Color.getByName(set.getString("table_color")).orElse(Color.NONE));
|
||||
TableAccessor.setTableName(table, set.getString("table_name"));
|
||||
TableAccessor.setTabName(table, Optional.ofNullable(set.getString("tab_name")).orElse(""));
|
||||
TableAccessor.setTabPriority(table, Optional.of(set.getInt("tab_priority")).orElse(100));
|
||||
TableAccessor.setTabOrder(table, Optional.ofNullable(set.getString(ExtensionTabTable.ELEMENT_ORDER)).map(ElementOrder::deserialize).orElse(ElementOrder.values()));
|
||||
TableAccessor.setTabIcon(table, extractIcon(set, "tab_icon"));
|
||||
return table;
|
||||
}
|
||||
|
||||
private void extractColumns(ResultSet set, Table.Factory table) throws SQLException {
|
||||
String col1 = set.getString(ExtensionTableProviderTable.COL_1);
|
||||
if (col1 != null) {
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* 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.extension.implementation.storage.queries;
|
||||
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
|
||||
import com.djrapitops.plan.extension.implementation.results.player.ExtensionPlayerData;
|
||||
import com.djrapitops.plan.extension.implementation.results.server.ExtensionServerData;
|
||||
import com.djrapitops.plan.utilities.java.ThrowingSupplier;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Query utility for extracting Tabs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class QueriedTabData {
|
||||
|
||||
private final Map<Integer, Map<String, ExtensionTabData.Factory>> byPluginID;
|
||||
|
||||
public QueriedTabData() {
|
||||
byPluginID = new HashMap<>();
|
||||
}
|
||||
|
||||
public <K extends Throwable> ExtensionTabData.Factory getTab(int pluginID, String tabName, ThrowingSupplier<TabInformation, K> newDefault) throws K {
|
||||
Map<String, ExtensionTabData.Factory> byTabName = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
|
||||
ExtensionTabData.Factory tab = byTabName.get(tabName);
|
||||
if (tab == null) {
|
||||
tab = new ExtensionTabData.Factory(newDefault.get());
|
||||
}
|
||||
|
||||
byTabName.put(tabName, tab);
|
||||
byPluginID.put(pluginID, byTabName);
|
||||
return tab;
|
||||
}
|
||||
|
||||
public Map<Integer, ExtensionServerData.Factory> toServerDataByPluginID() {
|
||||
Map<Integer, ExtensionServerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : byPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
|
||||
ExtensionServerData.Factory data = dataByPluginID.get(pluginID);
|
||||
if (data == null) {
|
||||
data = new ExtensionServerData.Factory(pluginID);
|
||||
}
|
||||
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
|
||||
public Map<Integer, ExtensionPlayerData.Factory> toPlayerDataByPluginID() {
|
||||
Map<Integer, ExtensionPlayerData.Factory> dataByPluginID = new HashMap<>();
|
||||
for (Map.Entry<Integer, Map<String, ExtensionTabData.Factory>> entry : byPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
|
||||
ExtensionPlayerData.Factory data = dataByPluginID.get(pluginID);
|
||||
if (data == null) {
|
||||
data = new ExtensionPlayerData.Factory(pluginID);
|
||||
}
|
||||
|
||||
for (ExtensionTabData.Factory tabData : entry.getValue().values()) {
|
||||
data.addTab(tabData.build());
|
||||
}
|
||||
dataByPluginID.put(pluginID, data);
|
||||
}
|
||||
return dataByPluginID;
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.extension.implementation.storage.queries;
|
||||
|
||||
import com.djrapitops.plan.extension.ElementOrder;
|
||||
import com.djrapitops.plan.extension.icon.Color;
|
||||
import com.djrapitops.plan.extension.icon.Icon;
|
||||
import com.djrapitops.plan.extension.implementation.TabInformation;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTabData;
|
||||
import com.djrapitops.plan.extension.implementation.results.ExtensionTableData;
|
||||
import com.djrapitops.plan.extension.table.Table;
|
||||
import com.djrapitops.plan.extension.table.TableAccessor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Query utility for extracting Tables.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class QueriedTables {
|
||||
|
||||
// Map: <Plugin ID - <Table ID - Table.Factory>>
|
||||
private final Map<Integer, Map<Integer, Table.Factory>> byPluginID;
|
||||
|
||||
public QueriedTables() {
|
||||
byPluginID = new HashMap<>();
|
||||
}
|
||||
|
||||
public void put(int pluginID, int tableID, Table.Factory table) {
|
||||
Map<Integer, Table.Factory> byTableID = byPluginID.getOrDefault(pluginID, new HashMap<>());
|
||||
byTableID.put(tableID, table);
|
||||
byPluginID.put(pluginID, byTableID);
|
||||
}
|
||||
|
||||
public void addRow(int pluginID, int tableID, Object[] row) {
|
||||
if (row.length <= 0) return;
|
||||
|
||||
Map<Integer, Table.Factory> byTableID = byPluginID.get(pluginID);
|
||||
if (byTableID == null) return;
|
||||
|
||||
Table.Factory table = byTableID.get(tableID);
|
||||
if (table == null) return;
|
||||
|
||||
table.addRow(row);
|
||||
}
|
||||
|
||||
public QueriedTabData toQueriedTabs() {
|
||||
QueriedTabData tabData = new QueriedTabData();
|
||||
|
||||
for (Map.Entry<Integer, Map<Integer, Table.Factory>> entry : byPluginID.entrySet()) {
|
||||
Integer pluginID = entry.getKey();
|
||||
|
||||
for (Table.Factory table : entry.getValue().values()) {
|
||||
// Extra Table information
|
||||
String tableName = TableAccessor.getTableName(table);
|
||||
Color tableColor = TableAccessor.getColor(table);
|
||||
|
||||
// Extra tab information
|
||||
String tabName = TableAccessor.getTabName(table);
|
||||
|
||||
ExtensionTabData.Factory tab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(table));
|
||||
tab.putTableData(new ExtensionTableData(
|
||||
tableName, table.build(), tableColor
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return tabData;
|
||||
}
|
||||
|
||||
private TabInformation extractTabInformation(Table.Factory table) {
|
||||
String tabName = TableAccessor.getTabName(table);
|
||||
int tabPriority = TableAccessor.getTabPriority(table);
|
||||
ElementOrder[] tabOrder = TableAccessor.getTabOrder(table);
|
||||
Icon tabIcon = TableAccessor.getTabIcon(table);
|
||||
|
||||
return new TabInformation(tabName, tabIcon, tabOrder, tabPriority);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.utilities.java;
|
||||
|
||||
/**
|
||||
* Functional interface that performs an operation that might throw an exception.
|
||||
* <p>
|
||||
* Follows naming scheme of Java 8 functional interfaces.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public interface ThrowingSupplier<T, K extends Throwable> {
|
||||
|
||||
T get() throws K;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user