X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fstorage%2FDatabaseContentToTopics.java;h=3a6bdd837a256060a2d2d4cccb8d085375de2792;hb=1dc7fa03037c7e3e212286bd9e4d012694600f64;hp=073ecd283635ac7cc23be67caee7c42d8e8babb3;hpb=3a661e8f0f659ab5ed2ac0e4d982ac0b398d11f1;p=mir.git diff --git a/source/mircoders/storage/DatabaseContentToTopics.java b/source/mircoders/storage/DatabaseContentToTopics.java index 073ecd28..3a6bdd83 100755 --- a/source/mircoders/storage/DatabaseContentToTopics.java +++ b/source/mircoders/storage/DatabaseContentToTopics.java @@ -21,197 +21,200 @@ import mircoders.entity.*; public class DatabaseContentToTopics extends Database implements StorageObject{ - private static DatabaseContentToTopics instance; - - public static DatabaseContentToTopics getInstance() - throws StorageObjectException { - if (instance == null) { - instance = new DatabaseContentToTopics(); - instance.myselfDatabase = instance; - } - return instance; - } - - private DatabaseContentToTopics() - throws StorageObjectException { - - super(); - this.hasTimestamp = false; - this.theTable="content_x_topic"; - try { - // this.theEntityClass = Class.forName("mir.entity.EntityGruppen"); - } catch (Exception e) { - throw new StorageObjectException(e.toString()); - } - } - - - public EntityList getTopics(EntityContent content) { - EntityList returnList=null; - if (content != null) { - // get all to_topic from content_x_topic - String id = content.getId(); - String subselect = "id in (select topic_id from " + theTable + " where content_id=" + id+")"; - - try { - returnList = DatabaseTopics.getInstance().selectByWhereClause(subselect,-1); - } catch (Exception e) { - theLog.printDebugInfo("-- get topics failed " + e.toString()); - } - } - return returnList; - } - - - public void setTopics(EntityContent content, ArrayList topicId) { - if (content == null && topicId == null) { - return; - } - String contentId = content.getId(); - //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 topics failed -- delete"); - } finally { - freeConnection(con,stmt); - } - - //now insert - //first delete all row with content_id=contentId - - for (Iterator i = topicId.listIterator(); i.hasNext();) { - sql = "insert into "+ theTable +" (content_id,topic_id) values (" - + contentId + "," + i.next().toString() + ")"; - try { - con = getPooledCon(); - // should be a preparedStatement because is faster - stmt = con.createStatement(); - ResultSet rs = executeSql(stmt,sql); - } catch (Exception e) { - theLog.printDebugInfo("-- set topics failed -- insert"); - } finally { - freeConnection(con,stmt); - } - } - } - - - public void setTopics(String contentId, String topicId) { - if (contentId == null && topicId == 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(); - int rs = executeUpdate(stmt,sql); - } catch (Exception e) { - theLog.printDebugInfo("-- set topics failed -- delete"); - } finally { - freeConnection(con,stmt); - } - - //now insert - //first delete all row with content_id=contentId - - sql = "insert into "+ theTable +" (content_id,topic_id) values (" - + contentId + "," + topicId + ")"; - 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"); - } finally { - freeConnection(con,stmt); - } - } - - public void deleteByContentId(String contentId) { - if (contentId == null) { - //theLog.printDebugInfo("-- delete topics failed -- no content id"); - return; - } - //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("-- delete topics failed "); - } finally { - freeConnection(con,stmt); - } - } - - public void deleteByTopicId(String topicId) { - if (topicId == null) { - //theLog.printDebugInfo("-- delete topics failed -- no topic id"); - return; - } - //delete all row with content_id=contentId - String sql = "delete from "+ theTable +" where topic_id=" + topicId; - - 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("-- delete topics failed "); - } finally { - freeConnection(con,stmt); - } - } - - - public EntityList getContent(EntityTopics topic) { - EntityList returnList=null; - if (topic != null) { - String id = topic.getId(); - String select = "select content_id from " + theTable + " where topic_id=" + id; - - // 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 topicSelect= "id IN ("; - boolean first=true; - while (rs.next()) { - if (first==false) topicSelect+=","; - topicSelect += rs.getString(1); - first=false; - } - topicSelect+=")"; - if (first==false) - returnList = DatabaseContent.getInstance().selectByWhereClause(topicSelect,-1); - } - } - catch (Exception e) {theLog.printDebugInfo("-- get contetn failed");} - finally { freeConnection(con,stmt);} - } - return returnList; - } + private static DatabaseContentToTopics instance; + + public static DatabaseContentToTopics getInstance() + throws StorageObjectException { + if (instance == null) { + instance = new DatabaseContentToTopics(); + instance.myselfDatabase = instance; + } + return instance; + } + + private DatabaseContentToTopics() + throws StorageObjectException { + + super(); + this.hasTimestamp = false; + this.theTable="content_x_topic"; + /** + try { + this.theEntityClass = Class.forName("mircoders.entity.EntityGruppen"); + } catch (Exception e) { + throw new StorageObjectException(e.toString()); + } + */ + } + + + public EntityList getTopics(EntityContent content) { + EntityList returnList=null; + if (content != null) { + // get all to_topic from content_x_topic + String id = content.getId(); + String subselect = "id in (select topic_id from " + theTable + " where content_id=" + id+")"; + + try { + returnList = DatabaseTopics.getInstance().selectByWhereClause(subselect,-1); + } catch (Exception e) { + theLog.printDebugInfo("-- get topics failed " + e.toString()); + } + } + return returnList; + } + + + public void setTopics(String contentId, String[] topicId) { + if (contentId == null){ + return; + } + if (topicId==null || topicId[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 topics failed -- delete"); + } finally { + freeConnection(con,stmt); + } + + //now insert + //first delete all row with content_id=contentId + for (int i=0;i