From d59d1103c4930049bd96a6d4fcc5cc4543bbc1d7 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 2 Feb 2002 10:33:02 +0000 Subject: [PATCH] more error handling. --- source/mir/entity/AbstractEntity.java | 12 +++++-- source/mir/media/MirMediaException.java | 25 ++++++++++++++ source/mir/storage/Database.java | 14 ++++++-- source/mircoders/entity/EntityContent.java | 17 +++++---- source/mircoders/entity/EntityImages.java | 8 ++--- source/mircoders/entity/EntityUploadedMedia.java | 10 ++++-- source/mircoders/producer/ProducerTopics.java | 1 + source/mircoders/servlet/ServletModuleContent.java | 3 +- source/mircoders/storage/DatabaseContent.java | 10 +++--- .../mircoders/storage/DatabaseContentToMedia.java | 40 ++++++++++++++++++---- .../mircoders/storage/DatabaseContentToTopics.java | 17 ++++++--- .../mircoders/storage/DatabaseUploadedMedia.java | 3 +- 12 files changed, 123 insertions(+), 37 deletions(-) create mode 100755 source/mir/media/MirMediaException.java diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java index 632fc396..dddb33fe 100755 --- a/source/mir/entity/AbstractEntity.java +++ b/source/mir/entity/AbstractEntity.java @@ -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 index 00000000..dfaf42a3 --- /dev/null +++ b/source/mir/media/MirMediaException.java @@ -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; + } +} + diff --git a/source/mir/storage/Database.java b/source/mir/storage/Database.java index 9fc15d02..aeb5cb6a 100755 --- a/source/mir/storage/Database.java +++ b/source/mir/storage/Database.java @@ -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); } } diff --git a/source/mircoders/entity/EntityContent.java b/source/mircoders/entity/EntityContent.java index 485f609d..14b89711 100755 --- a/source/mircoders/entity/EntityContent.java +++ b/source/mircoders/entity/EntityContent.java @@ -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); } diff --git a/source/mircoders/entity/EntityImages.java b/source/mircoders/entity/EntityImages.java index c9c1a319..577f3f17 100755 --- a/source/mircoders/entity/EntityImages.java +++ b/source/mircoders/entity/EntityImages.java @@ -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); } diff --git a/source/mircoders/entity/EntityUploadedMedia.java b/source/mircoders/entity/EntityUploadedMedia.java index 554795c4..95800ecd 100755 --- a/source/mircoders/entity/EntityUploadedMedia.java +++ b/source/mircoders/entity/EntityUploadedMedia.java @@ -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; } diff --git a/source/mircoders/producer/ProducerTopics.java b/source/mircoders/producer/ProducerTopics.java index 0c5aa379..2e9fa00c 100755 --- a/source/mircoders/producer/ProducerTopics.java +++ b/source/mircoders/producer/ProducerTopics.java @@ -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()); } } diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index eef12afa..a438ad8a 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -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); } diff --git a/source/mircoders/storage/DatabaseContent.java b/source/mircoders/storage/DatabaseContent.java index 5a76432c..2c750d09 100755 --- a/source/mircoders/storage/DatabaseContent.java +++ b/source/mircoders/storage/DatabaseContent.java @@ -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; } diff --git a/source/mircoders/storage/DatabaseContentToMedia.java b/source/mircoders/storage/DatabaseContentToMedia.java index 1cf37083..5bfe5af0 100755 --- a/source/mircoders/storage/DatabaseContentToMedia.java +++ b/source/mircoders/storage/DatabaseContentToMedia.java @@ -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; diff --git a/source/mircoders/storage/DatabaseContentToTopics.java b/source/mircoders/storage/DatabaseContentToTopics.java index 944eff4e..c9bb9ead 100755 --- a/source/mircoders/storage/DatabaseContentToTopics.java +++ b/source/mircoders/storage/DatabaseContentToTopics.java @@ -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; } diff --git a/source/mircoders/storage/DatabaseUploadedMedia.java b/source/mircoders/storage/DatabaseUploadedMedia.java index 15ce4e60..428edc44 100755 --- a/source/mircoders/storage/DatabaseUploadedMedia.java +++ b/source/mircoders/storage/DatabaseUploadedMedia.java @@ -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; } -- 2.11.0