Took the ChangeTracker reporting out of GeneratingProducerNode and put it into the...
[mir.git] / source / mircoders / entity / EntityContent.java
index 59ed478..96ab2dc 100755 (executable)
@@ -35,68 +35,46 @@ import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Map;
 
-import mir.entity.Entity;
+import mir.entity.AbstractEntity;
 import mir.log.LoggerWrapper;
-import mir.storage.StorageObject;
-import mir.storage.StorageObjectFailure;
-import mir.util.StringRoutines;
+import mir.storage.DatabaseFailure;
 import mircoders.storage.DatabaseContentToMedia;
 
 /**
  * this class implements mapping of one line of the database table content
  * to a java object
  *
- * @version $Id: EntityContent.java,v 1.19.2.4 2003/12/21 13:32:04 zapata Exp $
+ * @version $Id: EntityContent.java,v 1.19.2.12 2005/10/30 00:46:58 zapata Exp $
  * @author mir-coders group
  *
  */
 
 
-public class EntityContent extends Entity
-{
-  // constructors
-
-  public EntityContent()
-  {
-    super();
-
-    logger = new LoggerWrapper("Entity.Content");
-  }
-
-  public EntityContent(StorageObject theStorage) {
-    this();
-
-    setStorage(theStorage);
-  }
-
-  //
-  // methods
-
+public class EntityContent extends AbstractEntity {
   /**
    * set is_produced flag for the article
    */
-
-  public void setProduced(boolean yesno) throws StorageObjectFailure
+  public void setProduced(boolean yesno) throws DatabaseFailure
   {
     String value = (yesno) ? "1":"0";
-    if (value.equals( getValue("is_produced") )) return;
+    if (value.equals( getFieldValue("is_produced") )) return;
 
     Connection con=null;Statement stmt=null;
     String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
     try {
-      con = theStorageObject.getPooledCon();
-      /** @todo should be preparedStatement: faster!! */
+      con = database.obtainConnection();
+      /** todo should be preparedStatement: faster!! */
       stmt = con.createStatement();
-      theStorageObject.executeUpdate(stmt,sql);
+      database.executeUpdate(stmt,sql);
     }
-    catch (StorageObjectFailure e) {
-      throwStorageObjectFailure(e, "\n -- set produced failed");
+    catch (DatabaseFailure e) {
+      throw e;
     }
     catch (SQLException e) {
-      throwStorageObjectFailure(e, "\n -- set produced failed");
+      throw new DatabaseFailure(e);
     }
     finally {
-      theStorageObject.freeConnection(con,stmt);
+      database.freeConnection(con,stmt);
     }
   }
 
@@ -105,49 +83,36 @@ public class EntityContent extends Entity
    *
    * @param anArticleId
    * @param aMediaId
-   * @throws StorageObjectFailure
+   * @throws DatabaseFailure
    */
-  public void dettach(String anArticleId, String aMediaId) throws StorageObjectFailure
+  public void dettach(String anArticleId, String aMediaId) throws DatabaseFailure
   {
     if (aMediaId!=null){
-      try{
-        DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);
-      }
-      catch (Exception e){
-        throwStorageObjectFailure(e, "\n -- failed to get instance");
-      }
+      DatabaseContentToMedia.getInstance().delete(anArticleId, aMediaId);
 
       setProduced(false);
     }
   }
 
   /**
-   * Attaches media to an article
-   *
-   * @param mid
-   * @throws StorageObjectFailure
+   * Attaches media to the article
    */
 
-  public void attach(String aMediaId) throws StorageObjectFailure
+  public void attach(String aMediaId) throws DatabaseFailure
   {
     if (aMediaId!=null) {
-      try{
-        DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);
-      }
-      catch(StorageObjectFailure e){
-        throwStorageObjectFailure(e, "attach: could not get the instance");
-      }
+      DatabaseContentToMedia.getInstance().addMedia(getId(),aMediaId);
       setProduced(false);
     }
     else {
-      logger.error("EntityContent: attach without mid");
+      getLogger().error("EntityContent: attach without mid");
     }
   }
 
   /**
-   * overridden method setValues to patch creator_main_url
+   * overridden method setFieldValues to patch creator_main_url
    */
-  public void setValues(Map theStringValues) {
+  public void setFieldValues(Map theStringValues) {
     if (theStringValues != null) {
       if (theStringValues.containsKey("creator_main_url")){
         if (((String)theStringValues.get("creator_main_url")).equalsIgnoreCase("http://")){
@@ -158,6 +123,6 @@ public class EntityContent extends Entity
         }
       }
     }
-    super.setValues(theStringValues);
+    super.setFieldValues(theStringValues);
   }
 }