aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 17:10:25 +0530
committerAmaresh Kumar <kamaresh@in.ibm.com>2018-09-05 17:10:34 +0530
commit9172044cee69d8b421c8bfbb19dea9e77a8a23e6 (patch)
treecfc1af5f242cf7360d67855144de2ee62c428dfb
parentebf06902c4c780eeae0407ab519070c0df5b11d7 (diff)
fixed 12 blocker issues in group.java
https://sonar.onap.org/project/issues?fileUuids=AWHFaQiuEU5FCDfKtnFS&id=org.onap.dmaap.datarouter%3Aparent&resolved=false&severities=BLOCKER Issue-ID: DMAAP-715 Change-Id: Ia917c7144b330249c7af1cec301ddbddbb3462e6 Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java74
1 files changed, 41 insertions, 33 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
index a021a60e..a460d647 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
@@ -29,10 +29,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.Date;
-import java.util.List;
+import java.util.*;
import org.apache.log4j.Logger;
import org.json.JSONObject;
@@ -99,14 +96,14 @@ public class Group extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- Group group = new Group(rs);
- list.add(group);
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ while (rs.next()) {
+ Group group = new Group(rs);
+ list.add(group);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -120,13 +117,13 @@ public class Group extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select MAX(groupid) from GROUPS");
- if (rs.next()) {
- max = rs.getInt(1);
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery("select MAX(groupid) from GROUPS")) {
+ if (rs.next()) {
+ max = rs.getInt(1);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
intlogger.info("getMaxSubID: " + e.getMessage());
@@ -142,14 +139,14 @@ public class Group extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(sql);
- while (rs.next()) {
- int groupid = rs.getInt("groupid");
- //list.add(URLUtilities.generateSubscriptionURL(groupid));
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ while (rs.next()) {
+ int groupid = rs.getInt("groupid");
+
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
@@ -168,13 +165,13 @@ public class Group extends Syncable {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS");
- if (rs.next()) {
- count = rs.getInt(1);
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) {
+ if (rs.next()) {
+ count = rs.getInt(1);
+ }
+ }
}
- rs.close();
- stmt.close();
db.release(conn);
} catch (SQLException e) {
intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
@@ -351,7 +348,9 @@ public class Group extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -379,7 +378,9 @@ public class Group extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -402,7 +403,9 @@ public class Group extends Syncable {
e.printStackTrace();
} finally {
try {
- ps.close();
+ if(ps!=null) {
+ ps.close();
+ }
} catch (SQLException e) {
e.printStackTrace();
}
@@ -440,4 +443,9 @@ public class Group extends Syncable {
public String toString() {
return "GROUP: groupid=" + groupid;
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(groupid, authid, name, description, classification, members, last_mod);
+ }
}