1.1 restoration
[mir.git] / source / mircoders / storage / DatabaseContentToTopics.java
index eca6c29..2186c5e 100755 (executable)
@@ -70,14 +70,12 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     logger = new LoggerWrapper("Database.ContentToTopics");
 
     hasTimestamp = false;
-    theTable="content_x_topic";
+    mainTable="content_x_topic";
     theEntityClass = mir.entity.GenericEntity.class;
   }
 
   /**
    * This class return an EntityList of Topics
-   * @param EntityContent content
-   * @returns EntityList
    */
   public EntityList getTopics(EntityContent content) {
     EntityList returnList=null;
@@ -86,10 +84,10 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       String id = content.getId();
       try {
         Vector extraTables = new Vector();
-        extraTables.add(theTable+" cxt");
+        extraTables.add(mainTable+" cxt");
         returnList = DatabaseTopics.getInstance()
-                      .selectByWhereClauseWithExtraTables("t",extraTables, 
-                                              "t.id=cxt.topic_id and  cxt.content_id="+id );        
+                      .selectByWhereClauseWithExtraTables("t",extraTables,
+                                              "t.id=cxt.topic_id and  cxt.content_id="+id );
       }
       catch (Exception e) {
         logger.error("-- get topics failed " + e.toString());
@@ -99,24 +97,24 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
   }
 
   /**
-   * Returns a ArrayList of Integer-Objects from a content-id.
-   * @returns ArrayList
+   * Returns a List of String-Objects from a content-id.
    */
   public List getTopicsOfContent(String contentId)
     throws StorageObjectFailure {
     ArrayList returnList = new ArrayList();
 
     if (contentId != null) {
-      String sql = "select topic_id from " + theTable + " where content_id=" + contentId;
+      String sql = "select topic_id from " + mainTable + " where content_id=" + contentId;
       Connection con=null;Statement stmt=null;
       try {
-        con = getPooledCon();
+        con = obtainConnection();
+
         // should be a preparedStatement because is faster
         stmt = con.createStatement();
         ResultSet rs = executeSql(stmt,sql);
         if(rs!=null){
           while(rs.next()){
-            returnList.add(new Integer(rs.getInt("topic_id")));
+            returnList.add(Integer.toString(rs.getInt("topic_id")));
           }
         }
       }
@@ -163,26 +161,26 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     List currentTopics = getTopicsOfContent(anArticleId);
     logger.debug("New topics = " + newTopics.toString());
     logger.debug("Current topics = " + currentTopics.toString());
-    List topicsToDelete = new Vector(currentTopics);
+    List topicsToDelete = new ArrayList(currentTopics);
     topicsToDelete.removeAll(newTopics);
-    List topicsToAdd = new Vector(newTopics);
+    List topicsToAdd = new ArrayList(newTopics);
     topicsToAdd.removeAll(currentTopics);
     logger.debug("to delete = " + topicsToDelete.toString());
     logger.debug("to add = " + topicsToAdd.toString());
 
 
-    if (!topicsToDelete.isEmpty()) {      
+    if (!topicsToDelete.isEmpty()) {
       String sql =
-          "delete from " + theTable + " " +
+          "delete from " + mainTable + " " +
           "where content_id=" + anArticleId +
           "        and topic_id in (" + getIdListExpression(topicsToDelete) + ")";
 
       Connection connection=null;
       Statement statement=null;
       try {
-        connection = getPooledCon();
+        connection = obtainConnection();
         statement = connection.createStatement();
-        int rs = executeUpdate(statement, sql);
+        executeUpdate(statement, sql);
       }
       catch (Exception e) {
         logger.error("-- deleting topics failed");
@@ -200,15 +198,15 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
     while (i.hasNext()) {
       Integer topicId = (Integer) i.next();
       String sql =
-          "insert into " + theTable + " (content_id, topic_id) "+
+          "insert into " + mainTable + " (content_id, topic_id) "+
           "values (" + anArticleId + "," + topicId + ")";
       Connection connection=null;
       Statement statement=null;
       try {
-        connection = getPooledCon();
+        connection = obtainConnection();
         // should be a preparedStatement because is faster
         statement = connection.createStatement();
-        int rs = executeUpdate(statement, sql);
+        executeUpdate(statement, sql);
       }
       catch (Exception e) {
         logger.error("-- adding topics failed");
@@ -230,14 +228,14 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       return;
     }
     //delete all row with content_id=contentId
-    String sql = "delete from "+ theTable +" where content_id=" + contentId;
+    String sql = "delete from "+ mainTable +" where content_id=" + contentId;
 
     Connection con=null;Statement stmt=null;
     try {
-      con = getPooledCon();
+      con = obtainConnection();
       // should be a preparedStatement because is faster
       stmt = con.createStatement();
-      ResultSet rs = executeSql(stmt,sql);
+      executeSql(stmt,sql);
     } catch (Exception e) {
       //theLog.printDebugInfo("-- delete topics failed  ");
     } finally {
@@ -252,14 +250,14 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       return;
     }
     //delete all row with content_id=contentId
-    String sql = "delete from "+ theTable +" where topic_id=" + topicId;
+    String sql = "delete from "+ mainTable +" where topic_id=" + topicId;
 
     Connection con=null;Statement stmt=null;
     try {
-      con = getPooledCon();
+      con = obtainConnection();
       // should be a preparedStatement because is faster
       stmt = con.createStatement();
-      ResultSet rs = executeSql(stmt,sql);
+      executeSql(stmt,sql);
     }
     catch (Exception e) {
       logger.error("-- delete topics failed ");
@@ -268,7 +266,7 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       freeConnection(con,stmt);
     }
   }
-  
+
 /**
  * Returns list of Content for a specific topic
  * @param topic
@@ -282,10 +280,10 @@ public class DatabaseContentToTopics extends Database implements StorageObject{
       String id = topic.getId();
       try {
         Vector extraTables = new Vector();
-        extraTables.add(theTable+" cxt");
+        extraTables.add(mainTable+" cxt");
         returnList = DatabaseContent.getInstance()
-                      .selectByWhereClauseWithExtraTables("c",extraTables, 
-                          "c.id=cxt.content_id and cxt.topic_id="+id );    
+                      .selectByWhereClauseWithExtraTables("c",extraTables,
+                          "c.id=cxt.content_id and cxt.topic_id="+id );
       }
       catch (Exception e) {
         logger.error("-- get content failed");