import java.util.*;
import java.lang.*;
import com.javaexchange.dbConnectionBroker.*;
+import mir.storage.StorageObjectException;
+import com.codestudio.util.*;
/**
* Title: Mir
*/
public class MirConfig extends Configuration {
-
+
private static HashMap configHash = new HashMap();
private static HashMap brokerHash = new HashMap();
private static int instances=0;
configHash.put("Home", home);
configHash.put("RootUri", uri);
- configHash.put("ServletName", name);
-
+
Enumeration resKeys = getResourceKeys();
while(resKeys.hasMoreElements()) {
String keyNm = (String)resKeys.nextElement();
configHash.put(keyNm, getProperty(keyNm));
}
}
-
/**
* Returns the property asked for by pulling it out a HashMap
* @param a String containing the property name (key)
* @return a String containing the prop. value
*/
- public static String getProp(String PropName) {
- return (String)configHash.get(PropName);
+ public static void setServletName(String servletName) {
+ configHash.put("ServletName",servletName);
+ }
+
+ /**
+ * Returns the property asked for by pulling it out a HashMap
+ * @param a String containing the property name (key)
+ * @return a String containing the prop. value
+ */
+ public static String getProp(String propName) {
+ return (String)configHash.get(propName);
+ }
+
+ /**
+ * Returns the property asked for by pulling it out a HashMap and
+ * appending it to configproperty "Home"
+ * @param a String containing the property name (key)
+ * @return a String containing the prop.value
+ */
+ public static String getPropWithHome(String propName) {
+ return (String)configHash.get("Home") +
+ (String)configHash.get(propName);
+ }
+
+ public static void addBroker(String driver, String URL) throws StorageObjectException {
+
+ String username,passwd,min,max,log,reset;
+
+ if(!brokerHash.containsKey("Pool.broker")){
+ username=getProp("Database.Username");
+ passwd=getProp("Database.Password");
+ min=getProp("Database.poolMin");
+ max=getProp("Database.poolMax");
+ log=getProp("Home") + configHash.get("Database.PoolLog");
+ reset=getProp("Database.poolResetTime");
+
+ System.err.println("-- making Broker for -"
+ +driver+" - " +URL
+ + " log " + log + " user "
+ + username + " pass: " + passwd);
+
+ JDBCPoolMetaData meta = new JDBCPoolMetaData();
+ meta.setDbname("mir");
+ meta.setDriver(driver);
+ meta.setURL(URL);
+ meta.setUserName(username);
+ meta.setPassword(passwd);
+ meta.setJNDIName("mir");
+ meta.setMaximumSize(Integer.parseInt(max));
+ meta.setMinimumSize(Integer.parseInt(min));
+
+ JDBCPool pool = SQLManager.getInstance().createPool(meta);
+ SQLManager.getInstance().addPool("mir",pool);
+
+ if (pool!=null){
+ instances++;
+ brokerHash.put("Pool.broker",pool);
+ }
+
+ } // end if
}
- public static void addBroker(String driver, String URL){
+ public static void addBroker2(String driver, String URL) throws StorageObjectException {
- System.err.println("--trying to add broker");
String username,passwd,min,max,log,reset;
if(!brokerHash.containsKey("Pool.broker")){
if (br!=null){
instances++;
brokerHash.put("Pool.broker",br);
- } else {
- throw new Exception();
}
- } catch(Exception e){
+ } catch(IOException e){
System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
+ throw new StorageObjectException(e.toString());
}
} // end if
}
/**
- * Liefert DBConnectionBroker einer Configuration zurueck
- * @param confFilename
- * @return DBConnectionBroker
- */
- public static DbConnectionBroker getBroker() {
- DbConnectionBroker broker=null;
- broker=(DbConnectionBroker)brokerHash.get("Pool.broker");
- if (broker==null) {
- System.err.println("Konnte kein ConnectionPoolBroker initialisiert werden");
- }
- return broker;
- }
-
- /**
- * Liefert Anzahl der Instantiierten DBConnectionBroker zurueck
- * @return
- */
- public static int getBrokerInstances() {
- return instances;
- }
-
- public static DbConnectionBroker getBrokerInfo(){
- return (DbConnectionBroker)brokerHash.get("Pool.broker");
- }
-
- /**
- * Finalize Methode
+ * Finalize method
*/
public void finalize(){
instances --;