diff options
Diffstat (limited to 'ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util')
2 files changed, 85 insertions, 40 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/RemDbInfo.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/RemDbInfo.java index 0b9e08c7..57c1e31d 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/RemDbInfo.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/RemDbInfo.java @@ -37,24 +37,40 @@ */ package org.onap.portalsdk.analytics.util; +import java.sql.Connection; import java.util.HashMap; +import javax.servlet.ServletContext; + import org.onap.portalsdk.analytics.system.DbUtils; import org.onap.portalsdk.analytics.system.Globals; +import org.onap.portalsdk.analytics.system.fusion.adapter.RaptorAdapter; +import org.onap.portalsdk.analytics.system.fusion.adapter.SpringContext; + +import com.mchange.v2.c3p0.ComboPooledDataSource; public class RemDbInfo { private HashMap remDbMap = null; private HashMap remDbTypeMap = null; + private HashMap remDbConnectionMap = null; public RemDbInfo() throws Exception { if (remDbMap == null) { load(); } } + + private RaptorAdapter raptorAdapter; + + + public void initializeDbUtils(ServletContext servletContext) { + raptorAdapter = (RaptorAdapter)SpringContext.getApplicationContext().getBean("raptorAdapter"); + } // initializeDbUtils public void load() throws Exception { remDbMap = new HashMap(); remDbTypeMap = new HashMap(); + remDbConnectionMap = new HashMap(); try { //String query = " SELECT a.SCHEMA_ID, a.SCHEMA_DESC, DATASOURCE_TYPE, rownum id FROM SCHEMA_INFO a " + // " where schema_id = 'local' union " + @@ -65,20 +81,35 @@ public class RemDbInfo { Globals.getDbUtils(); ds = DbUtils.executeQuery(query); - String prefix = "", desc = "", dbType = ""; + String prefix = "", desc = "", dbType = "", connectionUrl = "", username = "", password = "", driver_class = ""; if(ds.getRowCount() > 0) { for (int i = 0; i < ds.getRowCount(); i++) { - prefix = ds.getItem(i, 0); - desc = ds.getItem(i, 1); - dbType = ds.getItem(i, 2); + prefix = ds.getItem(i, 0); + desc = ds.getItem(i, 1); + dbType = ds.getItem(i, 2); + connectionUrl = ds.getItem(i, 3); + username = ds.getItem(i, 4); + password = ds.getItem(i, 5); + driver_class = ds.getItem(i, 6); + + ComboPooledDataSource cpds = new ComboPooledDataSource(); + cpds.setDriverClass( driver_class ); //loads the jdbc driver + cpds.setJdbcUrl( connectionUrl); + cpds.setUser(username); + cpds.setPassword(password); + + + remDbMap.put(prefix, desc); remDbTypeMap.put(prefix, dbType); + remDbConnectionMap.put(prefix, cpds); } } else { remDbMap.put("local", "local"); remDbTypeMap.put("local", Globals.getDBType()); + remDbConnectionMap.put("local", raptorAdapter.getConnection()); } } catch (Exception e) {} @@ -100,6 +131,19 @@ public class RemDbInfo { return ""; } + + public Connection getDBConnection(String prefix) { + if ((remDbConnectionMap != null) && (remDbConnectionMap.containsKey(prefix))) { + try { + return ((ComboPooledDataSource) remDbConnectionMap.get(prefix)).getConnection(); + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } + + return null; + } public HashMap getDbHash() { return remDbMap; diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java index 12355573..b5390c92 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/util/jar/ExtractJar.java @@ -73,17 +73,18 @@ public class ExtractJar { * @throws Exception */ public static void readJar(File jarFile) throws Exception { - JarInputStream in = new JarInputStream(new FileInputStream(jarFile)); - JarEntry je; - while ((je = in.getNextJarEntry()) != null) { - if (je.isDirectory() == false) { - if (je.getName().startsWith("org/onap/portalsdk/analytics/config/")) { - System.out.println(je.getName() + " " + je.getTime()); - + try(JarInputStream in = new JarInputStream(new FileInputStream(jarFile))) + { + JarEntry je; + while ((je = in.getNextJarEntry()) != null) { + if (je.isDirectory() == false) { + if (je.getName().startsWith("org/onap/portalsdk/analytics/config/")) { + System.out.println(je.getName() + " " + je.getTime()); + + } } } } - in.close(); } /** @@ -95,37 +96,37 @@ public class ExtractJar { Class clazz = ExtractJar.class; URL jarUrl = clazz.getProtectionDomain().getCodeSource().getLocation(); - JarInputStream entryStream = new JarInputStream(jarUrl.openStream()); - JarEntry entry; - - while (true) { - entry = entryStream.getNextJarEntry(); - if (entry == null) - break; - if (entry.getName().indexOf("jarutil") < 0) { - System.out.println(entry.getName()); - File file = new File(directory, entry.getName()); - if (entry.isDirectory()) { - if (!file.exists()) - file.mkdirs(); - } else { - File dir = new File(file.getParent()); - if (!dir.exists()) - dir.mkdirs(); - if (file.exists()) - file.delete(); - FileOutputStream fout = new FileOutputStream(file); - copy(entryStream, fout); - fout.close(); - - if (entry.getTime() >= 0) - file.setLastModified(entry.getTime()); + try(JarInputStream entryStream = new JarInputStream(jarUrl.openStream())){ + JarEntry entry; + + while (true) { + entry = entryStream.getNextJarEntry(); + if (entry == null) + break; + if (entry.getName().indexOf("jarutil") < 0) { + System.out.println(entry.getName()); + File file = new File(directory, entry.getName()); + if (entry.isDirectory()) { + if (!file.exists()) + file.mkdirs(); + } else { + File dir = new File(file.getParent()); + if (!dir.exists()) + dir.mkdirs(); + if (file.exists()) + file.delete(); + try(FileOutputStream fout = new FileOutputStream(file)){ + copy(entryStream, fout); + } + + if (entry.getTime() >= 0) + file.setLastModified(entry.getTime()); + } + } - + entryStream.closeEntry(); } - entryStream.closeEntry(); } - entryStream.close(); System.out.println("/WEB-INF/classes/org/onap/portalsdk/analytics"); System.out.println("Delete .... "); |