1 64 package com.jcorporate.expresso.core.db; 65 66 import com.jcorporate.expresso.core.misc.ConfigManager; 67 import com.jcorporate.expresso.kernel.LogManager; 68 69 70 88 public class DBInitializer { 89 90 private static String dbName = null; 91 92 95 private DBConnectionPool myPool = null; 96 97 100 private DBConnection myConnection = null; 101 102 103 108 public DBInitializer() throws DBException { 109 setDbName("default"); 110 } 111 112 113 118 public DBInitializer(String newDBName) throws DBException { 119 setDbName(newDBName); 120 } 121 122 128 public synchronized DBConnection initialize(String webAppDir, String configDir, String logDir) { 129 try { 130 if (configDir == null || "".equals(configDir) || 131 logDir == null || "".equals(logDir) || 132 webAppDir == null || "".equals(webAppDir)) { 133 return null; 134 } 135 136 String logConfig = configDir + "/expressoLogging.xml"; 137 138 LogManager lm = new LogManager(logConfig, logDir); 139 140 ConfigManager.setWebAppDir(webAppDir); 142 ConfigManager.load(configDir); 143 144 ConfigManager.dbInitialize(); 146 147 ConfigManager.mapOtherDBs(); 149 150 if (dbName.equals("")) { 151 dbName = "default"; 152 } 153 154 myPool = DBConnectionPool.getInstance(dbName); 155 if (myPool != null) { 156 myConnection = myPool.getConnection("DBInitialize"); 157 } else { 158 return null; 159 } 160 161 } catch (Exception de) { 162 System.out.println("DBInitialze Error:" + de.getMessage()); 163 de.printStackTrace(); 164 } 165 return myConnection; 166 } 167 168 public synchronized void close(DBConnection myConnection) throws DBException { 169 myConnection.clear(); 170 } 171 172 public synchronized void release(DBConnection myConnection) { 173 174 myPool.release(myConnection); 175 ConfigManager.destroy(); 176 } 177 178 181 public static String getDbName() { 182 return dbName; 183 } 184 185 188 public static void setDbName(String newDBName) { 189 if (newDBName != null) { 190 dbName = newDBName; 191 } else { 192 dbName = "default"; 193 } 194 } 195 196 } 197 | Popular Tags |