X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Fbeans%2FParameters.java;h=78ed96dd9a00a9d6fe943427cc75a6012e8c462c;hb=f20778ffa99aa9c6f30a0f84112a5392b259ea63;hp=fff10ac7a45e45065f269c0d3f0b21992b201a5c;hpb=376688e95bd516282bc55ca88318b12043aa25dd;p=dmaap%2Fdatarouter.git 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 fff10ac7..78ed96dd 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 @@ -23,15 +23,18 @@ package org.onap.dmaap.datarouter.provisioning.beans; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.*; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; @@ -57,6 +60,7 @@ public class Parameters extends Syncable { public static final String PROV_POKETIMER2 = "PROV_POKETIMER2"; public static final String PROV_SPECIAL_SUBNET = "PROV_SPECIAL_SUBNET"; public static final String PROV_LOG_RETENTION = "PROV_LOG_RETENTION"; + public static final String DEFAULT_LOG_RETENTION = "DEFAULT_LOG_RETENTION"; public static final String NODES = "NODES"; public static final String ACTIVE_POD = "ACTIVE_POD"; public static final String STANDBY_POD = "STANDBY_POD"; @@ -66,7 +70,7 @@ public class Parameters extends Syncable { public static final String DELIVERY_RETRY_RATIO = "DELIVERY_RETRY_RATIO"; public static final String DELIVERY_MAX_AGE = "DELIVERY_MAX_AGE"; public static final String THROTTLE_FILTER = "THROTTLE_FILTER"; - public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610 + public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); private static final String SQLEXCEPTION = "SQLException: "; @@ -74,13 +78,23 @@ public class Parameters extends Syncable { private String keyname; private String value; + public Parameters(String k, String v) { + this.keyname = k; + this.value = v; + } + + public Parameters(ResultSet rs) throws SQLException { + this.keyname = rs.getString("KEYNAME"); + this.value = rs.getString("VALUE"); + } + /** * Get all parameters in the DB as a Map. * * @return the Map of keynames/values from the DB. */ public static Map getParameters() { - Map props = new HashMap(); + Map props = new HashMap<>(); for (Parameters p : getParameterCollection()) { props.put(p.getKeyname(), p.getValue()); } @@ -88,23 +102,20 @@ public class Parameters extends Syncable { } public static Collection getParameterCollection() { - Collection coll = new ArrayList(); - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - 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); - } + Collection coll = new ArrayList<>(); + DB db = new DB(); + String sql = "select * from PARAMETERS"; + try (Connection conn = db.getConnection(); + Statement stmt = conn.createStatement()) { + try (ResultSet rs = stmt.executeQuery(sql)) { + while (rs.next()) { + Parameters p = new Parameters(rs); + coll.add(p); } } db.release(conn); } catch (SQLException e) { - intlogger.error(SQLEXCEPTION + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } return coll; } @@ -117,48 +128,27 @@ public class Parameters extends Syncable { */ public static Parameters getParameter(String k) { Parameters v = null; - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - try (PreparedStatement stmt = conn - .prepareStatement("select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?")) { - stmt.setString(1, k); - try (ResultSet rs = stmt.executeQuery()) { - if (rs.next()) { - v = new Parameters(rs); - } + DB db = new DB(); + String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?"; + try (Connection conn = db.getConnection(); + PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, k); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + v = new Parameters(rs); } } db.release(conn); } catch (SQLException e) { - intlogger.error(SQLEXCEPTION + e.getMessage()); + intlogger.error(SQLEXCEPTION + e.getMessage(), e); } return v; } - public Parameters() { - this("", ""); - } - - public Parameters(String k, String v) { - this.keyname = k; - this.value = v; - } - - public Parameters(ResultSet rs) throws SQLException { - this.keyname = rs.getString("KEYNAME"); - this.value = rs.getString("VALUE"); - } - public String getKeyname() { return keyname; } - public void setKeyname(String keyname) { - this.keyname = keyname; - } - public String getValue() { return value; } @@ -178,25 +168,14 @@ public class Parameters extends Syncable { @Override public boolean doInsert(Connection c) { boolean rv = true; - PreparedStatement ps = null; - try { - // Create the SUBSCRIPTIONS row - String sql = "insert into PARAMETERS values (?, ?)"; - ps = c.prepareStatement(sql); + String sql = "insert into PARAMETERS values (?, ?)"; + try (PreparedStatement ps = c.prepareStatement(sql)) { ps.setString(1, getKeyname()); ps.setString(2, getValue()); ps.execute(); } catch (SQLException e) { rv = false; intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e); - } finally { - try { - if (ps != null) { - ps.close(); - } - } catch (SQLException e) { - intlogger.error(SQLEXCEPTION + e.getMessage()); - } } return rv; } @@ -204,25 +183,14 @@ public class Parameters extends Syncable { @Override public boolean doUpdate(Connection c) { boolean rv = true; - PreparedStatement ps = null; - try { - // Update the PARAMETERS row - String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?"; - ps = c.prepareStatement(sql); + String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?"; + try (PreparedStatement ps = c.prepareStatement(sql)) { ps.setString(1, getValue()); ps.setString(2, getKeyname()); ps.executeUpdate(); } catch (SQLException e) { rv = false; intlogger.warn("PROV0006 doUpdate: " + e.getMessage(),e); - } finally { - try { - if (ps != null) { - ps.close(); - } - } catch (SQLException e) { - intlogger.error(SQLEXCEPTION + e.getMessage(), e); - } } return rv; } @@ -230,24 +198,13 @@ public class Parameters extends Syncable { @Override public boolean doDelete(Connection c) { boolean rv = true; - PreparedStatement ps = null; - try { - // Create the SUBSCRIPTIONS row - String sql = "delete from PARAMETERS where KEYNAME = ?"; - ps = c.prepareStatement(sql); + String sql = "delete from PARAMETERS where KEYNAME = ?"; + try (PreparedStatement ps = c.prepareStatement(sql)) { ps.setString(1, getKeyname()); ps.execute(); } catch (SQLException e) { rv = false; intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e); - } finally { - try { - if (ps != null) { - ps.close(); - } - } catch (SQLException e) { - intlogger.error(SQLEXCEPTION + e.getMessage(), e); - } } return rv; } @@ -263,13 +220,7 @@ public class Parameters extends Syncable { return false; } Parameters of = (Parameters) obj; - if (!keyname.equals(of.keyname)) { - return false; - } - if (!value.equals(of.value)) { - return false; - } - return true; + return (!value.equals(of.value)) && (!keyname.equals(of.keyname)); } @Override