*** empty log message ***
[mir.git] / source / mircoders / storage / DatabaseContentToMedia.java
index 3a1fb52..c2d2ac1 100755 (executable)
@@ -39,12 +39,13 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
     this.hasTimestamp = false;
     this.theTable="content_x_media";
   }
-  
+
   /**
    * 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,16 +57,18 @@ 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;
   }
-  
+
   /**
    * 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
@@ -96,16 +101,19 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
       String subselect = "id in (select media_id from " + theTable + " where content_id=" + id+")";
 
       try {
-        returnList = DatabaseUploadedMedia.getInstance().selectByWhereClause(subselect,-1);
+        returnList = DatabaseMedia.getInstance().selectByWhereClause(subselect,"id");
       } catch (Exception e) {
+        e.printStackTrace();
         theLog.printDebugInfo("-- get uploadedMedia failed " + e.toString());
+        throw new StorageObjectException("-- get uploadedMedia failed " + e.toString());
       }
     }
     return returnList;
   }
 
 
-  public void setMedia(String contentId, String[] mediaId) {
+  public void setMedia(String contentId, String[] mediaId)
+    throws StorageObjectException {
     if (contentId == null){
       return;
     }
@@ -114,7 +122,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{
     }
     //first delete all row with content_id=contentId
     String sql = "delete from "+ theTable +" where content_id=" + contentId;
-  
+
     Connection con=null;Statement stmt=null;
     try {
       con = getPooledCon();
@@ -123,10 +131,11 @@ 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);
     }
-  
+
     //now insert
     //first delete all row with content_id=contentId
     for (int i=0;i<mediaId.length;i++) {
@@ -139,20 +148,22 @@ 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);
       }
     }
   }
 
-  public void addMedia(String contentId, String mediaId) {
+  public void addMedia(String contentId, String mediaId)
+    throws StorageObjectException {
     if (contentId == null && mediaId == null) {
       return;
     }
-    
+
     Connection con=null;Statement stmt=null;
     //now insert
-    
+
     String sql = "insert into "+ theTable +" (content_id,media_id) values ("
           + contentId + "," + mediaId + ")";
     try {
@@ -162,12 +173,15 @@ 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);
     }
   }
-  
-  public void setMedia(String contentId, String mediaId) {
+
+  public void setMedia(String contentId, String mediaId)
+    throws StorageObjectException {
     if (contentId == null && mediaId == null) {
       return;
     }
@@ -182,6 +196,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);
     }
@@ -198,12 +214,15 @@ 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);
     }
   }
 
-  public void deleteByContentId(String contentId) {
+  public void deleteByContentId(String contentId)
+    throws StorageObjectException {
     if (contentId == null) {
       //theLog.printDebugInfo("-- delete topics failed -- no content id");
       return;
@@ -218,13 +237,16 @@ 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);
     }
   }
 
-  public void deleteByMediaId(String mediaId) {
+  public void deleteByMediaId(String mediaId)
+    throws StorageObjectException {
     if (mediaId == null) {
       //theLog.printDebugInfo("-- delete topics failed -- no topic id");
       return;
@@ -241,12 +263,15 @@ 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);
     }
   }
-  
-  public void delete(String contentId, String mediaId) {
+
+  public void delete(String contentId, String mediaId)
+    throws StorageObjectException {
     if (mediaId == null || contentId==null) {
       theLog.printDebugInfo("-- delete media failed -- missing parameter");
       return;
@@ -263,13 +288,16 @@ 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);
     }
   }
 
 
-  public EntityList getContent(EntityMedia media) {
+  public EntityList getContent(EntityMedia media)
+    throws StorageObjectException {
     EntityList returnList=null;
     if (media != null) {
       String id = media.getId();
@@ -295,19 +323,24 @@ 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;
   }
-  
+
 /**
  * Returns a EntityList with all content-objects having a relation to a media
  */
-  
-public EntityList getContent() {
+
+public EntityList getContent()
+    throws StorageObjectException {
     EntityList returnList=null;
-    
+
     String select = "select distinct content_id from " + theTable;
     // execute select statement
     Connection con=null;Statement stmt=null;
@@ -329,7 +362,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;