- 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++){
- boolean set=false;
- int whichTopic = 0;
- for(Iterator it=hasTopics.iterator();it.hasNext();){
- Integer topic = (Integer)it.next();
- if(topicId[i].equals(topic.toString())){
- set=true;
- } else {
- whichTopic = i;
- }
- }
- if(set==false){
- toSet.add(topicId[i]);
- logger.debug("to set: "+ topicId[i]);
- }
+ List currentTopics = getTopicsOfContent(anArticleId);
+ logger.debug("New topics = " + newTopics.toString());
+ logger.debug("Current topics = " + currentTopics.toString());
+ List topicsToDelete = new Vector(currentTopics);
+ topicsToDelete.removeAll(newTopics);
+ List topicsToAdd = new Vector(newTopics);
+ topicsToAdd.removeAll(currentTopics);
+ logger.debug("to delete = " + topicsToDelete.toString());
+ logger.debug("to add = " + topicsToAdd.toString());
+
+
+ if (!topicsToDelete.isEmpty()) {
+ String sql =
+ "delete from " + theTable + " " +
+ "where content_id=" + anArticleId +
+ " and topic_id in (" + getIdListExpression(topicsToDelete) + ")";
+
+ Connection connection=null;
+ Statement statement=null;
+ try {
+ connection = getPooledCon();
+ statement = connection.createStatement();
+ int rs = executeUpdate(statement, sql);