- theEntityClass = mir.entity.GenericEntity.class;
- }
-
- public boolean hasMedia(EntityContent content) throws StorageObjectFailure,
- StorageObjectExc {
- if (content != null) {
- try {
- return (getSize("content_id=" + content.getId()) == 0) ? false:true;
- }
- catch (Exception e) {
- logger.error("DatabaseContentToMedia.hasMedia: " + e.toString());
- throw new StorageObjectFailure("DatabaseContentToMedia.hasMedia: " +
- e.toString(), e);
- }
- }
- else {
- logger.error("DatabaseContentToMedia.hasMedia: content == null");
- throw new StorageObjectExc(
- "DatabaseContentToMedia.hasMedia: content == null");
- }
- }
-
- private EntityList getMultiMediaForContent(StorageObject store, EntityContent content)
- throws StorageObjectFailure {
-
- EntityList returnList = null;
- if (content != null) {
- String id = content.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.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 {
- return getMultiMediaForContent(DatabaseVideo.getInstance(), content);
- }
-
- /**
- * get all the images belonging to a content entity
- */
- 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 {
- return getMultiMediaForContent(DatabaseOther.getInstance(), content);
- }
-
- /**
- * get all the uploaded/other Media belonging to a content entity
- */
- public EntityList getUploadedMedia(EntityContent content) throws StorageObjectFailure {
- return getMultiMediaForContent(DatabaseUploadedMedia.getInstance(), content);
- }
-
-
- 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
- String sql = "delete from " + mainTable + " where content_id=" + contentId;
-
- 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 content_id=contentId
- for (int i = 0; i < mediaId.length; i++) {
- sql = "insert into " + mainTable + " (content_id,media_id) values ("
- + contentId + "," + 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);
- }
- }