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