Fixing code as part of dmaap-775
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / DB.java
index 7f0d56b..1952f94 100644 (file)
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+import java.io.LineNumberReader;\r
+import java.sql.Connection;\r
+import java.sql.DatabaseMetaData;\r
+import java.sql.DriverManager;\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+import java.sql.Statement;\r
+import java.util.HashSet;\r
+import java.util.LinkedList;\r
+import java.util.NoSuchElementException;\r
+import java.util.Properties;\r
+import java.util.Queue;\r
+import java.util.Set;\r
 import org.apache.log4j.Logger;\r
 \r
-import java.io.*;\r
-import java.sql.*;\r
-import java.util.*;\r
-\r
 /**\r
  * Load the DB JDBC driver, and manage a simple pool of connections to the DB.\r
  *\r
@@ -38,7 +51,8 @@ import java.util.*;
  */\r
 public class DB {\r
 \r
-    private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
+    private static Logger intlogger = Logger\r
+        .getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
 \r
     private static String DB_URL;\r
     private static String DB_LOGIN;\r
@@ -46,12 +60,12 @@ public class DB {
     private static Properties props;\r
     private static final Queue<Connection> queue = new LinkedList<>();\r
 \r
-    public static String HTTPS_PORT;\r
-    public static String HTTP_PORT;\r
+    private static String HTTPS_PORT;\r
+    private static String HTTP_PORT;\r
 \r
     /**\r
      * Construct a DB object.  If this is the very first creation of this object, it will load a copy of the properties\r
-     * for the server, and attempt to load the JDBC driver for the database.  If a fatal error occurs (e.g. either the\r
+     * for the server, and attempt to load the JDBC driver for the database. If a fatal error occurs (e.g. either the\r
      * properties file or the DB driver is missing), the JVM will exit.\r
      */\r
     public DB() {\r
@@ -70,11 +84,9 @@ public class DB {
                 Class.forName(DB_DRIVER);\r
             } catch (IOException e) {\r
                 intlogger.fatal("PROV9003 Opening properties: " + e.getMessage());\r
-                e.printStackTrace();\r
                 System.exit(1);\r
             } catch (ClassNotFoundException e) {\r
                 intlogger.fatal("PROV9004 cannot find the DB driver: " + e);\r
-                e.printStackTrace();\r
                 System.exit(1);\r
             }\r
         }\r
@@ -111,8 +123,7 @@ public class DB {
                             if (++n >= 3) {\r
                                 throw sqlEx;\r
                             }\r
-                        }\r
-                        finally {\r
+                        } finally {\r
                             if (connection != null && !connection.isValid(1)) {\r
                                 connection.close();\r
                                 connection = null;\r
@@ -151,6 +162,15 @@ public class DB {
         return retroFit1();\r
     }\r
 \r
+\r
+    public static String getHttpsPort() {\r
+        return HTTPS_PORT;\r
+    }\r
+\r
+    public static String getHttpPort() {\r
+        return HTTP_PORT;\r
+    }\r
+\r
     /**\r
      * Retrofit 1 - Make sure the expected tables are in DB and are initialized. Uses sql_init_01.sql to setup the DB.\r
      *\r
@@ -175,7 +195,8 @@ public class DB {
                 runInitScript(connection, 1);\r
             }\r
         } catch (SQLException e) {\r
-            intlogger.fatal("PROV9000: The database credentials are not working: " + e.getMessage());\r
+            intlogger\r
+                .fatal("PROV9000: The database credentials are not working: " + e.getMessage());\r
             return false;\r
         } finally {\r
             if (connection != null) {\r
@@ -210,7 +231,8 @@ public class DB {
 \r
     /**\r
      * Initialize the tables by running the initialization scripts located in the directory specified by the property\r
-     * <i>org.onap.dmaap.datarouter.provserver.dbscripts</i>.  Scripts have names of the form sql_init_NN.sql\r
+     * <i>org.onap.dmaap.datarouter.provserver.dbscripts</i>.  Scripts have names of the form\r
+     * sql_init_NN.sql\r
      *\r
      * @param connection a DB connection\r
      * @param scriptId the number of the sql_init_NN.sql script to run\r