From f19da8774573d9ee8228407a3abb3330311bc504 Mon Sep 17 00:00:00 2001 From: idfx Date: Thu, 7 Feb 2002 14:17:11 +0000 Subject: [PATCH] poolman instead of connectionbroker --- source/config.properties-dist | 1 + source/mir/misc/MirConfig.java | 40 +++------------------ source/mir/servlet/ServletModuleMonitor.java | 30 +--------------- source/mir/storage/Database.java | 54 +--------------------------- 4 files changed, 8 insertions(+), 117 deletions(-) diff --git a/source/config.properties-dist b/source/config.properties-dist index 3684fa03..3c678530 100755 --- a/source/config.properties-dist +++ b/source/config.properties-dist @@ -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 diff --git a/source/mir/misc/MirConfig.java b/source/mir/misc/MirConfig.java index 9910b55f..f8bd0268 100755 --- a/source/mir/misc/MirConfig.java +++ b/source/mir/misc/MirConfig.java @@ -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 */ diff --git a/source/mir/servlet/ServletModuleMonitor.java b/source/mir/servlet/ServletModuleMonitor.java index ee8f5416..2356975e 100755 --- a/source/mir/servlet/ServletModuleMonitor.java +++ b/source/mir/servlet/ServletModuleMonitor.java @@ -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 "Connections im pool = "+ broker.getSize() + "\n"+ - "Connection die gerade benutzt werden = " + broker.getUseCount()+"\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;iKonfiguration : " + confs.get(key)+ "\n" ); - //broker=(DbConnectionBroker) ((HashMap)confs.get(key)).get("Pool.broker"); - if(broker!=null) out.write(getBrokerInfo(broker)); - else - out.write("Broker nicht initializiert\n"); - out.write("\n"); - } - } } diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index ec48710e..6728e404 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -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); -- 2.11.0