1-n-content-media, tomcat-session-tracking without cookies, and more
[mir.git] / source / mircoders / entity / EntityContent.java
index e08494e..693afd8 100755 (executable)
@@ -61,10 +61,10 @@ public class EntityContent extends AbstractEntity implements Entity
                String value = (yesno) ? "1":"0";
                String sql = "update content set is_produced='" + value + "' where id='" + getId()+"'";
                try {
-                               con = theStorageObject.getPooledCon();
-                               /** @todo should be preparedStatement: faster!! */
-                               stmt = con.createStatement();
-                               theStorageObject.executeUpdate(stmt,sql);
+                       con = theStorageObject.getPooledCon();
+                       /** @todo should be preparedStatement: faster!! */
+                       stmt = con.createStatement();
+                       theStorageObject.executeUpdate(stmt,sql);
                } catch (StorageObjectException e) {
                        theLog.printDebugInfo(e.toString() + "\n -- set produced failed");
                } catch (SQLException e) {
@@ -96,15 +96,16 @@ public class EntityContent extends AbstractEntity implements Entity
        * dettach from media
        */
 
-       public void dettach()
+       public void dettach(String cid,String mid)
        {
-               String sql = "update content set to_media=null, is_produced='0' where id='" + getId()+"'";
-               try {
-                               theStorageObject.executeUpdate(sql);
-               } catch (StorageObjectException e) {
-                       theLog.printError(e.toString() + "dettach failed");
-               } catch (SQLException e) {
-                       theLog.printError(e.toString() + "dettach failed");
+               if (mid!=null){
+                       try{
+                               DatabaseContentToMedia.getInstance().delete(cid,mid);
+                       } catch (Exception e){
+                               theLog.printError("failed to get instance");
+                       }
+                       //set Content to unproduced
+                       setProduced(false);
                }
        }
 
@@ -115,17 +116,17 @@ public class EntityContent extends AbstractEntity implements Entity
        public void attach(String mid)
        {
                if (mid!=null) {
-                       String sql = "update content set to_media='" + mid + "', is_produced='0' where id='" + getId()+"'";
-                       try {
-                                       theStorageObject.executeUpdate(sql);
-                       } catch (StorageObjectException e) {
-                               theLog.printError(e.toString() + "attach failed");
-                       } catch (SQLException e) {
-                               theLog.printError(e.toString() + "attach failed");
+                       //write media-id mid and content-id in table content_x_media
+                       try{
+                               DatabaseContentToMedia.getInstance().addMedia(getId(),mid);
+                       } catch(StorageObjectException e){
+                               theLog.printError("attach: could not get the instance");
                        }
-               }
-               else
+                       //set Content to unproduced
+                       setProduced(false);
+               }       else {
                        theLog.printError("EntityContent: attach without mid");
+               }
        }
 
        /**