dbpoolman instead of connectionbroker
authoridfx <idfx>
Thu, 7 Feb 2002 13:46:16 +0000 (13:46 +0000)
committeridfx <idfx>
Thu, 7 Feb 2002 13:46:16 +0000 (13:46 +0000)
build.xml
lib/jdbc-se2.0.jar [new file with mode: 0755]
lib/log4j.jar [new file with mode: 0755]
lib/poolman.jar [new file with mode: 0755]
source/Mir.java
source/mir/misc/MirConfig.java
source/mir/servlet/ServletModuleMonitor.java
source/mir/storage/Database.java

index 83bbe4c..11c97f7 100755 (executable)
--- a/build.xml
+++ b/build.xml
@@ -38,7 +38,6 @@
   <property name="dist.src"       value="${app.name}.jar"/>
   <property name="dist.war"       value="${app.name}.war"/>
   <property name="javadoc.home"   value="${deploy.home}/javadoc"/>
-  <property name="build.compiler"   value="jikes"/>
 
 
 <!-- The "prepare" target is used to construct the deployment home
     <copy   todir="${deploy.home}/WEB-INF/classes">
       <fileset dir="source" includes="**/*.properties"/>
     </copy>
+    <copy   todir="${deploy.home}/WEB-INF/classes">
+      <fileset dir="source" includes="**/*.xml"/>
+    </copy>
     <copy   todir="${deploy.home}">
       <fileset dir="source" includes="**/content-types.properties"/>
-      <fileset dir="source" includes="**/server.xml"/>
     </copy>
   </target>
 
diff --git a/lib/jdbc-se2.0.jar b/lib/jdbc-se2.0.jar
new file mode 100755 (executable)
index 0000000..7b6e322
Binary files /dev/null and b/lib/jdbc-se2.0.jar differ
diff --git a/lib/log4j.jar b/lib/log4j.jar
new file mode 100755 (executable)
index 0000000..dc2d758
Binary files /dev/null and b/lib/log4j.jar differ
diff --git a/lib/poolman.jar b/lib/poolman.jar
new file mode 100755 (executable)
index 0000000..d3de5b5
Binary files /dev/null and b/lib/poolman.jar differ
index 3ba6738..1c0de3e 100755 (executable)
@@ -214,8 +214,11 @@ public class Mir extends AbstractServlet
     try {
       if (usersModule == null) usersModule = new ModuleUsers(DatabaseUsers.getInstance());
       return usersModule.getUserForLogin(user, password);
+    } catch(Exception e) {
+      theLog.printDebugInfo(e.toString());
+      e.printStackTrace();
+      return null;
     }
-    catch(Exception e) { theLog.printDebugInfo(e.toString()); return null; }
   }
 
   // Redirect-methods
index 0cf4859..9910b55 100755 (executable)
@@ -6,7 +6,8 @@ import  java.io.*;
 import  java.util.*;
 import  java.lang.*;
 import  com.javaexchange.dbConnectionBroker.*;
