more error handling.
authormh <mh>
Sat, 2 Feb 2002 10:33:02 +0000 (10:33 +0000)
committermh <mh>
Sat, 2 Feb 2002 10:33:02 +0000 (10:33 +0000)
12 files changed:
source/mir/entity/AbstractEntity.java
source/mir/media/MirMediaException.java [new file with mode: 0755]
source/mir/storage/Database.java
source/mircoders/entity/EntityContent.java
source/mircoders/entity/EntityImages.java
source/mircoders/entity/EntityUploadedMedia.java
source/mircoders/producer/ProducerTopics.java
source/mircoders/servlet/ServletModuleContent.java
source/mircoders/storage/DatabaseContent.java
source/mircoders/storage/DatabaseContentToMedia.java
source/mircoders/storage/DatabaseContentToTopics.java
source/mircoders/storage/DatabaseUploadedMedia.java

index 632fc39..dddb33f 100755 (executable)
@@ -29,13 +29,13 @@ public class AbstractEntity implements Entity
   protected static Logfile    theLog;
   protected ArrayList         streamedInput=null;
   private static int instances = 0;
+    static {
+      theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
+    }
 
     public AbstractEntity() {
-      theLog = Logfile.getInstance(this.getClass().getName());
       this.changed = false;
       instances++;
-      Integer i = new Integer(instances);
-      System.err.println("New abstract entity instance: "+i.toString());
     }
 
   /**
@@ -204,6 +204,12 @@ public class AbstractEntity implements Entity
   public int getInstances() {
      return instances;
   }
+
+  protected void throwStorageObjectException (Exception e, String wo) throws StorageObjectException {
+    theLog.printError( e.toString() + " Funktion: "+ wo);
+    throw  new StorageObjectException("Storage Object Exception in entity" +e.toString());
+  }
+
   /**
    * Gibt eine Instanz frei
    */
diff --git a/source/mir/media/MirMediaException.java b/source/mir/media/MirMediaException.java
new file mode 100755 (executable)
index 0000000..dfaf42a
--- /dev/null
@@ -0,0 +1,25 @@
+package mir.media;
+
+import java.lang.*;
+
+/*
+ *  MirMediaException -
+ * 
+ * @version 29.1.2002
+ * @author mh
+ */
+
+public final class MirMediaException extends Exception
+{
+    String msg;
+
+       public MirMediaException(String msg) {
+               super(msg);
+        this.msg = msg;
+       }
+
+    public String getMsg() {
+        return msg;
+    }
+}
+
index 9fc15d0..aeb5cb6 100755 (executable)
@@ -1103,14 +1103,24 @@ public class Database implements StorageObject {
         sqe.toString());
   }
 
+  protected void _throwStorageObjectException (Exception e, String wo) throws StorageObjectException {
+    if (e != null) {
+        theLog.printError(e.toString()+ wo);
+        throw  new StorageObjectException(wo + e.toString());
+    } else {
+        theLog.printError(wo);
+        throw  new StorageObjectException(wo);
+    }
+        
+  }
+
   /**
    * Loggt Fehlermeldung mit dem Parameter Message und wirft dannach eine StorageObjectException
    * @param message Nachricht mit dem Fehler
    * @exception StorageObjectException
    */
   void throwStorageObjectException (String message) throws StorageObjectException {
-    theLog.printError(message);
-    throw  new StorageObjectException(message);
+    _throwStorageObjectException(null, message);
   }
 }
 
index 485f609..14b8971 100755 (executable)
@@ -66,9 +66,9 @@ public class EntityContent extends AbstractEntity implements Entity
                        stmt = con.createStatement();
                        theStorageObject.executeUpdate(stmt,sql);
                } catch (StorageObjectException e) {
-                       theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+            throwStorageObjectException(e, "\n -- set produced failed");
                } catch (SQLException e) {
-                       theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
+            throwStorageObjectException(e, "\n -- set produced failed");
                } finally {
                        theStorageObject.freeConnection(con,stmt);
                }
@@ -79,15 +79,15 @@ public class EntityContent extends AbstractEntity implements Entity
        * make openposting to newswire
        */
 
-       public void newswire()
+       public void newswire() throws StorageObjectException
        {
                String sql = "update content set to_article_type='1', is_produced='0' where id='" + getId()+"'";
                try {
                                theStorageObject.executeUpdate(sql);
                } catch (StorageObjectException e) {
-                       theLog.printError(e.toString() + "newswire failed");
+            throwStorageObjectException(e, "\n -- newswire failed");
                } catch (SQLException e) {
-                       theLog.printError(e.toString() + "newswire failed");
+            throwStorageObjectException(e, "\n -- newswire failed");
                }
        }
 
@@ -95,14 +95,13 @@ public class EntityContent extends AbstractEntity implements Entity
  /**
        * dettach from media
        */
