bugfixes mainly...
[mir.git] / source / mircoders / storage / DatabaseContentToTopics.java
index 1eb4137..dc76e9d 100755 (executable)
@@ -23,7 +23,10 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
 
   private static DatabaseContentToTopics instance;
 
-  public static DatabaseContentToTopics getInstance()
+  // 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 DatabaseContentToTopics getInstance()
     throws StorageObjectException {
     if (instance == null) {
       instance = new DatabaseContentToTopics();
@@ -38,6 +41,9 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     super();
     this.hasTimestamp = false;
     this.theTable="content_x_topic";
+    try { this.theEntityClass = Class.forName("mir.entity.GenericEntity"); }
+    catch (Exception e) { throw new StorageObjectException(e.toString()); }
+
   }
 
   /**
@@ -60,7 +66,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     }
     return returnList;
   }
-  
+
   /**
    * Returns a ArrayList of Integer-Objects from a content-id.
    * @returns ArrayList
@@ -106,7 +112,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     Collection hasTopics = getTopicsOfContent(contentId);
     Collection toSet = new ArrayList();
     Collection toDelete = new ArrayList();
-    
+
     if(hasTopics!=null && hasTopics.size()>0){
       //now we check if there are new topics and copy them to an array.
       for(int i = 0; i< topicId.length;i++){
@@ -148,7 +154,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
                                toSet.add(topicId[i]);
                        }
     }
-    
+
     //first delete all row with content_id=contentId
     String sql = "delete from "+ theTable +" where content_id=" + contentId
                 + " and topic_id in (";