-
- hasTimestamp = false;
- theTable = "comment_x_media";
- theEntityClass = mir.entity.GenericEntity.class;
- }
-
- /**
- * get all the media-files belonging to a comment entity
- *
- */
- public EntityList getMedia(EntityComment comment) throws StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
- // get all to_topic from media_x_topic
- String id = comment.getId();
- 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 = DatabaseMedia.getInstance().selectByWhereClause(subselect,
- "id", -1);
- }
- catch (Throwable e) {
- logger.debug("-- get media failed " + e.toString());
- throw new StorageObjectFailure("-- get media failed ", e);
- }
- }
- return returnList;
- }
-
- public boolean hasMedia(EntityComment comment) throws StorageObjectFailure,
- StorageObjectExc {
- if (comment != null) {
- try {
- if (selectByWhereClause("comment_id=" + comment.getId(), -1).size() ==
- 0)
- return false;
- else
- return true;
- }
- catch (Exception e) {
- logger.error("DatabaseCommentToMedia.hasMedia: " + e.toString());
- throw new StorageObjectFailure("DatabaseCommentToMedia.hasMedia: " +
- e.toString(), e);
- }
- }
- else {
- logger.error("DatabaseCommentToMedia.hasMedia: comment == null");
- throw new StorageObjectExc(
- "DatabaseCommentToMedia.hasMedia: comment == null");
- }
- }
-
- /**
- * get all the audio belonging to a comment entity
- *
- */
- public EntityList getAudio(EntityComment comment) throws StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
- // 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;
- }
-
- /**
- * get all the video belonging to a comment entity
- *
- */
- public EntityList getVideo(EntityComment comment) throws StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
- // 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;
- }
-
- /**
- * get all the images belonging to a comment entity
- *
- */
- public EntityList getImages(EntityComment comment) throws
- StorageObjectFailure {
- EntityList returnList = null;
- if (comment != null) {
- // 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;
- }
-
- /**
- * 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) {
- // 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;
- }
-
- /**
- * 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) {
- // 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 void setMedia(String commentId, String[] mediaId) throws
- StorageObjectFailure {
- if (commentId == null) {
- return;
- }
- if (mediaId == null || mediaId[0] == null) {
- return;
- }
- //first delete all row with comment_id=commentId
- String sql = "delete from " + theTable + " where comment_id=" + commentId;
-
- Connection con = null;
- Statement stmt = null;
- try {
- con = getPooledCon();
- // should be a preparedStatement because is faster
- stmt = con.createStatement();
- ResultSet rs = executeSql(stmt, sql);
- }
- catch (Exception e) {
- logger.error("-- set media failed -- delete");
- throw new StorageObjectFailure("-- set media failed -- delete", e);
- }
- finally {
- freeConnection(con, stmt);
- }
-
- //now insert
- //first delete all row with comment_id=commentId
- for (int i = 0; i < mediaId.length; i++) {
- sql = "insert into " + theTable + " (comment_id,media_id) values ("
- + commentId + "," + mediaId[i] + ")";
- try {
- con = getPooledCon();
- // should be a preparedStatement because is faster
- stmt = con.createStatement();
- int rs = executeUpdate(stmt, sql);
- }
- catch (Exception e) {
- logger.error("-- set topics failed -- insert");
- throw new StorageObjectFailure("-- set topics failed -- insert ", e);
- }
- finally {
- freeConnection(con, stmt);
- }
- }