gains better error handling.
import java.lang.reflect.*;
import javax.servlet.*;
import javax.servlet.http.*;
+import javax.servlet.UnavailableException;
import java.sql.*;
import freemarker.template.*;
import mir.misc.*;
import mir.servlet.*;
+import mir.storage.StorageObjectException;
import mircoders.servlet.*;
import mircoders.module.*;
private static ModuleUsers usersModule=null;
private static ModuleMessage messageModule=null;
- private static boolean confed=false;
+ //private static boolean confed=false;
public HttpSession session;
-
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doPost(req,res);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
+ throws ServletException, IOException, UnavailableException {
long startTime = (new java.util.Date()).getTime();
Class theServletModule;
String http="";
// get the configration
- if (!confed){
- confed = getConfig(req);
+ if(getServletContext().getAttribute("mir.confed") == null) {
+ getConfig(req);
}
MirConfig.setServletName(getServletName());
public class OpenMir extends AbstractServlet {
- private static boolean confed=false;
+ //private static boolean confed=false;
private static String lang;
public HttpSession session;
long sessionConnectTime=0;
- if (!confed){
- confed = getConfig(req);
- }
+ // get the configration
+ if(getServletContext().getAttribute("mir.confed") == null) {
+ getConfig(req);
+ }
session = req.getSession();
if(session.getAttribute("Language")==null){
import java.util.*;
import java.lang.*;
import mir.storage.StorageObjectException;
+import mir.storage.DatabaseAdaptor;
import com.codestudio.util.*;
/**
public class MirConfig extends Configuration {
- private static HashMap configHash = new HashMap();
+ private static HashMap configHash = null;
private static HashMap brokerHash = new HashMap();
private static int instances=0;
* @param name, The name of the servlet (usually "Mir")
* @param confName, the name of the config file to load.
*/
- public static void initConfig(String home, String uri, String name, String confName) {
+ public static synchronized void initConfig(String home, String uri,
+ String name, String confName) {
initConfResource(confName);
-
+ configHash = new HashMap();
configHash.put("Home", home);
configHash.put("RootUri", uri);
(String)configHash.get(propName);
}
- public static void addBroker(String driver, String URL) throws StorageObjectException {
+ public static void initDbPool () throws StorageObjectException {
+ if (configHash == null) {
+ throw new StorageObjectException("MirConfig -- Trying initialize "+
+ "DB pool when system not yet "+
+ "configured");
+ }
+ String dbUser=getProp("Database.Username");
+ String dbPassword=getProp("Database.Password");
+ String dbHost=getProp("Database.Host");
+ String dbAdapName=getProp("Database.Adaptor");
+ DatabaseAdaptor adaptor;
+ try {
+ adaptor = (DatabaseAdaptor)Class.forName(dbAdapName).newInstance();
+ } catch (Exception e) {
+ throw new StorageObjectException("Could not load DB adapator: "+
+ e.toString());
+ }
+ String dbDriver=adaptor.getDriver();
+ String dbUrl=adaptor.getURL(dbUser,dbPassword, dbHost);
+ System.out.println("adding Broker with: " +dbDriver+":"+dbUrl );
+ addBroker( dbDriver, dbUrl);
+ }
+
+ public static void addBroker(String driver, String URL)
+ throws StorageObjectException {
+ if (configHash == null) {
+ throw new StorageObjectException("MirConfig -- Trying initialize "+
+ "DB pool when system not yet "+
+ "configured");
+ }
String username,passwd,min,max,log,reset,dbname,dblogfile;
if(!brokerHash.containsKey("Pool.broker")){
meta.setMaximumSize(Integer.parseInt(max));
meta.setMinimumSize(Integer.parseInt(min));
meta.setCacheEnabled(true);
- //meta.setDebugging(true);
+ meta.setCacheEnabled(true);
+ meta.setCacheSize(15);
+ meta.setDebugging(true);
meta.setLogFile(dblogfile+".pool");
JDBCPool pool = SQLManager.getInstance().createPool(meta);
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.servlet.UnavailableException;
import java.io.File;
import java.util.Locale;
import java.util.HashMap;
import mir.misc.StringUtil;
import mir.misc.MirConfig;
import mir.misc.Logfile;
+import mir.storage.StorageObjectException;
/**
* Title: Mir
/**
* the configration
*/
- protected boolean getConfig(HttpServletRequest req) {
+ protected boolean getConfig(HttpServletRequest req)
+ throws UnavailableException {
String RealPath = super.getServletContext().getRealPath("/");
String Uri = req.getRequestURI();
// init config
MirConfig.initConfig(RealPath, RootUri, Name, getInitParameter("Config"));
- theLog = Logfile.getInstance(this.getClass().getName());
+ theLog = Logfile.getInstance(MirConfig.getPropWithHome(Name+".Logfile"));
theLog.printInfo(Name + " started.");
theLog.printInfo("Path is: " + MirConfig.getProp("Home"));
theLog.printInfo("Root URI is: " + MirConfig.getProp("RootUri"));
theLog.printInfo("Lang is: " + MirConfig.getProp("StandardLanguage"));
+ try {
+ MirConfig.initDbPool();
+ } catch ( StorageObjectException e) {
+ throw new UnavailableException(
+ "Could not initialize database pool. -- "
+ + e.toString(), 0);
+ }
+ super.getServletContext().setAttribute("mir.confed", new Boolean(true));
return true;
}
protected String thePKeyName="id";
protected int thePKeyType;
protected boolean evaluatedMetaData=false;
- protected ArrayList metadataFields,metadataLabels,metadataNotNullFields;
+ protected ArrayList metadataFields,metadataLabels,
+ metadataNotNullFields;
protected int[] metadataTypes;
protected Class theEntityClass;
protected StorageObject myselfDatabase;
* @param String confFilename Dateiname der Konfigurationsdatei
*/
public Database() throws StorageObjectException {
- theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Database.Logfile"));
- String database_username=MirConfig.getProp("Database.Username");
- String database_password=MirConfig.getProp("Database.Password");
- String database_host=MirConfig.getProp("Database.Host");
+ theLog = Logfile.getInstance(MirConfig.getProp("Home")+
+ MirConfig.getProp("Database.Logfile"));
String theAdaptorName=MirConfig.getProp("Database.Adaptor");
+ defaultLimit = Integer.parseInt(MirConfig.getProp("Database.Limit"));
try {
theEntityClass = Class.forName("mir.entity.GenericEntity");
theAdaptor = (DatabaseAdaptor)Class.forName(theAdaptorName).newInstance();
- defaultLimit = Integer.parseInt(MirConfig.getProp("Database.Limit"));
+ } catch (Exception e){
+ theLog.printError("Error in Database() constructor with "+
+ theAdaptorName + " -- " +e.toString());
+ throw new StorageObjectException("Error in Database() constructor with "
+ +e.toString());
+ }
+ /*String database_username=MirConfig.getProp("Database.Username");
+ String database_password=MirConfig.getProp("Database.Password");
+ String database_host=MirConfig.getProp("Database.Host");
+ try {
database_driver=theAdaptor.getDriver();
- database_url=theAdaptor.getURL(database_username,database_password,database_host);
- theLog.printDebugInfo("adding Broker with: " +database_driver+":"+database_url );
+ 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();
- }
- catch (Exception e){
- theLog.printError("Bei Konstruktion von Database() with " + theAdaptorName + " -- " +e.toString());
- throw new StorageObjectException(e.toString());
- }
+ }*/
}
/**
/*
* Dient dazu vererbte Tabellen bei objectrelationalen DBMS
- * zu speichern, wenn die id einer Tabelle in der parenttabelle verwaltet wird.
+ * zu speichern, wenn die id einer Tabelle in der parenttabelle verwaltet
+ * wird.
* @return liefert theCoreTabel als String zurueck, wenn gesetzt, sonst
* the Table
*/
// execute sql
try {
con = getPooledCon();
+ } catch (Exception e) {
+ throw new StorageObjectException(e.toString());
+ }
+ try {
stmt = con.createStatement();
ResultSet rs = executeSql(stmt, sql.toString());
if (rs != null) {
rs.close();
}
} catch (Exception e) {
- theLog.printDebugInfo(e.toString());
- throw new StorageObjectException(e.toString());
+ theLog.printError("getPopupData: "+e.toString());
+ throw new StorageObjectException(e.toString());
} finally {
freeConnection(con, stmt);
}
public Connection getPooledCon() throws StorageObjectException {
- /*try{
+ /* @todo , doublecheck but I'm pretty sure that this is unnecessary. -mh
+ try{
Class.forName("com.codestudio.sql.PoolMan").newInstance();
} catch (Exception e){
throw new StorageObjectException("Could not find the PoolMan Driver"
try{
con = SQLManager.getInstance().requestConnection();
} catch(SQLException e){
- throw new StorageObjectException("No connection to the database");
+ theLog.printError("could not connect to the database "+e.toString());
+ System.err.println("could not connect to the database "+e.toString());
+ throw new StorageObjectException("Could not connect to the database"+
+ e.toString());
}
return con;
}