Skip to content

Commit

Permalink
Converting List to Hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek mahalingam authored and vivek mahalingam committed Jul 24, 2024
1 parent 00eed52 commit 7d103f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ private void shortPollingInterval() {
private void longPollingInterval() {
//TODO: A method to execute the query, store it in object, call that object in subsequent lines
metricDataQueryConfig.fetchQueryResults();
getRawMetric(DB_TABLESPACE_SIZE_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(0));
getRawMetric(DB_TABLESPACE_USED_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(2));
getRawMetric(DB_TABLESPACE_UTILIZATION_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(3));
getRawMetric(DB_TABLESPACE_MAX_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(0));
getRawMetric(DB_TABLESPACE_SIZE_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(SemanticAttributes.TOTAL_KB.getKey()));
getRawMetric(DB_TABLESPACE_USED_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(SemanticAttributes.USED_KB.getKey()));
getRawMetric(DB_TABLESPACE_UTILIZATION_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(SemanticAttributes.TABLE_UTILIZATION.getKey()));
getRawMetric(DB_TABLESPACE_MAX_NAME).setValue((List<SimpleQueryResult>) metricDataQueryConfig.getResults(SemanticAttributes.TOTAL_KB.getKey()));
getRawMetric(DB_DATABASE_LOG_ENABLED_NAME).setValue((List<SimpleQueryResult>) metricCollector.collectMetrics(DB_DATABASE_LOG_ENABLED_NAME));
getRawMetric(DB_DATABASE_BUFF_LOG_ENABLED_NAME).setValue((List<SimpleQueryResult>) metricCollector.collectMetrics(DB_DATABASE_BUFF_LOG_ENABLED_NAME));
getRawMetric(DB_DATABASE_ANSI_COMPLAINT_NAME).setValue((List<SimpleQueryResult>) metricCollector.collectMetrics(DB_DATABASE_ANSI_COMPLAINT_NAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
Expand All @@ -32,17 +33,17 @@ public class MetricsDataQueryConfig {
private ResultSet rs;
private String[] attr;

private List<List<SimpleQueryResult>> results;
private HashMap<String,List<SimpleQueryResult>> results;


public MetricsDataQueryConfig(String query, Class<?> returnType, BasicDataSource dataSource,String... attr) {
public MetricsDataQueryConfig(String query, Class<?> returnType, BasicDataSource dataSource, String... attr) {
this.query = query;
this.returnType = returnType;
this.attr = attr;
this.dataSource = dataSource;
this.results = new ArrayList<>();
this.results = new HashMap<String,List<SimpleQueryResult>>();
for (int attrIndex = 0;attrIndex<attr.length;attrIndex++) {
this.results.add(new ArrayList<>());
this.results.put(this.attr[attrIndex],new ArrayList<>());
}
}

Expand All @@ -68,7 +69,9 @@ public void fetchQueryResults() {
SimpleQueryResult result = new SimpleQueryResult((Number) rs.getObject(attrIndex+1));
result.setAttribute(this.attr[1], obj);
result.setKey(obj.toString());
this.results.get(attrIndex).add(result);
List<SimpleQueryResult> ls = this.results.get(this.attr[attrIndex]);
ls.add(result);
this.results.put(this.attr[attrIndex],ls);
}
}
}
Expand Down Expand Up @@ -99,8 +102,7 @@ public Class<?> getReturnType() {
return returnType;
}


public List<SimpleQueryResult> getResults(int n) {
return this.results.get(n);
public List<SimpleQueryResult> getResults(String key) {
return this.results.get(key);
}
}

0 comments on commit 7d103f9

Please sign in to comment.