package mircoders.storage;
-import java.sql.Connection;\r
-import java.sql.ResultSet;\r
-import java.sql.Statement;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Vector;\r
-\r
-import mir.entity.EntityList;\r
-import mir.log.LoggerWrapper;\r
-import mir.storage.Database;\r
-import mir.storage.StorageObject;\r
-import mir.storage.StorageObjectFailure;\r
-import mircoders.entity.EntityContent;\r
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import mir.entity.EntityList;
+import mir.log.LoggerWrapper;
+import mir.storage.Database;
+import mir.storage.StorageObject;
+import mir.storage.StorageObjectFailure;
+import mircoders.entity.EntityContent;
import mircoders.entity.EntityTopics;
/**
public EntityList getTopics(EntityContent content) {
EntityList returnList=null;
if (content != null) {
- // get all to_topic from content_x_topic
- String id = content.getId();
- String subselect = "id in (select topic_id from " + theTable + " where content_id=" + id+")";
+ String id = content.getId();
try {
- returnList = DatabaseTopics.getInstance().selectByWhereClause(subselect,-1);
+ Vector extraTables = new Vector();
+ extraTables.add(theTable+" cxt");
+ returnList = DatabaseTopics.getInstance()
+ .selectByWhereClauseWithExtraTables("t",extraTables,
+ "t.id=cxt.topic_id and cxt.content_id="+id );
}
catch (Exception e) {
logger.error("-- get topics failed " + e.toString());
logger.debug("to add = " + topicsToAdd.toString());
- if (!topicsToDelete.isEmpty()) {
+ if (!topicsToDelete.isEmpty()) {
String sql =
"delete from " + theTable + " " +
"where content_id=" + anArticleId +
freeConnection(con,stmt);
}
}
-
-
+
+/**
+ * Returns list of Content for a specific topic
+ * @param topic
+ * @return EntityList
+ * @throws StorageObjectFailure
+ */
public EntityList getContent(EntityTopics topic)
throws StorageObjectFailure {
EntityList returnList=null;
if (topic != null) {
String id = topic.getId();
- String select = "select content_id from " + theTable + " where topic_id=" + id;
-
- // execute select statement
- Connection con=null;Statement stmt=null;
try {
- con = getPooledCon();
- // should be a preparedStatement because is faster
- stmt = con.createStatement();
- ResultSet rs = executeSql(stmt,select);
- if (rs!=null) {
- String topicSelect= "id IN (";
- boolean first=true;
- while (rs.next()) {
- if (first==false) topicSelect+=",";
- topicSelect += rs.getString(1);
- first=false;
- }
- topicSelect+=")";
- if (first==false)
- returnList = DatabaseContent.getInstance().selectByWhereClause(topicSelect,-1);
- }
+ Vector extraTables = new Vector();
+ extraTables.add(theTable+" cxt");
+ returnList = DatabaseContent.getInstance()
+ .selectByWhereClauseWithExtraTables("c",extraTables,
+ "c.id=cxt.content_id and cxt.topic_id="+id );
}
catch (Exception e) {
- logger.error("-- get contetn failed");
+ logger.error("-- get content failed");
}
- finally { freeConnection(con,stmt);}
}
return returnList;
}