- /**
- * get all the images belonging to a content entity
- *
- */
- public EntityList getImages(EntityContent content)
- throws StorageObjectException {
- EntityList returnList=null;
- if (content != null) {
- // 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 = DatabaseImages.getInstance().selectByWhereClause(subselect,-1);
- } catch (Exception e) {
- theLog.printDebugInfo("-- get images failed " + e.toString());
- throw new StorageObjectException("-- get images failed " + e.toString());
- }
- }
- return returnList;
- }
-
-
- /**
- * get all the uploaded/other Media belonging to a content entity
- *
- */
- public EntityList getOther(EntityContent content)
- throws StorageObjectException
- {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList=null;
- if (content != null) {
- // 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 = DatabaseOther.getInstance().selectByWhereClause(subselect,
- "id");
- } catch (Exception e) {
- e.printStackTrace();
- theLog.printDebugInfo("-- get Other failed " + e.toString());
- throw new StorageObjectException("-- get Other failed "
- + e.toString());
- }
- }
- return returnList;
- }
-
- /**
- * get all the uploaded/other Media belonging to a content entity
- *
- */
- public EntityList getUploadedMedia(EntityContent content)
- throws StorageObjectException
- {
- /** @todo this should only fetch published media / rk */
-
- EntityList returnList=null;
- if (content != null) {
- // 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) {
- e.printStackTrace();
- theLog.printDebugInfo("-- get uploadedMedia failed " + e.toString());
- throw new StorageObjectException("-- get uploadedMedia failed "
- + e.toString());
- }
- }
- return returnList;
- }
-
-
- public void setMedia(String contentId, String[] mediaId)
- throws StorageObjectException {
- if (contentId == null){
- return;
- }
- if (mediaId==null || mediaId[0]==null) {
- return;
- }
- //first delete all row with content_id=contentId
- String sql = "delete from "+ theTable +" where content_id=" + contentId;
-
- 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) {
- theLog.printDebugInfo("-- set media failed -- delete");
- throw new StorageObjectException("-- set media failed -- delete"+e.toString());
- } 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 "+ theTable +" (content_id,media_id) values ("
- + contentId + "," + mediaId[i] + ")";
- try {
- con = getPooledCon();
- // should be a preparedStatement because is faster
- stmt = con.createStatement();
- int rs = executeUpdate(stmt,sql);
- } catch (Exception e) {
- theLog.printDebugInfo("-- set topics failed -- insert");
- throw new StorageObjectException("-- set topics failed -- insert "+e.toString());
- } finally {
- freeConnection(con,stmt);
- }
- }
- }
-
- public void addMedia(String contentId, String mediaId)
- throws StorageObjectException {