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=08914868b85b499c1e9bcd947b517538acb2dbc6;hb=refs%2Fchanges%2F51%2F78851%2F11;hp=8e9d5bfd32b4dd4cb5b748349b9131cc7accbc94;hpb=e78029abb4dd73bf14e0291096d5b6762c55739b;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 8e9d5bfd..08914868 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,23 +28,22 @@ 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 com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.json.JSONObject; import org.onap.dmaap.datarouter.provisioning.utils.DB; /** - * Methods to provide access to Provisioning parameters in the DB. - * This class also provides constants of the standard parameters used by the Data Router. + * Methods to provide access to Provisioning parameters in the DB. This class also provides constants of the standard + * parameters used by the Data Router. * * @author Robert Eby * @version $Id: Parameters.java,v 1.11 2014/03/12 19:45:41 eby Exp $ */ public class Parameters extends Syncable { + public static final String PROV_REQUIRE_SECURE = "PROV_REQUIRE_SECURE"; public static final String PROV_REQUIRE_CERT = "PROV_REQUIRE_CERT"; public static final String PROV_AUTH_ADDRESSES = "PROV_AUTH_ADDRESSES"; @@ -69,7 +68,7 @@ public class Parameters extends Syncable { 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 - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog"); private String keyname; private String value; @@ -93,18 +92,18 @@ 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(); + intlogger.error("SQLException " + e.getMessage()); } return coll; } @@ -121,17 +120,18 @@ 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 (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); + } + } } - rs.close(); - stmt.close(); db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } return v; } @@ -188,12 +188,13 @@ public class Parameters extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); } finally { try { - ps.close(); + if (ps != null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -213,12 +214,13 @@ public class Parameters extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0006 doUpdate: " + e.getMessage()); - e.printStackTrace(); } finally { try { - ps.close(); + if (ps != null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -237,12 +239,13 @@ public class Parameters extends Syncable { } catch (SQLException e) { rv = false; intlogger.warn("PROV0007 doDelete: " + e.getMessage()); - e.printStackTrace(); } finally { try { - ps.close(); + if (ps != null) { + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intlogger.error("SQLException " + e.getMessage()); } } return rv; @@ -255,16 +258,24 @@ public class Parameters extends Syncable { @Override public boolean equals(Object obj) { - if (!(obj instanceof Parameters)) + if (!(obj instanceof Parameters)) { return false; + } Parameters of = (Parameters) obj; - if (!keyname.equals(of.keyname)) + if (!keyname.equals(of.keyname)) { return false; - if (!value.equals(of.value)) + } + if (!value.equals(of.value)) { return false; + } return true; } + @Override + public int hashCode() { + return Objects.hash(keyname, value); + } + @Override public String toString() { return "PARAM: keyname=" + keyname + ", value=" + value;