-
        public void dettach(String cid,String mid) throws StorageObjectException
        {
                if (mid!=null){
                        try{
                                DatabaseContentToMedia.getInstance().delete(cid,mid);
                        } catch (Exception e){
-                               theLog.printError("failed to get instance");
+                throwStorageObjectException(e, "\n -- failed to get instance");
                        }
                        //set Content to unproduced
                        setProduced(false);
@@ -120,7 +119,7 @@ public class EntityContent extends AbstractEntity implements Entity
                        try{
                                DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
                        } catch(StorageObjectException e){
-                               theLog.printError("attach: could not get the instance");
+                               throwStorageObjectException(e, "attach: could not get the instance");
                        }
                        //set Content to unproduced
                        setProduced(false);
@@ -198,7 +197,7 @@ public class EntityContent extends AbstractEntity implements Entity
         *
         * @return freemarker.template.SimpleList
         */
-       public SimpleList getComments() {
+       public SimpleList getComments() throws StorageObjectException {
                return ((DatabaseContent)theStorageObject).getComments(this);
        }
 
index c9c1a31..577f3f1 100755 (executable)
@@ -55,7 +55,7 @@ public class EntityImages extends AbstractEntity implements Entity
                                rs.close();
                        }
                }
-               catch (Exception e) {theLog.printDebugInfo("-- getImage gescheitert: "+e.toString());}
+               catch (Exception e) {throwStorageObjectException(e, "-- getImage gescheitert: ");}
                finally {
                        try {con.setAutoCommit(true); } catch (Exception e) {;}
                        theStorageObject.freeConnection(con,stmt); }
@@ -104,7 +104,7 @@ public class EntityImages extends AbstractEntity implements Entity
                                        pstmt.executeUpdate();
                                }
                        }
-                       catch (Exception e) {theLog.printDebugInfo("settimage :: setImage gescheitert: "+e.toString());}
+                       catch (Exception e) {throwStorageObjectException(e, "settimage :: setImage gescheitert: ");}
                        finally {
                                try {con.setAutoCommit(true); } catch (Exception e) {;}
                                theStorageObject.freeConnection(con,pstmt); }
@@ -116,7 +116,7 @@ public class EntityImages extends AbstractEntity implements Entity
                try {
                        theStorageObject.executeUpdate("update content set is_produced='0' where to_media="+getId());
                } catch (SQLException e) {
-                       theLog.printError("EntityImages :: update :: failed!! "+ e.toString());
+                       throwStorageObjectException(e, "EntityImages :: update :: failed!! ");
                }
        }
 
@@ -146,7 +146,7 @@ public class EntityImages extends AbstractEntity implements Entity
                                rs.close();
                        }
                }
-               catch (Exception e) {theLog.printDebugInfo("-- getIcon gescheitert: "+e.toString());}
+               catch (Exception e) {throwStorageObjectException(e, "-- getIcon gescheitert: ");}
                finally {
                        try {con.setAutoCommit(true); } catch (Exception e) {;}
                        theStorageObject.freeConnection(con,stmt); }
index 554795c..95800ec 100755 (executable)
@@ -47,8 +47,14 @@ public class EntityUploadedMedia extends AbstractEntity implements Entity
         *
         * @return mir.entity.Entity
         */
-       public Entity getMediaType() {
-               return ((DatabaseUploadedMedia)theStorageObject).getMediaType(this);
+       public Entity getMediaType() throws StorageObjectException {
+        Entity ent = null;
+        try {
+                   ent = ((DatabaseUploadedMedia)theStorageObject).getMediaType(this);
+        } catch (StorageObjectException e) {
+            throwStorageObjectException(e, "get MediaType failed -- ");
+        }
+        return ent;
        }
 
 
index 0c5aa37..2e9fa00 100755 (executable)
@@ -147,6 +147,7 @@ public class ProducerTopics extends ProducerList {
               setAdditional("special",specialHash);
           } catch (Exception e) {
             theLog.printError("ProducerTopics: problem with start special: "+currentContent.getId()+" "+e.toString());
+            logHTML(htmlout,"ProducerTopics: problem with start special: "+currentContent.getId()+" "+e.toString());
           }
         }
         
index eef12af..a438ad8 100755 (executable)
@@ -296,8 +296,9 @@ public class ServletModuleContent extends ServletModule
       EntityContent entContent = (EntityContent)mainModule.getById(idParam);
       entContent.newswire();
     }
-    catch(ModuleException e) {
+    catch(Exception e) {
       theLog.printError("smod content :: newswire :: could not get entityContent");
+      throw new ServletModuleException("smod content :: newswire :: could not get entityContent"+e.toString());
     }
     list(req, res);
   }
index 5a76432..2c750d0 100755 (executable)
@@ -65,7 +65,7 @@ public class DatabaseContent extends Database implements StorageObject {
       stmt = con.createStatement();
       executeUpdate(stmt,sql);
     }
