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();
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()); }
+
}
/**
}
return returnList;
}
-
+
/**
* Returns a ArrayList of Integer-Objects from a content-id.
* @returns ArrayList
*/
- public ArrayList getTopicsOfContent(String contentId) {
+ public ArrayList getTopicsOfContent(String contentId)
+ throws StorageObjectException {
ArrayList returnList = new ArrayList();
if (contentId != null) {
String sql = "select topic_id from " + theTable + " where content_id=" + contentId;
/**
* Set new topics
*/
- public void setTopics(String contentId, String[] topicId) {
+ public void setTopics(String contentId, String[] topicId)
+ throws StorageObjectException {
if (contentId == null){
return;
}
return;
}
//first check which topics this article has
- ArrayList hasTopics = getTopicsOfContent(contentId);
- ArrayList toSet = new ArrayList();
- ArrayList toDelete = new ArrayList();
-
+ 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++){
}
} else {
//all the topics has to be set, so we copy all to the array
- toSet=(ArrayList)Arrays.asList(topicId);
+ for (int i = 0; i < topicId.length; i++){
+ 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 (";
}
}
- public void deleteByContentId(String contentId) {
+ public void deleteByContentId(String contentId)
+ throws StorageObjectException {
if (contentId == null) {
//theLog.printDebugInfo("-- delete topics failed -- no content id");
return;
}
}
- public void deleteByTopicId(String topicId) {
+ public void deleteByTopicId(String topicId)
+ throws StorageObjectException {
if (topicId == null) {
//theLog.printDebugInfo("-- delete topics failed -- no topic id");
return;
}
- public EntityList getContent(EntityTopics topic) {
+ public EntityList getContent(EntityTopics topic)
+ throws StorageObjectException {
EntityList returnList=null;
if (topic != null) {
String id = topic.getId();