import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
-import java.util.Vector;
+import java.util.ArrayList;
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.7 2004/11/21 22:07:14 zapata Exp $
+ * @version $Id: DatabaseCommentToMedia.java,v 1.3.2.8 2005/01/09 20:37:15 zapata Exp $
*
*/
private DatabaseCommentToMedia() {
super();
+
logger = new LoggerWrapper("Database.CommentToMedia");
- hasTimestamp = false;
mainTable = "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(mainTable+" 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 " + mainTable + " where comment_id=" + commentId;
-
- Connection con = null;
- Statement stmt = null;
- try {
- con = obtainConnection();
- // 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 " + mainTable + " (comment_id,media_id) values ("
- + commentId + "," + mediaId[i] + ")";
- try {
- con = obtainConnection();
- // 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);
- }
- }
+ entityClass = mir.entity.GenericEntity.class;
}
public void addMedia(String commentId, String mediaId) throws
if (media != null) {
String id = media.getId();
- Vector extraTables = new Vector();
+ ArrayList extraTables = new ArrayList();
extraTables.add(mainTable + " cxm");
String mediaSelect = "cxm.comment_id=c.id and cxm.media_id="+id;
public EntityList getComment() throws StorageObjectFailure {
EntityList returnList = null;
- Vector extraTables = new Vector();
+ ArrayList extraTables = new ArrayList();
extraTables.add(mainTable + " cxm");
String mediaSelect = "cxm.comment_id=c.id";