package com.seeyon.apps.src_contract.lease.kit;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;



/**
 * 读取参数
 */

public class PropJDBCKit {
	
	private static long lastModify;
	
	private static ConcurrentHashMap<String, String> props;
    
    public static final String PROFILE = "profile";
    
    public static final String JDBCDRIVER = "jdbcdriver";
    public static final String JDBCURL = "jdbcurl";
    public static final String JDBCUSER = "jdbcuser";
    public static final String JDBCPASSWORD = "jdbcpassword";
    
    public static final String PROD_JDBCDRIVER = "prod.jdbcdriver";
    public static final String PROD_JDBCURL = "prod.jdbcurl";
    public static final String PROD_JDBCUSER = "prod.jdbcuser";
    public static final String PROD_JDBCPASSWORD = "prod.jdbcpassword";
    
    /**
     * @return
     * @throws IOException 
     * @throws FileNotFoundException 
     */
    public static String getProp(String key) throws FileNotFoundException, IOException {
		File f = new File(A8FolderKit.getPropJDBCFile());
		if(null == props) {
			props = new ConcurrentHashMap<String, String>();
		}
		if(f.lastModified() != lastModify) {
			/**
			 * huangzhengguo 
			 * 2022-10-18
			 */
			Properties prop = new Properties();
			prop.load(new FileInputStream(f));
//			Properties prop = PropertiesUtil.getFromFile((CtpLocalFile) f);
			/**
			 * end
			 */
			String profile = prop.getProperty(PROFILE);
			if("prod".equals(profile)) {
				props.put(JDBCDRIVER, prop.getProperty(PROD_JDBCDRIVER));
				props.put(JDBCURL, prop.getProperty(PROD_JDBCURL));
				props.put(JDBCUSER, prop.getProperty(PROD_JDBCUSER));
				props.put(JDBCPASSWORD, prop.getProperty(PROD_JDBCPASSWORD));
			} else {
				props.put(JDBCDRIVER, prop.getProperty(PROD_JDBCDRIVER));
				props.put(JDBCURL, prop.getProperty(PROD_JDBCURL));
				props.put(JDBCUSER, prop.getProperty(PROD_JDBCUSER));
				props.put(JDBCPASSWORD, prop.getProperty(PROD_JDBCPASSWORD));
			}
		}
		return props.get(key);
    }
  
}
