poolman instead of connectionbroker
authoridfx <idfx>
Thu, 7 Feb 2002 14:17:11 +0000 (14:17 +0000)
committeridfx <idfx>
Thu, 7 Feb 2002 14:17:11 +0000 (14:17 +0000)
source/config.properties-dist
source/mir/misc/MirConfig.java
source/mir/servlet/ServletModuleMonitor.java
source/mir/storage/Database.java

index 3684fa0..3c67853 100755 (executable)
@@ -146,6 +146,7 @@ Database.Limit=20
 Database.Username=postgres
 Database.Password=
 Database.Host=localhost
+Database..Name=Mir
 
 #
 # this sets the adaptor to be used
index 9910b55..f8bd026 100755 (executable)
@@ -5,7 +5,6 @@ import  java.net.*;
 import  java.io.*;
 import  java.util.*;
 import  java.lang.*;
-import  com.javaexchange.dbConnectionBroker.*;
 import  mir.storage.StorageObjectException;
 import com.codestudio.util.*;
 
@@ -83,13 +82,14 @@ public class MirConfig extends Configuration {
   
   public static void addBroker(String driver, String URL) throws StorageObjectException {
 
-    String username,passwd,min,max,log,reset;
+    String username,passwd,min,max,log,reset,dbname;
 
     if(!brokerHash.containsKey("Pool.broker")){
       username=getProp("Database.Username");
       passwd=getProp("Database.Password");
       min=getProp("Database.poolMin");
       max=getProp("Database.poolMax");
+      dbname=getProp("Database.Name");
       log=getProp("Home") + configHash.get("Database.PoolLog");
       reset=getProp("Database.poolResetTime");
 
@@ -99,7 +99,7 @@ public class MirConfig extends Configuration {
                           + username + " pass: " + passwd);
 
       JDBCPoolMetaData meta = new JDBCPoolMetaData();
-      meta.setDbname("mir");
+      meta.setDbname(dbname);
       meta.setDriver(driver);
       meta.setURL(URL);
       meta.setUserName(username);
@@ -107,9 +107,10 @@ public class MirConfig extends Configuration {
       meta.setJNDIName("mir");
       meta.setMaximumSize(Integer.parseInt(max));
       meta.setMinimumSize(Integer.parseInt(min));
+      meta.setCacheEnabled(true);
+      meta.setDebugging(true);
       
       JDBCPool pool = SQLManager.getInstance().createPool(meta);
-      SQLManager.getInstance().addPool("mir",pool);
           
       if (pool!=null){
         instances++;
@@ -119,37 +120,6 @@ public class MirConfig extends Configuration {
     } // 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
-                            + " log " + log + " user "
-                            + username + " pass: " + passwd);
-
-        DbConnectionBroker br = new DbConnectionBroker(driver,URL,username,passwd,(new Integer(min)).intValue(),
-                                                      (new Integer(max)).intValue(),log,(new Float(reset)).floatValue());
-        if (br!=null){
-          instances++;
-          brokerHash.put("Pool.broker",br);
-        }
-      } catch(IOException e){
-        System.err.println("Der ConnectionBroker konnte nicht initializiert werden"+ e.toString());e.printStackTrace();
-        throw new StorageObjectException(e.toString());
-      }
-    } // end if
-  }
-
   /**
    * Finalize method
    */
index ee8f541..2356975 100755 (executable)
@@ -14,7 +14,6 @@ import mir.misc.*;
 import mir.storage.*;
 import mir.entity.*;
 
-import com.javaexchange.dbConnectionBroker.*;
 /*
  *  ServletModuleShow -
  *  liefert HTML fuer Show
@@ -37,7 +36,7 @@ public class ServletModuleMonitor extends ServletModule
       // instances in AbstractEntity
       // eingelesene confs
       // datenbankverbindungen fuer brokers
-      getSimpleInfo(res.getWriter(),getConfs());
+      //getSimpleInfo(res.getWriter(),getConfs());
       PrintWriter out = res.getWriter();
       out.println(getInstancesInfo());
 
@@ -57,32 +56,5 @@ public class ServletModuleMonitor extends ServletModule
   protected HashMap getConfs(){
     return Configuration.getConfs();
   }
-  protected int getBrokerUseCnt(DbConnectionBroker broker){
-    return broker.getUseCount();
-  }
-
-  protected int getBrokerSize(DbConnectionBroker broker){
-    return broker.getSize();
-  }
-  public String getBrokerInfo(DbConnectionBroker broker){
-    return "<tr><td>Connections im pool                  = </td><td>"+ broker.getSize() + "</td></tr>\n"+
-           "<tr><td>Connection die gerade benutzt werden = </td><td>" + broker.getUseCount()+"</td></tr>\n";
-  }
-  public void getSimpleInfo(Writer out,HashMap confs) throws IOException{
-    String key;
-    DbConnectionBroker broker = null;
-    out.write(getInstancesInfo());
-    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=(DbConnectionBroker) ((HashMap)confs.get(key)).get("Pool.broker");
-      if(broker!=null)  out.write(getBrokerInfo(broker));
-      else
-        out.write("<tr><td>Broker nicht initializiert</td><td></td></tr>\n");
-      out.write("</table>\n");
-    }
-  }
 }
 
index ec48710..6728e40 100755 (executable)
@@ -8,12 +8,10 @@ import  java.lang.*;
 import  java.io.*;
 import  java.util.*;
 import  freemarker.template.*;
-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.*;
 
 
@@ -30,7 +28,6 @@ import com.codestudio.util.*;
  */
 public class Database implements StorageObject {
 
-  protected DbConnectionBroker        myBroker;
   protected String                    theTable;
   protected String                    theCoreTable=null;
   protected String                    thePKeyName="id";
@@ -1036,71 +1033,22 @@ public class Database implements StorageObject {
     }
   }
 
-  /**
-   * Datenbankverbindung wird geschlossen
-   */
-  public void disconnectPool () throws StorageObjectException {
-    try {
-      myBroker.destroy(100);
-    } catch (SQLException sqe) {
-      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 getPooledCon2() throws StorageObjectException {
-    if (myBroker != null) {
-      Connection con = myBroker.getConnection();
-      if (con != null)
-        return  con;
-    }
-    throw  new StorageObjectException("No connection to database!");
-  }
-
-  /**
-   * Connection und StatementObjekt werden geschlossen und an den Connectionpool
-   * zurückgeben
-   * @param con Connection zur Datenbank
-   * @param stmt Statement-Objekt
-   */
-  public void freeConnection2 (Connection con, Statement stmt)
-    throws StorageObjectException {
-    try {
-      if (stmt != null)
-        stmt.close();
-    } catch (SQLException e1) {
-      theLog.printDebugInfo(e1.toString());
-      throw new StorageObjectException("DB, in freeConnection: "+e1.toString());
-    }
-    if (con != null)
-      myBroker.freeConnection(con);
-    else {
-      theLog.printDebugInfo("Con was null!");
-      throw new StorageObjectException("Con was null!");
-    }
-  }
-  
   public void freeConnection (Connection con, Statement stmt)
     throws StorageObjectException {
     SQLManager.getInstance().closeStatement(stmt);