package net.ajed.event.persistence;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Properties;


/**
 * A generic persistence facade to decouple the database specific code.
 * This application has been built with MongoDB in mind and with this class as an abstraction
 * instead of working directly with the Mongo driver here.
 */
public class Persistence {
    Logger logger = LoggerFactory.getLogger(Persistence.class);
    private HashMap<String, String> configuration = new HashMap<>();

    public Persistence(String configFileRelativePathName){

        logger.info("Reading db.config");

        boolean successfulLoad = false;
        try{
            successfulLoad = getProperties(configFileRelativePathName);
        } catch (IOException e){
            logger.error("Failed to load properties from db.config.", e);
        }
        if (!successfulLoad)
            logger.info("Failed to load configuration files successfully");
    }

    public HashMap<String, String> getConfiguration(){
        //TODO: Placeholder. WIP.
        return null;
    }

    private boolean getProperties(String configFileRelativePathName) throws IOException {
        //InputStream inputStream = null;
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(configFileRelativePathName);)  {
            Properties properties = new Properties();
            //inputStream = getClass().getClassLoader().getResourceAsStream(configFileRelativePathName);

            if (inputStream != null) {
                properties.load(inputStream);
            } else {
                throw new FileNotFoundException("property file '" + configFileRelativePathName + "' not found.");
            }

            String type = properties.getProperty("persistence_implementation");
            // TODO: Continue fetching properties


        } catch (Exception e) {
            logger.error("In getProperties()", e);
            throw e;
        } 
        //finally {
        //    inputStream.close();
        //}
        return true;
    }


}

@@ -30,17 +30,16 @@
 tence;%0A%0A
-%0A
 import o
@@ -87,17 +87,16 @@
 actory;%0A
-%0A
 import j
@@ -237,17 +237,16 @@
 rties;%0A%0A
-%0A
 /**%0A * A
@@ -690,17 +690,16 @@
 hName)%7B%0A
-%0A
         
@@ -732,17 +732,16 @@
 nfig%22);%0A
-%0A
         
@@ -1081,25 +1081,29 @@
 ly%22);%0A    %7D%0A
+    
 %0A
-
     public H
@@ -1202,25 +1202,29 @@
 null;%0A    %7D%0A
+    
 %0A
-
     private 
@@ -1305,50 +1305,8 @@
 n %7B%0A
-        //InputStream inputStream = null;%0A
     
@@ -1479,114 +1479,8 @@
 ();%0A
-            //inputStream = getClass().getClassLoader().getResourceAsStream(configFileRelativePathName);%0A%0A
     
@@ -1709,17 +1709,16 @@
       %7D%0A
-%0A
         
@@ -1839,18 +1839,16 @@
 perties%0A
-%0A%0A
         
@@ -1958,75 +1958,8 @@
  %7D %0A
-        //finally %7B%0A        //    inputStream.close();%0A        //%7D%0A
     
@@ -1979,14 +1979,12 @@
 ue;%0A
+
     %7D%0A
-%0A%0A
 %7D%0A

Update Persistence.java