bugfixes mainly...
[mir.git] / source / mircoders / storage / DatabaseMedia.java
index fe63a14..fa09f08 100755 (executable)
@@ -20,8 +20,13 @@ import mir.misc.*;
 public class DatabaseMedia extends Database implements StorageObject{
 
   private static DatabaseMedia instance;
+  private static EntityRelation         relationMediaType;
 
-  public static DatabaseMedia getInstance() throws StorageObjectException {
+  // the following *has* to be sychronized cause this static method
+  // could get preemted and we could end up with 2 instances of DatabaseFoo..
+  // see the "Singletons with needles and thread" article at JavaWorld -mh
+  public synchronized static DatabaseMedia getInstance() 
+    throws StorageObjectException {
     if (instance == null) {
       instance = new DatabaseMedia();
       instance.myselfDatabase = instance;
@@ -32,9 +37,11 @@ public class DatabaseMedia extends Database implements StorageObject{
   private DatabaseMedia() throws StorageObjectException
   {
     super();
-    this.cache = new HashMap();
+    //this.cache = new DatabaseCache(100);
     this.hasTimestamp = false;
-    this.theTable="media*";
+    this.theTable="media";
+    relationMediaType = new EntityRelation("to_media_type", "id", 
+                        DatabaseMediaType.getInstance(), EntityRelation.TO_ONE);
     try {
       this.theEntityClass = Class.forName("mircoders.entity.EntityMedia");
     }
@@ -43,5 +50,23 @@ public class DatabaseMedia extends Database implements StorageObject{
     }
   }
 
+  // methods
+
+
+  /**
+   * returns the comments that belong to the article (via entityrelation)
+   * where db-flag is_published is true
+   */
+  public Entity getMediaType(Entity ent) throws StorageObjectException {
+    Entity type=null;
+    try {
+      type = relationMediaType.getOne(ent);
+    }
+    catch (StorageObjectException e) {
+      theLog.printError("DatabaseMedia :: failed to get media_type");
+      throw new StorageObjectException("DatabaseMedia :"+e.toString());
+    }
+    return type;
+  }
 
 }