- logger = new LoggerWrapper("Database.CommentToMedia");
- hasTimestamp = false;
- theTable = "comment_x_media";
- theEntityClass = mir.entity.GenericEntity.class;
- }
-
- public boolean hasMedia(EntityComment comment) throws StorageObjectFailure,
- StorageObjectExc {
- if (comment != null) {
- try {
- return (getSize("comment_id=" + comment.getId()) == 0) ? false: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");
- }
- }
-
- 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 {
- return getMultiMediaForComment(DatabaseAudio.getInstance(), comment);
- }
-
- /**
- * get all the video belonging to a comment entity
- *
- */
- public EntityList getVideo(EntityComment comment) throws StorageObjectFailure {
- return getMultiMediaForComment(DatabaseVideo.getInstance(), comment);
- }
-
- /**
- * get all the images belonging to a comment entity
- */
- 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 {
- return getMultiMediaForComment(DatabaseOther.getInstance(), comment);
- }
-
- /**
- * get all the uploaded/other Media belonging to a comment entity
- */
- public EntityList getUploadedMedia(EntityComment comment) throws StorageObjectFailure {
- return getMultiMediaForComment(DatabaseUploadedMedia.getInstance(), comment);
- }
-
- 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);
- }