Database.Username=postgres
Database.Password=
Database.Host=localhost
+Database..Name=Mir
#
# this sets the adaptor to be used
import java.io.*;
import java.util.*;
import java.lang.*;
-import com.javaexchange.dbConnectionBroker.*;
import mir.storage.StorageObjectException;
import com.codestudio.util.*;
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");
+ username + " pass: " + passwd);
JDBCPoolMetaData meta = new JDBCPoolMetaData();
- meta.setDbname("mir");
+ meta.setDbname(dbname);
meta.setDriver(driver);
meta.setURL(URL);
meta.setUserName(username);
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++;
} // 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
*/
import mir.storage.*;
import mir.entity.*;
-import com.javaexchange.dbConnectionBroker.*;
/*
* ServletModuleShow -
* liefert HTML fuer Show
// instances in AbstractEntity
// eingelesene confs
// datenbankverbindungen fuer brokers
- getSimpleInfo(res.getWriter(),getConfs());
+ //getSimpleInfo(res.getWriter(),getConfs());
PrintWriter out = res.getWriter();
out.println(getInstancesInfo());
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");
- }
- }
}
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.*;
*/
public class Database implements StorageObject {
- protected DbConnectionBroker myBroker;
protected String theTable;
protected String theCoreTable=null;
protected String thePKeyName="id";
}
}
- /**
- * 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);