X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FGroup.java;h=35363094d04be029d77e1f1e3328eb81bf264977;hb=968d81eba83a680163fc8793180c25388be2e297;hp=a021a60e6e3c6cda9d8674ee98e1b77844c5c2d6;hpb=4fe3669fbd63c06ab4d87ed371a49ab2ac9b066a;p=dmaap%2Fdatarouter.git 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..35363094 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,17 +96,17 @@ 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(); + intlogger.error("SQLException " + e.getMessage()); } return list; } @@ -120,39 +117,40 @@ 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()); - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return max; } public static Collection getGroupsByClassfication(String classfication) { - List list = new ArrayList(); - String sql = "select * from GROUPS where classification = '" + classfication + "'"; + List list = new ArrayList<>(); + String sql = "select * from GROUPS where classification = ?"; try { 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(PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, classfication); + try(ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + int groupid = rs.getInt("groupid"); + + } + } } - rs.close(); - stmt.close(); db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return list; } @@ -168,17 +166,17 @@ 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()); - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return count; } @@ -348,12 +346,14 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -376,12 +376,14 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -399,12 +401,14 @@ public class Group extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } finally { try { - ps.close(); + if(ps!=null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -440,4 +444,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); + } }