summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 18:03:51 +0530
committerAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 18:04:01 +0530
commitd76ae00310f23c8a816512929903a0f4cbc42459 (patch)
tree24ae0afaed0e0580c4f285a2b58986bae3e156e5
parent20e80641ccbd5e0cf1e75740a8ca5e3f06f872bc (diff)
Added 8 Sonar blocker fixes in Parameters.java
https://sonar.onap.org/project/issues?id=org.onap.dmaap.datarouter%3Aparent&open=AWHFaQpVEU5FCDfKtna5&resolved=false&severities=BLOCKER&types=BUG Issue-ID: DMAAP-718 Change-Id: I5ff9ce3f294bdf111b3e434332734a72f1f5980e Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java52
1 files changed, 30 insertions, 22 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
index 8e9d5bfd..3e8c90b4 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
@@ -28,10 +28,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import org.apache.log4j.Logger;
import org.json.JSONObject;
@@ -93,15 +90,15 @@ public class Parameters extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- String sql = "select * from PARAMETERS";
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- Parameters p = new Parameters(rs);
- coll.add(p);
+ try(Statement stmt = conn.createStatement()) {
+ String sql = "select * from PARAMETERS";
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ while (rs.next()) {
+ Parameters p = new Parameters(rs);
+ coll.add(p);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -121,14 +118,14 @@ public class Parameters extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";
- ResultSet rs = stmt.executeQuery(sql);
- if (rs.next()) {
- v = new Parameters(rs);
+ try(Statement stmt = conn.createStatement()) {
+ String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ if (rs.next()) {
+ v = new Parameters(rs);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -191,7 +188,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -216,7 +215,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -240,7 +241,9 @@ public class Parameters extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -266,6 +269,11 @@ public class Parameters extends Syncable {
}
@Override
+ public int hashCode() {
+ return Objects.hash(keyname, value);
+ }
+
+ @Override
public String toString() {
return "PARAM: keyname=" + keyname + ", value=" + value;
}