X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fstorage%2FDatabaseContentToMedia.java;h=e154fcb6705a04313837d02752254c5770bca146;hb=c785369f4ca9b7a6b295464041c14206c6db84bf;hp=9a475751899656b8d2703d00fa90ddfbccc5abf6;hpb=302ba1b59ef0365d9272ebe1cafb3cf500002e11;p=mir.git diff --git a/source/mircoders/storage/DatabaseContentToMedia.java b/source/mircoders/storage/DatabaseContentToMedia.java index 9a475751..e154fcb6 100755 --- a/source/mircoders/storage/DatabaseContentToMedia.java +++ b/source/mircoders/storage/DatabaseContentToMedia.java @@ -90,7 +90,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); } catch (Exception e) { theLog.printDebugInfo("-- set topics failed -- insert"); } finally { @@ -99,7 +99,28 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } } - + public void addMedia(String contentId, String mediaId) { + if (contentId == null && mediaId == null) { + return; + } + + Connection con=null;Statement stmt=null; + //now insert + + String sql = "insert into "+ theTable +" (content_id,media_id) values (" + + contentId + "," + mediaId + ")"; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt,sql); + } catch (Exception e) { + theLog.printDebugInfo("-- add media failed -- insert"); + } finally { + freeConnection(con,stmt); + } + } + public void setMedia(String contentId, String mediaId) { if (contentId == null && mediaId == null) { return; @@ -149,7 +170,7 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); } catch (Exception e) { //theLog.printDebugInfo("-- delete topics failed "); } finally { @@ -163,14 +184,14 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ return; } //delete all row with content_id=contentId - String sql = "delete from "+ theTable +" where topic_id=" + mediaId; + String sql = "delete from "+ theTable +" where media_id=" + mediaId; Connection con=null;Statement stmt=null; try { con = getPooledCon(); // should be a preparedStatement because is faster stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); + int rs = executeUpdate(stmt,sql); theLog.printDebugInfo("-- delete media success "); } catch (Exception e) { theLog.printDebugInfo("-- delete media failed "); @@ -178,6 +199,28 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ freeConnection(con,stmt); } } + + public void delete(String contentId, String mediaId) { + if (mediaId == null || contentId==null) { + theLog.printDebugInfo("-- delete media failed -- missing parameter"); + return; + } + //delete all row with content_id=contentId and media_id=mediaId + String sql = "delete from "+ theTable +" where media_id=" + mediaId + " and content_id= "+contentId; + + Connection con=null;Statement stmt=null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + int rs = executeUpdate(stmt,sql); + theLog.printDebugInfo("-- delete content_x_media success "); + } catch (Exception e) { + theLog.printDebugInfo("-- delete content_x_media failed "); + } finally { + freeConnection(con,stmt); + } + } public EntityList getContent(EntityMedia media) { @@ -211,5 +254,39 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ } return returnList; } + +/** + * Returns a EntityList with all content-objects having a relation to a media + */ + +public EntityList getContent() { + EntityList returnList=null; + + String select = "select distinct content_id from " + theTable; + // execute select statement + Connection con=null;Statement stmt=null; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + ResultSet rs = executeSql(stmt,select); + if (rs!=null) { + String mediaSelect= "id IN ("; + boolean first=true; + while (rs.next()) { + if (first==false) mediaSelect+=","; + mediaSelect += rs.getString(1); + first=false; + } + mediaSelect+=")"; + if (first==false) + returnList = DatabaseContent.getInstance().selectByWhereClause(mediaSelect,"webdb_lastchange desc"); + } + } + catch (Exception e) {theLog.printDebugInfo("-- get content failed");} + finally { freeConnection(con,stmt);} + + return returnList; + } }