* <b>implements abstract DB connection to the comment_x_media SQL table
*
* @author RK, mir-coders group
- * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.4 2003/11/26 19:21:06 rk Exp $
+ * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.5 2003/11/26 19:23:16 rk Exp $
*
*/
public EntityList getComment(EntityUploadedMedia media) throws
StorageObjectFailure {
+
EntityList returnList = null;
if (media != null) {
- // TODO rewrite as relational sql
- String id = media.getId();
- String select = "select comment_id from " + theTable + " where media_id=" +
- id;
- // execute select statement
- Connection con = null;
- Statement stmt = null;
+ String id = media.getId();
+ Vector extraTables = new Vector();
+ extraTables.add(theTable + " cxm");
+
+ String mediaSelect = "cxm.comment_id=c.id and cxm.media_id="+id;
try {
- con = getPooledCon();
- // should be a preparedStatement because is faster
- stmt = con.createStatement();
- ResultSet rs = executeSql(stmt, select);
- if (rs != null) {
- String mediaSelect = "id IN (";
- boolean first = true;
- while (rs.next()) {
- if (first == false)
- mediaSelect += ",";
- mediaSelect += rs.getString(1);
- first = false;
- }
- mediaSelect += ")";
- if (first == false)
- returnList = DatabaseComment.getInstance().selectByWhereClause(
- mediaSelect, -1);
- }
+ returnList = DatabaseComment.getInstance().selectByWhereClause("c",
+ extraTables, mediaSelect, "c.id" );
+
}
catch (Exception e) {
logger.error("-- get comment failed");
throw new StorageObjectFailure("-- get comment failed -- ", e);
}
- finally {
- freeConnection(con, stmt);
- }
}
return returnList;
}