1 19 package org.openharmonise.rm.dsi; 20 21 import java.util.logging.*; 22 import java.util.logging.Logger ; 23 24 import org.openharmonise.commons.dsi.*; 25 import org.openharmonise.rm.config.ConfigException; 26 27 28 37 public class DataStoreInterfaceFactory { 38 39 43 public static final String DSI_PNAME = "DSI_CLASS"; 44 45 48 public static final String DBURL_PNAME = "DB_URL"; 49 50 53 public static final String DBUSR_PNAME = "DB_USR"; 54 55 58 public static final String DBPWD_PNAME = "DB_PWD"; 59 60 64 public static final String DBDRV_PNAME = "DB_DRIVERNAME"; 65 66 69 private static String m_dsi_classname = null; 70 71 74 private static AbstractDataStoreInterface m_dsi = null; 75 76 79 private static final Logger m_logger = Logger.getLogger(DataStoreInterfaceFactory.class.getName()); 80 81 90 public static AbstractDataStoreInterface getDataStoreInterface() 91 throws DataStoreException { 92 93 if (m_dsi == null) { 94 95 String sDriver; 96 String sURL; 97 String sUsr; 98 String sPwd; 99 try { 100 m_dsi_classname = DatabaseSettings.getInstance().getDsiClass(); 101 sDriver = DatabaseSettings.getInstance().getDbDriver(); 102 sURL = DatabaseSettings.getInstance().getDbUrl(); 103 sUsr = DatabaseSettings.getInstance().getDbUser(); 104 sPwd = DatabaseSettings.getInstance().getDbPwd(); 105 } 106 catch (ConfigException e) { 107 throw new DataStoreException(e); 108 } 109 110 m_dsi = 111 getDataStoreInterface( 112 m_dsi_classname, 113 sDriver, 114 sURL, 115 sUsr, 116 sPwd); 117 118 } 119 120 return m_dsi; 121 } 122 123 136 public static AbstractDataStoreInterface getDataStoreInterface( 137 String sDSIclass, 138 String sDriver, 139 String sURL, 140 String sUsr, 141 String sPwd) 142 throws DataStoreException { 143 AbstractDataStoreInterface dbinterf = null; 144 145 if (sDSIclass == null) { 146 throw new DataStoreException("No datastoreinterface class name found"); 147 } 148 149 try { 150 Class cls = Class.forName(sDSIclass); 151 152 dbinterf = (AbstractDataStoreInterface) cls.newInstance(); 153 154 dbinterf.setDataStoreDetails(sDriver, sURL, sUsr, sPwd); 155 dbinterf.initialise( 156 AbstractDataStoreInterface.DB_CONNECTION_BROKER); 157 } catch (Exception e) { 158 m_logger.log(Level.WARNING, e.getLocalizedMessage(), e); 159 throw new DataStoreException("Couldn't create new datastoreinterface"); 160 } 161 162 return dbinterf; 163 } 164 } | Popular Tags |