-    catch (Exception e) {theLog.printDebugInfo("-- set unproduced failed");}
+    catch (Exception e) {_throwStorageObjectException(e, "-- set unproduced failed");}
     finally { freeConnection(con,stmt);}
   }
 
@@ -73,13 +73,13 @@ public class DatabaseContent extends Database implements StorageObject {
    * returns the comments that belong to the article (via entityrelation)
    * where db-flag is_published is true
    */
-  public SimpleList getComments(EntityContent entC) {
+  public SimpleList getComments(EntityContent entC) throws StorageObjectException {
     SimpleList comments=null;
     try {
       comments = relationComments.getManyAsSimpleList(entC,"webdb_create","is_published='1'");
     }
     catch (StorageObjectException e) {
-      theLog.printError("DatabaseComments :: failed to get comments");
+      _throwStorageObjectException(e, "DatabaseComments :: failed to get comments");
     }
     return comments;
   }
@@ -87,13 +87,13 @@ public class DatabaseContent extends Database implements StorageObject {
   /**
    * returns the features that belong to the article (via entityrelation)
    */
-  public SimpleList getFeature(EntityContent entC) {
+  public SimpleList getFeature(EntityContent entC) throws StorageObjectException {
     SimpleList feature=null;
     try {
       feature = relationFeature.getManyAsSimpleList(entC);
     }
     catch (StorageObjectException e) {
-      theLog.printError("DatabaseComments :: failed to get features");
+      _throwStorageObjectException(e, "DatabaseComments :: failed to get features");
     }
     return feature;
   }
index 1cf3708..5bfe5af 100755 (executable)
@@ -44,7 +44,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
    * get all the media-files belonging to a content entity
    *
    */
-  public EntityList getMedia(EntityContent content) {
+  public EntityList getMedia(EntityContent content)
+    throws StorageObjectException {
     EntityList returnList=null;
     if (content != null) {
       // get all to_topic from media_x_topic
@@ -56,6 +57,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
         returnList = DatabaseMedia.getInstance().selectByWhereClause(subselect,-1);
       } catch (Exception e) {
         theLog.printDebugInfo("-- get media failed " + e.toString());
+        throw new StorageObjectException("-- get media failed " + e.toString());
       }
     }
     return returnList;
@@ -65,7 +67,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
    * get all the images belonging to a content entity
    *
    */
-  public EntityList getImages(EntityContent content) {
+  public EntityList getImages(EntityContent content)
+    throws StorageObjectException {
     EntityList returnList=null;
     if (content != null) {
       // get all to_topic from media_x_topic
@@ -77,6 +80,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
         returnList = DatabaseImages.getInstance().selectByWhereClause(subselect,-1);
       } catch (Exception e) {
         theLog.printDebugInfo("-- get images failed " + e.toString());
+        throw new StorageObjectException("-- get images failed " + e.toString());
       }
     }
     return returnList;
@@ -87,7 +91,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
    * get all the uploaded Media belonging to a content entity
    *
    */
-  public EntityList getUploadedMedia(EntityContent content) {
+  public EntityList getUploadedMedia(EntityContent content)
+    throws StorageObjectException {
     EntityList returnList=null;
     if (content != null) {
       // get all to_topic from media_x_topic
@@ -99,6 +104,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
         returnList = DatabaseMedia.getInstance().selectByWhereClause(subselect,-1);
       } catch (Exception e) {
         theLog.printDebugInfo("-- get uploadedMedia failed " + e.toString());
+        throw new StorageObjectException("-- get uploadedMedia failed " + e.toString());
       }
     }
     return returnList;
@@ -124,6 +130,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       ResultSet rs = executeSql(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- set media failed -- delete");
+      throw new StorageObjectException("-- set media failed -- delete"+e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -140,6 +147,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
         int rs = executeUpdate(stmt,sql);
       } catch (Exception e) {
         theLog.printDebugInfo("-- set topics failed -- insert");
+        throw new StorageObjectException("-- set topics failed -- insert "+e.toString());
       } finally {
         freeConnection(con,stmt);
       }
@@ -164,6 +172,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       int rs = executeUpdate(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- add media failed -- insert");
+      throw new StorageObjectException("-- add media failed -- insert "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -185,6 +195,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       int rs = executeUpdate(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- set media failed -- delete");
+      throw new StorageObjectException("-- set media failed -- delete "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -201,6 +213,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       int rs = executeUpdate(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- set media failed -- insert");
+      throw new StorageObjectException("-- set media failed -- insert "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -222,7 +236,9 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       stmt = con.createStatement();
       int rs = executeUpdate(stmt,sql);
     } catch (Exception e) {
-      //theLog.printDebugInfo("-- delete topics failed  ");
+      theLog.printDebugInfo("-- delete by contentId failed  ");
+      throw new StorageObjectException("-- delete by content id failed -- delete "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -246,6 +262,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       theLog.printDebugInfo("-- delete media success ");
     } catch (Exception e) {
       theLog.printDebugInfo("-- delete media failed ");
+      throw new StorageObjectException("-- delete by media id failed -- "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -269,6 +287,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       theLog.printDebugInfo("-- delete content_x_media success ");
     } catch (Exception e) {
       theLog.printDebugInfo("-- delete content_x_media failed ");
+      throw new StorageObjectException("-- delete content_x_media failed -- "
+        +e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -302,7 +322,11 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
             returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,-1);
         }
       }
-      catch (Exception e) {theLog.printDebugInfo("-- get content failed");}
+      catch (Exception e) {
+        theLog.printDebugInfo("-- get content failed");
+        throw new StorageObjectException("-- get content failed -- "
+        +e.toString());
+      }
       finally { freeConnection(con,stmt);}
     }
     return returnList;
@@ -337,7 +361,11 @@ public EntityList getContent()
           returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,"webdb_lastchange desc");
       }
     }
-    catch (Exception e) {theLog.printDebugInfo("-- get content failed");}
+    catch (Exception e) {
+        theLog.printDebugInfo("-- get content failed");
+        throw new StorageObjectException("-- get content failed -- "
+        +e.toString());
+    }
     finally { freeConnection(con,stmt);}
 
     return returnList;
index 944eff4..c9bb9ea 100755 (executable)
@@ -45,7 +45,8 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
    * @param EntityContent content
    * @returns EntityList
    */
-  public EntityList getTopics(EntityContent content) {
+  public EntityList getTopics(EntityContent content)
+    throws StorageObjectException {
     EntityList returnList=null;
     if (content != null) {
       // get all to_topic from content_x_topic
@@ -56,6 +57,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
         returnList = DatabaseTopics.getInstance().selectByWhereClause(subselect,-1);
       } catch (Exception e) {
         theLog.printDebugInfo("-- get topics failed " + e.toString());
+        throw new StorageObjectException("-- get topics failed " + e.toString());
       }
     }
     return returnList;
@@ -84,6 +86,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       } catch (Exception e) {
         theLog.printError(e.toString());
         theLog.printError("-- get topicsofcontent failed");
+        throw new StorageObjectException("-- get topicsofcontent failed" + e.toString());
       } finally {
         freeConnection(con,stmt);
       }
@@ -168,6 +171,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       int rs = executeUpdate(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- deleting topics failed");
+      throw new StorageObjectException("-- deleting topics failed" + e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -184,6 +188,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
         int rs = executeUpdate(stmt,sql);
       } catch (Exception e) {
         theLog.printDebugInfo("-- set topics failed -- insert laenge topicId" + topicId.length);
+        throw new StorageObjectException("-- set topics failed" + e.toString());
       } finally {
         freeConnection(con,stmt);
       }
@@ -206,7 +211,8 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       stmt = con.createStatement();
       ResultSet rs = executeSql(stmt,sql);
     } catch (Exception e) {
-      //theLog.printDebugInfo("-- delete topics failed  ");
+      theLog.printDebugInfo("-- delete topics by contentId failed  ");
+      throw new StorageObjectException("-- delete topics by contentId failed" + e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -229,6 +235,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       ResultSet rs = executeSql(stmt,sql);
     } catch (Exception e) {
       theLog.printDebugInfo("-- delete topics failed ");
+      throw new StorageObjectException("-- delete topics by topicId failed" + e.toString());
     } finally {
       freeConnection(con,stmt);
     }
@@ -262,8 +269,10 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
             returnList = DatabaseContent.getInstance().selectByWhereClause(topicSelect,-1);
         }
       }
-      catch (Exception e) {theLog.printDebugInfo("-- get contetn failed");}
-      finally { freeConnection(con,stmt);}
+      catch (Exception e) {
+        theLog.printDebugInfo("-- get content failed");
+        throw new StorageObjectException("-- get content failed" + e.toString());
+      } finally { freeConnection(con,stmt);}
     }
     return returnList;
   }
index 15ce4e6..428edc4 100755 (executable)
@@ -54,13 +54,14 @@ public class DatabaseUploadedMedia extends Database implements StorageObject {
    * returns the comments that belong to the article (via entityrelation)
    * where db-flag is_published is true
    */
-  public Entity getMediaType(Entity ent) {
+  public Entity getMediaType(Entity ent) throws StorageObjectException {
     Entity type=null;
     try {
       type = relationMediaType.getOne(ent);
     }
     catch (StorageObjectException e) {
       theLog.printError("DatabaseUploadedMedia :: failed to get media_type");
+      throw new StorageObjectException("DatabaseUploadedMedia :: failed to get media_type"+ e.toString());
     }
     return type;
   }