Refactor Prov DB handling
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / beans / Feed.java
index 4a14da2..ac1f70a 100644 (file)
@@ -42,8 +42,8 @@ import java.util.Set;
 import org.json.JSONArray;\r
 import org.json.JSONException;\r
 import org.json.JSONObject;\r
-import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 import org.onap.dmaap.datarouter.provisioning.utils.JSONUtilities;\r
+import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;\r
 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
 \r
 \r
@@ -57,8 +57,12 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
 public class Feed extends Syncable {\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
-    private static int next_feedid = getMaxFeedID() + 1;\r
-    private static final String SQLEXCEPTION = "SQLException: ";\r
+    private static int nextFeedID = getMaxFeedID() + 1;\r
+    private static final String FEED_ID_SQL = "FEEDID";\r
+    private static final String FEED_ID = "feedid";\r
+    private static final String DEL = "deleted";\r
+    private static final String LAST_MOD = "last_mod";\r
+    private static final String CREATED_DATE = "created_date";\r
 \r
     private int feedid;\r
     private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
@@ -75,6 +79,143 @@ public class Feed extends Syncable {
     private Date createdDate;\r
     private String aafInstance;\r
 \r
+    public Feed() {\r
+        this("", "", "", "");\r
+    }\r
+\r
+    /**\r
+     * Feed constructor.\r
+     * @param name feed name\r
+     * @param version feed version\r
+     * @param desc feed description\r
+     * @param businessDescription feed business description\r
+     */\r
+    public Feed(String name, String version, String desc, String businessDescription) {\r
+        this.feedid = -1;\r
+        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.name = name;\r
+        this.version = version;\r
+        this.description = desc;\r
+        this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
+        this.authorization = new FeedAuthorization();\r
+        this.publisher = "";\r
+        this.links = new FeedLinks();\r
+        this.deleted = false;\r
+        this.suspended = false;\r
+        this.lastMod = new Date();\r
+        this.createdDate = new Date();\r
+        this.aafInstance = "";\r
+    }\r
+\r
+    /**\r
+     * Feed Constructor from ResultSet.\r
+     * @param rs ResultSet\r
+     * @throws SQLException in case of SQL statement error\r
+     */\r
+    public Feed(ResultSet rs) throws SQLException {\r
+        this.feedid = rs.getInt(FEED_ID_SQL);\r
+        //New field is added - Groups feature Rally:US708115 - 1610\r
+        this.groupid = rs.getInt("GROUPID");\r
+        this.name = rs.getString("NAME");\r
+        this.version = rs.getString("VERSION");\r
+        this.description = rs.getString("DESCRIPTION");\r
+        // New field is added - Groups feature Rally:US708102 - 1610\r
+        this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");\r
+        this.authorization = new FeedAuthorization();\r
+        this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
+        this.publisher = rs.getString("PUBLISHER");\r
+        this.links = new FeedLinks();\r
+        this.links.setSelf(rs.getString("SELF_LINK"));\r
+        this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
+        this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
+        this.links.setLog(rs.getString("LOG_LINK"));\r
+        this.deleted = rs.getBoolean("DELETED");\r
+        this.suspended = rs.getBoolean("SUSPENDED");\r
+        this.lastMod = rs.getDate("LAST_MOD");\r
+        this.createdDate = rs.getTimestamp("CREATED_DATE");\r
+        this.aafInstance = rs.getString("AAF_INSTANCE");\r
+    }\r
+\r
+    /**\r
+     * Feed constructor from JSONObject.\r
+     * @param jo JSONObject\r
+     * @throws InvalidObjectException in case of JSON error\r
+     */\r
+    public Feed(JSONObject jo) throws InvalidObjectException {\r
+        this("", "", "", "");\r
+        try {\r
+            // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
+            this.feedid = jo.optInt(FEED_ID, -1);\r
+            this.groupid = jo.optInt("groupid");\r
+            this.name = jo.getString("name");\r
+            this.aafInstance = jo.optString("aaf_instance", "legacy");\r
+            if (!("legacy".equalsIgnoreCase(aafInstance)) && aafInstance.length() > 255) {\r
+                throw new InvalidObjectException("aaf_instance field is too long");\r
+            }\r
+            if (name.length() > 255) {\r
+                throw new InvalidObjectException("name field is too long");\r
+            }\r
+            try {\r
+                this.version = jo.getString("version");\r
+            } catch (JSONException e) {\r
+                intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
+                this.version = null;\r
+            }\r
+            if (version != null && version.length() > 20) {\r
+                throw new InvalidObjectException("version field is too long");\r
+            }\r
+            this.description = jo.optString("description");\r
+            this.businessDescription = jo.optString("business_description");\r
+            if (description.length() > 1000) {\r
+                throw new InvalidObjectException("technical description field is too long");\r
+            }\r
+            if (businessDescription.length() > 1000) {\r
+                throw new InvalidObjectException("business description field is too long");\r
+            }\r
+            this.authorization = new FeedAuthorization();\r
+            JSONObject jauth = jo.getJSONObject("authorization");\r
+            this.authorization.setClassification(jauth.getString("classification"));\r
+            if (this.authorization.getClassification().length() > 32) {\r
+                throw new InvalidObjectException("classification field is too long");\r
+            }\r
+            JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
+            for (int i = 0; i < endPointIds.length(); i++) {\r
+                JSONObject id = endPointIds.getJSONObject(i);\r
+                FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
+                if (fid.getId().length() > 60) {\r
+                    throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
+                }\r
+                if (fid.getPassword().length() > 32) {\r
+                    //Fortify scan fixes - Privacy Violation\r
+                    throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
+                }\r
+                this.authorization.getEndpointIDS().add(fid);\r
+            }\r
+            if (this.authorization.getEndpointIDS().isEmpty()) {\r
+                throw new InvalidObjectException("need to specify at least one endpoint_id");\r
+            }\r
+            endPointIds = jauth.getJSONArray("endpoint_addrs");\r
+            for (int i = 0; i < endPointIds.length(); i++) {\r
+                String addr = endPointIds.getString(i);\r
+                if (!JSONUtilities.validIPAddrOrSubnet(addr)) {\r
+                    throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
+                }\r
+                this.authorization.getEndpointAddrs().add(addr);\r
+            }\r
+\r
+            this.publisher = jo.optString("publisher", "");\r
+            this.deleted = jo.optBoolean(DEL, false);\r
+            this.suspended = jo.optBoolean("suspend", false);\r
+            JSONObject jol = jo.optJSONObject("links");\r
+            this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
+        } catch (InvalidObjectException e) {\r
+            throw e;\r
+        } catch (Exception e) {\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
+        }\r
+    }\r
+\r
     /**\r
      * Check if a feed ID is valid.\r
      *\r
@@ -82,20 +223,17 @@ public class Feed extends Syncable {
      * @return true if it is valid\r
      */\r
     @SuppressWarnings("resource")\r
-    public static boolean isFeedValid(int id) {\r
+    static boolean isFeedValid(int id) {\r
         int count = 0;\r
-        try {\r
-            DB db = new DB();\r
-            Connection conn = db.getConnection();\r
-            try (PreparedStatement stmt = conn.prepareStatement("select COUNT(*) from FEEDS where FEEDID = ?")) {\r
-                stmt.setInt(1, id);\r
-                try (ResultSet rs = stmt.executeQuery()) {\r
-                    if (rs.next()) {\r
-                        count = rs.getInt(1);\r
-                    }\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+            PreparedStatement ps = conn.prepareStatement(\r
+                "select COUNT(*) from FEEDS where FEEDID = ?")) {\r
+            ps.setInt(1, id);\r
+            try (ResultSet rs = ps.executeQuery()) {\r
+                if (rs.next()) {\r
+                    count = rs.getInt(1);\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
         }\r
@@ -134,17 +272,14 @@ public class Feed extends Syncable {
      */\r
     public static int countActiveFeeds() {\r
         int count = 0;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource") Connection conn = db.getConnection();\r
-            try (Statement stmt = conn.createStatement()) {\r
-                try (ResultSet rs = stmt.executeQuery("select count(*) from FEEDS where DELETED = 0")) {\r
-                    if (rs.next()) {\r
-                        count = rs.getInt(1);\r
-                    }\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+            PreparedStatement ps = conn.prepareStatement(\r
+                "select count(*) from FEEDS where DELETED = 0")) {\r
+            try (ResultSet rs = ps.executeQuery()) {\r
+                if (rs.next()) {\r
+                    count = rs.getInt(1);\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
         }\r
@@ -157,18 +292,14 @@ public class Feed extends Syncable {
      */\r
     public static int getMaxFeedID() {\r
         int max = 0;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (Statement stmt = conn.createStatement()) {\r
-                try (ResultSet rs = stmt.executeQuery("select MAX(feedid) from FEEDS")) {\r
-                    if (rs.next()) {\r
-                        max = rs.getInt(1);\r
-                    }\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+            PreparedStatement ps = conn.prepareStatement(\r
+                "select MAX(feedid) from FEEDS")) {\r
+            try (ResultSet rs = ps.executeQuery()) {\r
+                if (rs.next()) {\r
+                    max = rs.getInt(1);\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
         }\r
@@ -181,44 +312,37 @@ public class Feed extends Syncable {
      */\r
     public static Collection<Feed> getAllFeeds() {\r
         Map<Integer, Feed> map = new HashMap<>();\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (Statement stmt = conn.createStatement()) {\r
-                try (ResultSet rs = stmt.executeQuery("select * from FEEDS")) {\r
-                    while (rs.next()) {\r
-                        Feed feed = new Feed(rs);\r
-                        map.put(feed.getFeedid(), feed);\r
-                    }\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection()) {\r
+            try (PreparedStatement ps = conn.prepareStatement("select * from FEEDS");\r
+                ResultSet rs = ps.executeQuery()) {\r
+                while (rs.next()) {\r
+                    Feed feed = new Feed(rs);\r
+                    map.put(feed.getFeedid(), feed);\r
                 }\r
-\r
-                String sql = "select * from FEED_ENDPOINT_IDS";\r
-                try (ResultSet rs = stmt.executeQuery(sql)) {\r
-                    while (rs.next()) {\r
-                        int id = rs.getInt("FEEDID");\r
-                        Feed feed = map.get(id);\r
-                        if (feed != null) {\r
-                            FeedEndpointID epi = new FeedEndpointID(rs);\r
-                            Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();\r
-                            ecoll.add(epi);\r
-                        }\r
+            }\r
+            try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_IDS");\r
+                ResultSet rs = ps.executeQuery()) {\r
+                while (rs.next()) {\r
+                    int id = rs.getInt(FEED_ID_SQL);\r
+                    Feed feed = map.get(id);\r
+                    if (feed != null) {\r
+                        FeedEndpointID epi = new FeedEndpointID(rs);\r
+                        Collection<FeedEndpointID> ecoll = feed.getAuthorization().getEndpointIDS();\r
+                        ecoll.add(epi);\r
                     }\r
                 }\r
-\r
-                sql = "select * from FEED_ENDPOINT_ADDRS";\r
-                try (ResultSet rs = stmt.executeQuery(sql)) {\r
-                    while (rs.next()) {\r
-                        int id = rs.getInt("FEEDID");\r
-                        Feed feed = map.get(id);\r
-                        if (feed != null) {\r
-                            Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
-                            acoll.add(rs.getString("ADDR"));\r
-                        }\r
+            }\r
+            try (PreparedStatement ps = conn.prepareStatement("select * from FEED_ENDPOINT_ADDRS");\r
+                ResultSet rs = ps.executeQuery()) {\r
+                while (rs.next()) {\r
+                    int id = rs.getInt(FEED_ID_SQL);\r
+                    Feed feed = map.get(id);\r
+                    if (feed != null) {\r
+                        Collection<String> acoll = feed.getAuthorization().getEndpointAddrs();\r
+                        acoll.add(rs.getString("ADDR"));\r
                     }\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
         }\r
@@ -240,26 +364,21 @@ public class Feed extends Syncable {
             sql += " and PUBLISHER = ?";\r
         } else if (name.equals("subs")) {\r
             sql = "select distinct FEEDS.SELF_LINK from FEEDS, SUBSCRIPTIONS "\r
-                          + "where DELETED = 0 "\r
-                          + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "\r
-                          + "and SUBSCRIPTIONS.SUBSCRIBER = ?";\r
+                + "where DELETED = 0 "\r
+                + "and FEEDS.FEEDID = SUBSCRIPTIONS.FEEDID "\r
+                + "and SUBSCRIPTIONS.SUBSCRIBER = ?";\r
         }\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
-                if (sql.indexOf('?') >= 0) {\r
-                    ps.setString(1, val);\r
-                }\r
-                try (ResultSet rs = ps.executeQuery()) {\r
-                    while (rs.next()) {\r
-                        String str = rs.getString(1);\r
-                        list.add(str.trim());\r
-                    }\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+            PreparedStatement ps = conn.prepareStatement(sql)) {\r
+            if (sql.indexOf('?') >= 0) {\r
+                ps.setString(1, val);\r
+            }\r
+            try (ResultSet rs = ps.executeQuery()) {\r
+                while (rs.next()) {\r
+                    String str = rs.getString(1);\r
+                    list.add(str.trim());\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
         }\r
@@ -269,9 +388,7 @@ public class Feed extends Syncable {
     @SuppressWarnings("resource")\r
     private static Feed getFeedBySQL(String sql) {\r
         Feed feed = null;\r
-        try {\r
-            DB db = new DB();\r
-            Connection conn = db.getConnection();\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection()) {\r
             try (Statement stmt = conn.createStatement()) {\r
                 try (ResultSet rs = stmt.executeQuery(sql)) {\r
                     if (rs.next()) {\r
@@ -296,149 +413,13 @@ public class Feed extends Syncable {
                     }\r
                 }\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
         }\r
         return feed;\r
     }\r
 \r
-    public Feed() {\r
-        this("", "", "", "");\r
-    }\r
 \r
-    /**\r
-     * Feed constructor.\r
-     * @param name feed name\r
-     * @param version feed version\r
-     * @param desc feed description\r
-     * @param businessDescription feed business description\r
-     */\r
-    public Feed(String name, String version, String desc, String businessDescription) {\r
-        this.feedid = -1;\r
-        this.groupid = -1; //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.name = name;\r
-        this.version = version;\r
-        this.description = desc;\r
-        this.businessDescription = businessDescription; // New field is added - Groups feature Rally:US708102 - 1610\r
-        this.authorization = new FeedAuthorization();\r
-        this.publisher = "";\r
-        this.links = new FeedLinks();\r
-        this.deleted = false;\r
-        this.suspended = false;\r
-        this.lastMod = new Date();\r
-        this.createdDate = new Date();\r
-        this.aafInstance = "";\r
-    }\r
-\r
-    /**\r
-     * Feed Constructor from ResultSet.\r
-     * @param rs ResultSet\r
-     * @throws SQLException in case of SQL statement error\r
-     */\r
-    public Feed(ResultSet rs) throws SQLException {\r
-        this.feedid = rs.getInt("FEEDID");\r
-        //New field is added - Groups feature Rally:US708115 - 1610\r
-        this.groupid = rs.getInt("GROUPID");\r
-        this.name = rs.getString("NAME");\r
-        this.version = rs.getString("VERSION");\r
-        this.description = rs.getString("DESCRIPTION");\r
-        // New field is added - Groups feature Rally:US708102 - 1610\r
-        this.businessDescription = rs.getString("BUSINESS_DESCRIPTION");\r
-        this.authorization = new FeedAuthorization();\r
-        this.authorization.setClassification(rs.getString("AUTH_CLASS"));\r
-        this.publisher = rs.getString("PUBLISHER");\r
-        this.links = new FeedLinks();\r
-        this.links.setSelf(rs.getString("SELF_LINK"));\r
-        this.links.setPublish(rs.getString("PUBLISH_LINK"));\r
-        this.links.setSubscribe(rs.getString("SUBSCRIBE_LINK"));\r
-        this.links.setLog(rs.getString("LOG_LINK"));\r
-        this.deleted = rs.getBoolean("DELETED");\r
-        this.suspended = rs.getBoolean("SUSPENDED");\r
-        this.lastMod = rs.getDate("LAST_MOD");\r
-        this.createdDate = rs.getTimestamp("CREATED_DATE");\r
-        this.aafInstance = rs.getString("AAF_INSTANCE");\r
-    }\r
-\r
-    /**\r
-     * Feed constructor from JSONObject.\r
-     * @param jo JSONObject\r
-     * @throws InvalidObjectException in case of JSON error\r
-     */\r
-    public Feed(JSONObject jo) throws InvalidObjectException {\r
-        this("", "", "", "");\r
-        try {\r
-            // The JSONObject is assumed to contain a vnd.dmaap-dr.feed representation\r
-            this.feedid = jo.optInt("feedid", -1);\r
-            this.groupid = jo.optInt("groupid");\r
-            this.name = jo.getString("name");\r
-            this.aafInstance = jo.optString("aaf_instance", "legacy");\r
-            if (!(aafInstance.equalsIgnoreCase("legacy")) && aafInstance.length() > 255) {\r
-                throw new InvalidObjectException("aaf_instance field is too long");\r
-            }\r
-            if (name.length() > 255) {\r
-                throw new InvalidObjectException("name field is too long");\r
-            }\r
-            try {\r
-                this.version = jo.getString("version");\r
-            } catch (JSONException e) {\r
-                intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
-                this.version = null;\r
-            }\r
-            if (version != null && version.length() > 20) {\r
-                throw new InvalidObjectException("version field is too long");\r
-            }\r
-            this.description = jo.optString("description");\r
-            this.businessDescription = jo.optString("business_description");\r
-            if (description.length() > 1000) {\r
-                throw new InvalidObjectException("technical description field is too long");\r
-            }\r
-            if (businessDescription.length() > 1000) {\r
-                throw new InvalidObjectException("business description field is too long");\r
-            }\r
-            this.authorization = new FeedAuthorization();\r
-            JSONObject jauth = jo.getJSONObject("authorization");\r
-            this.authorization.setClassification(jauth.getString("classification"));\r
-            if (this.authorization.getClassification().length() > 32) {\r
-                throw new InvalidObjectException("classification field is too long");\r
-            }\r
-            JSONArray endPointIds = jauth.getJSONArray("endpoint_ids");\r
-            for (int i = 0; i < endPointIds.length(); i++) {\r
-                JSONObject id = endPointIds.getJSONObject(i);\r
-                FeedEndpointID fid = new FeedEndpointID(id.getString("id"), id.getString("password"));\r
-                if (fid.getId().length() > 60) {\r
-                    throw new InvalidObjectException("id field is too long (" + fid.getId() + ")");\r
-                }\r
-                if (fid.getPassword().length() > 32) {\r
-                    //Fortify scan fixes - Privacy Violation\r
-                    throw new InvalidObjectException("password field is too long (" + fid.getPassword() + ")");\r
-                }\r
-                this.authorization.getEndpointIDS().add(fid);\r
-            }\r
-            if (this.authorization.getEndpointIDS().isEmpty()) {\r
-                throw new InvalidObjectException("need to specify at least one endpoint_id");\r
-            }\r
-            endPointIds = jauth.getJSONArray("endpoint_addrs");\r
-            for (int i = 0; i < endPointIds.length(); i++) {\r
-                String addr = endPointIds.getString(i);\r
-                if (!JSONUtilities.validIPAddrOrSubnet(addr)) {\r
-                    throw new InvalidObjectException("bad IP addr or subnet mask: " + addr);\r
-                }\r
-                this.authorization.getEndpointAddrs().add(addr);\r
-            }\r
-\r
-            this.publisher = jo.optString("publisher", "");\r
-            this.deleted = jo.optBoolean("deleted", false);\r
-            this.suspended = jo.optBoolean("suspend", false);\r
-            JSONObject jol = jo.optJSONObject("links");\r
-            this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
-        } catch (InvalidObjectException e) {\r
-            throw e;\r
-        } catch (Exception e) {\r
-            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
-            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
-        }\r
-    }\r
 \r
     public int getFeedid() {\r
         return feedid;\r
@@ -446,7 +427,7 @@ public class Feed extends Syncable {
 \r
     /**\r
      *  Set feedid with FeedLinks.\r
-      * @param feedid Feedid to set to\r
+     * @param feedid Feedid to set to\r
      */\r
     public void setFeedid(int feedid) {\r
         this.feedid = feedid;\r
@@ -463,10 +444,6 @@ public class Feed extends Syncable {
         return aafInstance;\r
     }\r
 \r
-    public void setAaf_instance(String aafInstance) {\r
-        this.aafInstance = aafInstance;\r
-    }\r
-\r
     //new getter setters for groups- Rally:US708115 - 1610\r
     public int getGroupid() {\r
         return groupid;\r
@@ -501,11 +478,11 @@ public class Feed extends Syncable {
     }\r
 \r
     // New field is added - Groups feature Rally:US708102 - 1610\r
-    public String getBusiness_description() {\r
+    String getBusinessDescription() {\r
         return businessDescription;\r
     }\r
 \r
-    public void setBusiness_description(String businessDescription) {\r
+    void setBusinessDescription(String businessDescription) {\r
         this.businessDescription = businessDescription;\r
     }\r
 \r
@@ -538,7 +515,7 @@ public class Feed extends Syncable {
         return links;\r
     }\r
 \r
-    public void setLinks(FeedLinks links) {\r
+    void setLinks(FeedLinks links) {\r
         this.links = links;\r
     }\r
 \r
@@ -550,18 +527,18 @@ public class Feed extends Syncable {
         this.deleted = deleted;\r
     }\r
 \r
-    public boolean isSuspended() {\r
+    boolean isSuspended() {\r
         return suspended;\r
     }\r
 \r
-    public void setSuspended(boolean suspended) {\r
+    void setSuspended(boolean suspended) {\r
         this.suspended = suspended;\r
     }\r
 \r
     @Override\r
     public JSONObject asJSONObject() {\r
         JSONObject jo = new JSONObject();\r
-        jo.put("feedid", feedid);\r
+        jo.put(FEED_ID, feedid);\r
         //New field is added - Groups feature Rally:US708115 - 1610\r
         jo.put("groupid", groupid);\r
         jo.put("name", name);\r
@@ -572,10 +549,10 @@ public class Feed extends Syncable {
         jo.put("authorization", authorization.asJSONObject());\r
         jo.put("publisher", publisher);\r
         jo.put("links", links.asJSONObject());\r
-        jo.put("deleted", deleted);\r
+        jo.put(DEL, deleted);\r
         jo.put("suspend", suspended);\r
-        jo.put("last_mod", lastMod.getTime());\r
-        jo.put("created_date", createdDate.getTime());\r
+        jo.put(LAST_MOD, lastMod.getTime());\r
+        jo.put(CREATED_DATE, createdDate.getTime());\r
         jo.put("aaf_instance", aafInstance);\r
         return jo;\r
     }\r
@@ -588,10 +565,10 @@ public class Feed extends Syncable {
     public JSONObject asJSONObject(boolean hidepasswords) {\r
         JSONObject jo = asJSONObject();\r
         if (hidepasswords) {\r
-            jo.remove("feedid");    // we no longer hide passwords, however we do hide these\r
-            jo.remove("deleted");\r
-            jo.remove("last_mod");\r
-            jo.remove("created_date");\r
+            jo.remove(FEED_ID);    // we no longer hide passwords, however we do hide these\r
+            jo.remove(DEL);\r
+            jo.remove(LAST_MOD);\r
+            jo.remove(CREATED_DATE);\r
         }\r
         return jo;\r
     }\r
@@ -602,10 +579,10 @@ public class Feed extends Syncable {
      */\r
     public JSONObject asLimitedJSONObject() {\r
         JSONObject jo = asJSONObject();\r
-        jo.remove("deleted");\r
-        jo.remove("feedid");\r
-        jo.remove("last_mod");\r
-        jo.remove("created_date");\r
+        jo.remove(DEL);\r
+        jo.remove(FEED_ID);\r
+        jo.remove(LAST_MOD);\r
+        jo.remove(CREATED_DATE);\r
         return jo;\r
     }\r
 \r
@@ -614,23 +591,12 @@ public class Feed extends Syncable {
     @Override\r
     public boolean doDelete(Connection conn) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            String sql = "delete from FEEDS where FEEDID = ?";\r
-            ps = conn.prepareStatement(sql);\r
+        try (PreparedStatement ps = conn.prepareStatement("delete from FEEDS where FEEDID = ?")) {\r
             ps.setInt(1, feedid);\r
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
             intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
-        } finally {\r
-            try {\r
-                if (ps != null) {\r
-                    ps.close();\r
-                }\r
-            } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -640,57 +606,52 @@ public class Feed extends Syncable {
         boolean rv = true;\r
         try {\r
             if (feedid == -1) {\r
-                setFeedid(next_feedid++);\r
+                setFeedid(nextFeedID++);\r
             }\r
             // In case we insert a feed from synchronization\r
-            if (feedid > next_feedid) {\r
-                next_feedid = feedid + 1;\r
+            if (feedid > nextFeedID) {\r
+                nextFeedID = feedid + 1;\r
             }\r
-\r
             // Create FEED_ENDPOINT_IDS rows\r
             FeedAuthorization auth = getAuthorization();\r
-            String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
-            try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
+            try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {\r
                 for (FeedEndpointID fid : auth.getEndpointIDS()) {\r
-                    ps2.setInt(1, feedid);\r
-                    ps2.setString(2, fid.getId());\r
-                    ps2.setString(3, fid.getPassword());\r
-                    ps2.executeUpdate();\r
+                    ps.setInt(1, feedid);\r
+                    ps.setString(2, fid.getId());\r
+                    ps.setString(3, fid.getPassword());\r
+                    ps.executeUpdate();\r
                 }\r
             }\r
-\r
             // Create FEED_ENDPOINT_ADDRS rows\r
-            sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
-            try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
+            try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {\r
                 for (String t : auth.getEndpointAddrs()) {\r
-                    ps2.setInt(1, feedid);\r
-                    ps2.setString(2, t);\r
-                    ps2.executeUpdate();\r
+                    ps.setInt(1, feedid);\r
+                    ps.setString(2, t);\r
+                    ps.executeUpdate();\r
                 }\r
             }\r
-\r
             // Finally, create the FEEDS row\r
-            sql = "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "\r
-                          + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"\r
-                          + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "\r
-                          + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
-            try (PreparedStatement ps2 = conn.prepareStatement(sql)) {\r
-                ps2.setInt(1, feedid);\r
-                ps2.setString(2, getName());\r
-                ps2.setString(3, getVersion());\r
-                ps2.setString(4, getDescription());\r
-                ps2.setString(5, getAuthorization().getClassification());\r
-                ps2.setString(6, getPublisher());\r
-                ps2.setString(7, getLinks().getSelf());\r
-                ps2.setString(8, getLinks().getPublish());\r
-                ps2.setString(9, getLinks().getSubscribe());\r
-                ps2.setString(10, getLinks().getLog());\r
-                ps2.setBoolean(11, isDeleted());\r
-                ps2.setBoolean(12, isSuspended());\r
-                ps2.setString(13, getBusiness_description());\r
-                ps2.setInt(14, groupid);\r
-                ps2.setString(15, getAafInstance());\r
-                ps2.executeUpdate();\r
+            try (PreparedStatement ps = conn.prepareStatement(\r
+                "insert into FEEDS (FEEDID, NAME, VERSION, DESCRIPTION, AUTH_CLASS, PUBLISHER, SELF_LINK, "\r
+                    + "PUBLISH_LINK, SUBSCRIBE_LINK, LOG_LINK, DELETED, SUSPENDED,"\r
+                    + "BUSINESS_DESCRIPTION, GROUPID, AAF_INSTANCE) "\r
+                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {\r
+                ps.setInt(1, feedid);\r
+                ps.setString(2, getName());\r
+                ps.setString(3, getVersion());\r
+                ps.setString(4, getDescription());\r
+                ps.setString(5, getAuthorization().getClassification());\r
+                ps.setString(6, getPublisher());\r
+                ps.setString(7, getLinks().getSelf());\r
+                ps.setString(8, getLinks().getPublish());\r
+                ps.setString(9, getLinks().getSubscribe());\r
+                ps.setString(10, getLinks().getLog());\r
+                ps.setBoolean(11, isDeleted());\r
+                ps.setBoolean(12, isSuspended());\r
+                ps.setString(13, getBusinessDescription());\r
+                ps.setInt(14, groupid);\r
+                ps.setString(15, getAafInstance());\r
+                ps.executeUpdate();\r
             }\r
         } catch (SQLException e) {\r
             rv = false;\r
@@ -702,88 +663,72 @@ public class Feed extends Syncable {
     @Override\r
     public boolean doUpdate(Connection conn) {\r
         boolean rv = true;\r
-        Feed oldobj = getFeedById(feedid);\r
-        PreparedStatement ps = null;\r
         try {\r
+            Feed oldobj = getFeedById(feedid);\r
             Set<FeedEndpointID> newset = getAuthorization().getEndpointIDS();\r
             Set<FeedEndpointID> oldset = oldobj.getAuthorization().getEndpointIDS();\r
-\r
-            // Insert new FEED_ENDPOINT_IDS rows\r
-            String sql = "insert into FEED_ENDPOINT_IDS values (?, ?, ?)";\r
-            ps = conn.prepareStatement(sql);\r
-            for (FeedEndpointID fid : newset) {\r
-                if (!oldset.contains(fid)) {\r
-                    ps.setInt(1, feedid);\r
-                    ps.setString(2, fid.getId());\r
-                    ps.setString(3, fid.getPassword());\r
-                    ps.executeUpdate();\r
+            try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_IDS values (?, ?, ?)")) {\r
+                // Insert new FEED_ENDPOINT_IDS rows\r
+                for (FeedEndpointID fid : newset) {\r
+                    if (!oldset.contains(fid)) {\r
+                        ps.setInt(1, feedid);\r
+                        ps.setString(2, fid.getId());\r
+                        ps.setString(3, fid.getPassword());\r
+                        ps.executeUpdate();\r
+                    }\r
                 }\r
             }\r
-            ps.close();\r
-\r
             // Delete old FEED_ENDPOINT_IDS rows\r
-            sql = "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?";\r
-            ps = conn.prepareStatement(sql);\r
-            for (FeedEndpointID fid : oldset) {\r
-                if (!newset.contains(fid)) {\r
-                    ps.setInt(1, feedid);\r
-                    ps.setString(2, fid.getId());\r
-                    ps.setString(3, fid.getPassword());\r
-                    ps.executeUpdate();\r
+            try (PreparedStatement ps = conn.prepareStatement(\r
+                "delete from FEED_ENDPOINT_IDS where FEEDID = ? AND USERID = ? AND PASSWORD = ?")) {\r
+                for (FeedEndpointID fid : oldset) {\r
+                    if (!newset.contains(fid)) {\r
+                        ps.setInt(1, feedid);\r
+                        ps.setString(2, fid.getId());\r
+                        ps.setString(3, fid.getPassword());\r
+                        ps.executeUpdate();\r
+                    }\r
                 }\r
             }\r
-            ps.close();\r
-\r
-            // Insert new FEED_ENDPOINT_ADDRS rows\r
             Set<String> newset2 = getAuthorization().getEndpointAddrs();\r
             Set<String> oldset2 = oldobj.getAuthorization().getEndpointAddrs();\r
-            sql = "insert into FEED_ENDPOINT_ADDRS values (?, ?)";\r
-            ps = conn.prepareStatement(sql);\r
-            for (String t : newset2) {\r
-                if (!oldset2.contains(t)) {\r
-                    ps.setInt(1, feedid);\r
-                    ps.setString(2, t);\r
-                    ps.executeUpdate();\r
+            // Insert new FEED_ENDPOINT_ADDRS rows\r
+            try (PreparedStatement ps = conn.prepareStatement("insert into FEED_ENDPOINT_ADDRS values (?, ?)")) {\r
+                for (String t : newset2) {\r
+                    if (!oldset2.contains(t)) {\r
+                        ps.setInt(1, feedid);\r
+                        ps.setString(2, t);\r
+                        ps.executeUpdate();\r
+                    }\r
                 }\r
             }\r
-            ps.close();\r
-\r
             // Delete old FEED_ENDPOINT_ADDRS rows\r
-            sql = "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?";\r
-            ps = conn.prepareStatement(sql);\r
-            for (String t : oldset2) {\r
-                if (!newset2.contains(t)) {\r
-                    ps.setInt(1, feedid);\r
-                    ps.setString(2, t);\r
-                    ps.executeUpdate();\r
+            try (PreparedStatement ps = conn.prepareStatement(\r
+                "delete from FEED_ENDPOINT_ADDRS where FEEDID = ? AND ADDR = ?")) {\r
+                for (String t : oldset2) {\r
+                    if (!newset2.contains(t)) {\r
+                        ps.setInt(1, feedid);\r
+                        ps.setString(2, t);\r
+                        ps.executeUpdate();\r
+                    }\r
                 }\r
             }\r
-            ps.close();\r
-\r
-            // Finally, update the FEEDS row\r
-            sql = "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "\r
-                          + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?";\r
-            ps = conn.prepareStatement(sql);\r
-            ps.setString(1, getDescription());\r
-            ps.setString(2, getAuthorization().getClassification());\r
-            ps.setInt(3, deleted ? 1 : 0);\r
-            ps.setInt(4, suspended ? 1 : 0);\r
-            ps.setString(5, getBusiness_description());\r
-            ps.setInt(6, groupid);\r
-            ps.setInt(7, feedid);\r
-            ps.executeUpdate();\r
-            ps.close();\r
+            try (PreparedStatement ps = conn.prepareStatement(\r
+                "update FEEDS set DESCRIPTION = ?, AUTH_CLASS = ?, DELETED = ?, SUSPENDED = ?, "\r
+                    + "BUSINESS_DESCRIPTION=?, GROUPID=? where FEEDID = ?")) {\r
+                // Finally, update the FEEDS row\r
+                ps.setString(1, getDescription());\r
+                ps.setString(2, getAuthorization().getClassification());\r
+                ps.setInt(3, deleted ? 1 : 0);\r
+                ps.setInt(4, suspended ? 1 : 0);\r
+                ps.setString(5, getBusinessDescription());\r
+                ps.setInt(6, groupid);\r
+                ps.setInt(7, feedid);\r
+                ps.executeUpdate();\r
+            }\r
         } catch (SQLException e) {\r
             rv = false;\r
             intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
-        } finally {\r
-            try {\r
-                if (ps != null) {\r
-                    ps.close();\r
-                }\r
-            } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -794,29 +739,15 @@ public class Feed extends Syncable {
      */\r
     public boolean changeOwnerShip() {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "update FEEDS set PUBLISHER = ? where FEEDID = ?";\r
-            ps = conn.prepareStatement(sql);\r
+        try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+            PreparedStatement ps = conn.prepareStatement(\r
+                "update FEEDS set PUBLISHER = ? where FEEDID = ?")) {\r
             ps.setString(1, this.publisher);\r
             ps.setInt(2, feedid);\r
             ps.execute();\r
-            ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
             intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);\r
-        } finally {\r
-            try {\r
-                if (ps != null) {\r
-                    ps.close();\r
-                }\r
-            } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r