import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.Vector;
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
* <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.2 2003/11/24 23:37:18 rk Exp $
+ * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.3 2003/11/25 02:04:43 rk Exp $
*
*/
private DatabaseCommentToMedia() {
super();
-
logger = new LoggerWrapper("Database.CommentToMedia");
-
hasTimestamp = false;
theTable = "comment_x_media";
theEntityClass = mir.entity.GenericEntity.class;
StorageObjectExc {
if (comment != null) {
try {
- // TODO make this a count statement
- if (selectByWhereClause("comment_id=" + comment.getId(), -1).size() ==
- 0)
- return false;
- else
- return true;
+ return (getSize("comment_id=" + comment.getId()) == 0) ? false:true;
}
catch (Exception e) {
logger.error("DatabaseCommentToMedia.hasMedia: " + e.toString());
}
}
+ private EntityList getMultiMediaForComment(StorageObject store, EntityComment comment)
+ throws StorageObjectFailure {
+
+ EntityList returnList = null;
+ if (comment != null) {
+ String id = comment.getId();
+ try {
+ Vector extraTable = new Vector();
+ extraTable.add(theTable+" cxm");
+ // media should stay in uploaded order. this is especially important
+ // for photo stories which require a specific chronologic order.
+ // this is why we have the the second parameter "id"
+ store.selectByWhereClause("m", extraTable,
+ "m.id=cxm.media_id and cxm.comment_id="+id, "id", -1, -1);
+
+ } catch (Exception e) {
+ logger.error("DatabaseCommenttToMedia.getMultiMediaForComment: " + e.toString());
+ throw new StorageObjectFailure("DatabaseContentToMedia.etMultiMediaForComment: " +
+ e.toString(), e);
+ }
+ }
+ return returnList;
+ }
+
/**
* get all the audio belonging to a comment entity
- *
*/
public EntityList getAudio(EntityComment comment) throws StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = comment.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where comment_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseAudio.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.getAudio: " + e.toString());
- throw new StorageObjectFailure("DatabaseCommentToMedia.getAudio: " +
- e.toString(), e);
- }
- }
- return returnList;
+ return getMultiMediaForComment(DatabaseAudio.getInstance(), comment);
}
/**
*
*/
public EntityList getVideo(EntityComment comment) throws StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = comment.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where comment_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseVideo.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.getVideo: " + e.toString());
- throw new StorageObjectFailure("DatabaseCommentToMedia.getVideo: " +
- e.toString(), e);
- }
- }
- return returnList;
+ return getMultiMediaForComment(DatabaseVideo.getInstance(), comment);
}
/**
* get all the images belonging to a comment entity
- *
*/
- public EntityList getImages(EntityComment comment) throws
- StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = comment.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where comment_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseImages.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.getImages: " + e.toString());
- throw new StorageObjectFailure("DatabaseCommentToMedia.getImages: " +
- e.toString(), e);
- }
- }
- return returnList;
+ public EntityList getImages(EntityComment comment) throws StorageObjectFailure {
+ return getMultiMediaForComment(DatabaseImages.getInstance(), comment);
}
/**
* get all the uploaded/other Media belonging to a comment entity
- *
*/
public EntityList getOther(EntityComment comment) throws StorageObjectFailure {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList = null;
- if (comment != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = comment.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where comment_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseOther.getInstance().selectByWhereClause(subselect,
- "id");
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.getOther: " + e.toString());
- throw new StorageObjectFailure("DatabaseCommentToMedia.getOther: " + e.toString(), e);
- }
- }
- return returnList;
+ return getMultiMediaForComment(DatabaseOther.getInstance(), comment);
}
/**
* get all the uploaded/other Media belonging to a comment entity
- *
*/
- public EntityList getUploadedMedia(EntityComment comment) throws
- StorageObjectFailure {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList = null;
- if (comment != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = comment.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where comment_id=" + id + ")";
-
- try {
- returnList = DatabaseUploadedMedia.getInstance().selectByWhereClause(
- subselect,
- "id");
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.getUploadedMedia: " + e.toString());
- throw new StorageObjectFailure(
- "DatabaseCommentToMedia.getUploadedMedia: " + e.toString(), e);
- }
- }
- return returnList;
+ public EntityList getUploadedMedia(EntityComment comment) throws StorageObjectFailure {
+ return getMultiMediaForComment(DatabaseUploadedMedia.getInstance(), comment);
}
public void setMedia(String commentId, String[] mediaId) throws
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
+import java.util.Vector;
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
* <b>implements abstract DB connection to the content_x_media SQL table
*
* @author RK, mir-coders group
- * @version $Id: DatabaseContentToMedia.java,v 1.19.2.2 2003/11/24 23:37:18 rk Exp $
+ * @version $Id: DatabaseContentToMedia.java,v 1.19.2.3 2003/11/25 02:04:43 rk Exp $
*
*/
super();
logger = new LoggerWrapper("Database.ContentToMedia");
-
hasTimestamp = false;
theTable = "content_x_media";
theEntityClass = mir.entity.GenericEntity.class;
public boolean hasMedia(EntityContent content) throws StorageObjectFailure,
StorageObjectExc {
if (content != null) {
- try {
- // TODO make this a count statement
- if (selectByWhereClause("content_id=" + content.getId(), -1).size() ==
- 0)
- return false;
- else
- return true;
+ try {
+ return (getSize("content_id=" + content.getId()) == 0) ? false:true;
}
catch (Exception e) {
logger.error("DatabaseContentToMedia.hasMedia: " + e.toString());
}
}
- /**
- * get all the audio belonging to a content entity
- *
- */
- public EntityList getAudio(EntityContent content) throws StorageObjectFailure {
+ private EntityList getMultiMediaForContent(StorageObject store, EntityContent content)
+ throws StorageObjectFailure {
+
EntityList returnList = null;
if (content != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
String id = content.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where content_id=" + id + ")";
-
- try {
+ try {
+ Vector extraTable = new Vector();
+ extraTable.add(theTable+" cxm");
// media should stay in uploaded order. this is especially important
// for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseAudio.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.getAudio: " + e.toString());
- throw new StorageObjectFailure("DatabaseContentToMedia.getAudio: " +
- e.toString(), e);
+ // this is why we have the the second parameter "id"
+ store.selectByWhereClause("m", extraTable,
+ "m.id=cxm.media_id and cxm.content_id="+id, "id", -1, -1);
+
+ } catch (Exception e) {
+ logger.error("DatabaseContentToMedia.getMultiMediaForContent: " + e.toString());
+ throw new StorageObjectFailure("DatabaseContentToMedia.etMultiMediaForContent: " +
+ e.toString(), e);
}
}
return returnList;
}
+
+ /**
+ * get all the audio belonging to a content entity
+ */
+ public EntityList getAudio(EntityContent content) throws StorageObjectFailure {
+ return getMultiMediaForContent(DatabaseAudio.getInstance(), content);
+ }
/**
* get all the video belonging to a content entity
- *
*/
public EntityList getVideo(EntityContent content) throws StorageObjectFailure {
- EntityList returnList = null;
- if (content != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = content.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where content_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseVideo.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.getVideo: " + e.toString());
- throw new StorageObjectFailure("DatabaseContentToMedia.getVideo: " +
- e.toString(), e);
- }
- }
- return returnList;
+ return getMultiMediaForContent(DatabaseVideo.getInstance(), content);
}
/**
* get all the images belonging to a content entity
- *
*/
- public EntityList getImages(EntityContent content) throws
- StorageObjectFailure {
- EntityList returnList = null;
- if (content != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = content.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where content_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseImages.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.getImages: " + e.toString());
- throw new StorageObjectFailure("DatabaseContentToMedia.getImages: " +
- e.toString(), e);
- }
- }
- return returnList;
+ public EntityList getImages(EntityContent content) throws StorageObjectFailure {
+ return getMultiMediaForContent(DatabaseImages.getInstance(), content);
}
/**
* get all the uploaded/other Media belonging to a content entity
- *
*/
public EntityList getOther(EntityContent content) throws StorageObjectFailure {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList = null;
- if (content != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = content.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where content_id=" + id + ")";
-
- try {
- // media should stay in uploaded order. this is especially important
- // for photo stories which require a specific chronologic order.
- // this is why we have the the second parameter "id"
- returnList = DatabaseOther.getInstance().selectByWhereClause(subselect,
- "id");
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.getOther: " + e.toString());
- throw new StorageObjectFailure("DatabaseContentToMedia.getOther: " + e.toString(), e);
- }
- }
- return returnList;
+ return getMultiMediaForContent(DatabaseOther.getInstance(), content);
}
/**
* get all the uploaded/other Media belonging to a content entity
- *
*/
- public EntityList getUploadedMedia(EntityContent content) throws
- StorageObjectFailure {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList = null;
- if (content != null) {
-// TODO rewrite as relational sql
- // get all to_topic from media_x_topic
- String id = content.getId();
- //this is not supported by mysql
- String subselect = "id in (select media_id from " + theTable +
- " where content_id=" + id + ")";
-
- try {
- returnList = DatabaseUploadedMedia.getInstance().selectByWhereClause(
- subselect,
- "id");
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.getUploadedMedia: " + e.toString());
- throw new StorageObjectFailure(
- "DatabaseContentToMedia.getUploadedMedia: " + e.toString(), e);
- }
- }
- return returnList;
+ public EntityList getUploadedMedia(EntityContent content) throws StorageObjectFailure {
+ return getMultiMediaForContent(DatabaseUploadedMedia.getInstance(), content);
}
- public void setMedia(String contentId, String[] mediaId) throws
- StorageObjectFailure {
- if (contentId == null) {
- return;
- }
- if (mediaId == null || mediaId[0] == null) {
+
+ public void setMedia(String contentId, String[] mediaId) throws StorageObjectFailure {
+ if (contentId == null || mediaId == null || mediaId[0] == null) {
return;
}
//first delete all row with content_id=contentId
}
public void deleteByMediaId(String mediaId) throws StorageObjectFailure {
+
if (mediaId == null) {
//theLog.printDebugInfo("-- delete topics failed -- no topic id");
return;
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) {
-
- // TODO rewrite with getByWhereClauseWithExtraTables
-
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 content failed");
}
- finally { freeConnection(con,stmt);}
}
return returnList;
}