From 7d103f99d75b6b54a5fb0b4af141cbffb9acb1b2 Mon Sep 17 00:00:00 2001 From: vivek mahalingam Date: Wed, 24 Jul 2024 17:32:54 +0530 Subject: [PATCH] Converting List to Hashmap --- .../dc/rdb/impl/informix/InformixDc.java | 8 ++++---- .../collection/MetricsDataQueryConfig.java | 18 ++++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java index 9cc654b..0bd4dfb 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/InformixDc.java @@ -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) metricDataQueryConfig.getResults(0)); - getRawMetric(DB_TABLESPACE_USED_NAME).setValue((List) metricDataQueryConfig.getResults(2)); - getRawMetric(DB_TABLESPACE_UTILIZATION_NAME).setValue((List) metricDataQueryConfig.getResults(3)); - getRawMetric(DB_TABLESPACE_MAX_NAME).setValue((List) metricDataQueryConfig.getResults(0)); + getRawMetric(DB_TABLESPACE_SIZE_NAME).setValue((List) metricDataQueryConfig.getResults(SemanticAttributes.TOTAL_KB.getKey())); + getRawMetric(DB_TABLESPACE_USED_NAME).setValue((List) metricDataQueryConfig.getResults(SemanticAttributes.USED_KB.getKey())); + getRawMetric(DB_TABLESPACE_UTILIZATION_NAME).setValue((List) metricDataQueryConfig.getResults(SemanticAttributes.TABLE_UTILIZATION.getKey())); + getRawMetric(DB_TABLESPACE_MAX_NAME).setValue((List) metricDataQueryConfig.getResults(SemanticAttributes.TOTAL_KB.getKey())); getRawMetric(DB_DATABASE_LOG_ENABLED_NAME).setValue((List) metricCollector.collectMetrics(DB_DATABASE_LOG_ENABLED_NAME)); getRawMetric(DB_DATABASE_BUFF_LOG_ENABLED_NAME).setValue((List) metricCollector.collectMetrics(DB_DATABASE_BUFF_LOG_ENABLED_NAME)); getRawMetric(DB_DATABASE_ANSI_COMPLAINT_NAME).setValue((List) metricCollector.collectMetrics(DB_DATABASE_ANSI_COMPLAINT_NAME)); diff --git a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/MetricsDataQueryConfig.java b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/MetricsDataQueryConfig.java index 5cb646f..214aaa2 100644 --- a/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/MetricsDataQueryConfig.java +++ b/rdb/src/main/java/com/instana/dc/rdb/impl/informix/metric/collection/MetricsDataQueryConfig.java @@ -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; @@ -32,17 +33,17 @@ public class MetricsDataQueryConfig { private ResultSet rs; private String[] attr; - private List> results; + private HashMap> 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>(); for (int attrIndex = 0;attrIndex()); + this.results.put(this.attr[attrIndex],new ArrayList<>()); } } @@ -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 ls = this.results.get(this.attr[attrIndex]); + ls.add(result); + this.results.put(this.attr[attrIndex],ls); } } } @@ -99,8 +102,7 @@ public Class getReturnType() { return returnType; } - - public List getResults(int n) { - return this.results.get(n); + public List getResults(String key) { + return this.results.get(key); } }