-import         mir.storage.StorageObjectException;
+import  mir.storage.StorageObjectException;
+import com.codestudio.util.*;
 
 /**
  * Title:        Mir
@@ -79,7 +80,7 @@ public class MirConfig extends Configuration {
     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;
@@ -92,6 +93,44 @@ public class MirConfig extends Configuration {
       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 addBroker2(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");
+
       try{
         System.err.println("-- making Broker for -"
                             +driver+" - " +URL
@@ -107,37 +146,11 @@ public class MirConfig extends Configuration {
       } 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 method
    */
   public void finalize(){
index 3bfdd1f..ee8f541 100755 (executable)
@@ -40,7 +40,6 @@ public class ServletModuleMonitor extends ServletModule
       getSimpleInfo(res.getWriter(),getConfs());
       PrintWriter out = res.getWriter();
       out.println(getInstancesInfo());
-      out.println(getInstancesConfInfo());
 
     }
     catch (Exception e) {
@@ -55,19 +54,13 @@ public class ServletModuleMonitor extends ServletModule
   public String getInstancesInfo(){
     return "<table><tr><td>Momentan instanzierte EntityObjekte = </td><td>" + getInstances()+"</td></tr></table>\n";
   }
-  public String getInstancesConfInfo(){
-    return "<table><tr><td>Momentan instanzierte BrokerObjekte  = </td><td>" + getConfBrokerCnt()+"</td></tr></table>\n";
-  }
-
   protected HashMap getConfs(){
     return Configuration.getConfs();
   }
   protected int getBrokerUseCnt(DbConnectionBroker broker){
     return broker.getUseCount();
   }
-  protected int getConfBrokerCnt(){
-    return MirConfig.getBrokerInstances();
-  }
+
   protected int getBrokerSize(DbConnectionBroker broker){
     return broker.getSize();
   }
@@ -79,13 +72,11 @@ public class ServletModuleMonitor extends ServletModule
     String key;
     DbConnectionBroker broker = null;
     out.write(getInstancesInfo());
-    out.write(getInstancesConfInfo());
     Set set = confs.keySet();
     Iterator it = set.iterator();
     for (int i=0;i<set.size();i++){
       key=(String)it.next();
       out.write("<table><tr><td>Konfiguration : </td><td>" + confs.get(key)+ "</td></tr>\n" );
-      broker=MirConfig.getBrokerInfo();
       //broker=(DbConnectionBroker) ((HashMap)confs.get(key)).get("Pool.broker");
       if(broker!=null)  out.write(getBrokerInfo(broker));
       else
index 32eb579..ec48710 100755 (executable)
@@ -12,6 +12,9 @@ import  com.javaexchange.dbConnectionBroker.*;
 import  mir.storage.StorageObject;
 import  mir.entity.*;
 import  mir.misc.*;
+import com.codestudio.sql.*;
+import com.codestudio.sql.*;
+import com.codestudio.util.*;
 
 
 /**
@@ -72,7 +75,7 @@ public class Database implements StorageObject {
       database_url=theAdaptor.getURL(database_username,database_password,database_host);
       theLog.printDebugInfo("adding Broker with: " +database_driver+":"+database_url  );
       MirConfig.addBroker(database_driver,database_url);
-      myBroker=MirConfig.getBroker();
+      //myBroker=MirConfig.getBroker();
     }
     catch (Exception e){
       theLog.printError("Bei Konstruktion von Database() with " + theAdaptorName + " -- " +e.toString());
@@ -1043,13 +1046,30 @@ public class Database implements StorageObject {
       throwSQLException(sqe, "disconnectPool");
     }
   }
+  
+  public Connection getPooledCon() throws StorageObjectException {
+    try{
+      Class.forName("com.codestudio.sql.PoolMan").newInstance();
+    } catch (Exception e){
+      e.printStackTrace();
+      throw new StorageObjectException("Could not find the PoolMan Driver"+e.toString());
+    }
+    Connection con = null;
+    try{
+      con = SQLManager.getInstance().requestConnection();
+    } catch(SQLException e){
+      e.printStackTrace();
+      throw new StorageObjectException("No connection to the database");
+    }
+    return con;
+  }
 
   /**
    * Returns Connection-Object out of the PoolBroker.
    *
    * @return Connection Object.
    */
-  public Connection getPooledCon () throws StorageObjectException {
+  public Connection getPooledCon2() throws StorageObjectException {
     if (myBroker != null) {
       Connection con = myBroker.getConnection();
       if (con != null)
@@ -1064,7 +1084,7 @@ public class Database implements StorageObject {
    * @param con Connection zur Datenbank
    * @param stmt Statement-Objekt
    */
-  public void freeConnection (Connection con, Statement stmt)
+  public void freeConnection2 (Connection con, Statement stmt)
     throws StorageObjectException {
     try {
       if (stmt != null)
@@ -1080,6 +1100,12 @@ public class Database implements StorageObject {
       throw new StorageObjectException("Con was null!");
     }
   }
+  
+  public void freeConnection (Connection con, Statement stmt)
+    throws StorageObjectException {
+    SQLManager.getInstance().closeStatement(stmt);
+    SQLManager.getInstance().returnConnection(con);
+  }
 
   /**
    * Wertet SQLException aus und wirft dannach eine StorageObjectException