X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fstorage%2FDatabaseContent.java;h=2e3a4dcf7f9ec568d053060010ef28f749205536;hb=9065f22c307993d6dd19be86aafcef915f52f36d;hp=fd97ca24dc95d053f402dd5cd030cf2805e3461b;hpb=716ee167e6cab50959a72b2c02c244fe80d7a101;p=mir.git diff --git a/source/mircoders/storage/DatabaseContent.java b/source/mircoders/storage/DatabaseContent.java index fd97ca24..2e3a4dcf 100755 --- a/source/mircoders/storage/DatabaseContent.java +++ b/source/mircoders/storage/DatabaseContent.java @@ -21,87 +21,89 @@ import mircoders.entity.*; public class DatabaseContent extends Database implements StorageObject { - private static DatabaseContent instance; - private static EntityRelation relationComments; - private static EntityRelation relationFeature; - - // Contructors / Singleton - - public static DatabaseContent getInstance() - throws StorageObjectException { - - if (instance == null ) { - instance = new DatabaseContent(); - instance.myselfDatabase = instance; - } - return instance; - } - - private DatabaseContent() - throws StorageObjectException { - - super(); - this.theTable="content"; - this.theCoreTable="media"; - relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY); - relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE); - try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); } - catch (Exception e) { throw new StorageObjectException(e.toString()); } - } - - // methods - - /** - * sets the database flag is_produced to unproduced - */ - - public void setUnproduced(String where) - { - Connection con=null;Statement stmt=null; - String sql = "update content set is_produced=0 where " + where; - try { - con = getPooledCon(); - // should be a preparedStatement because is faster - stmt = con.createStatement(); - executeSql(stmt,sql); - } - catch (Exception e) {theLog.printDebugInfo("-- set unproduced failed");} - finally { freeConnection(con,stmt);} - } - - /** - * returns the comments that belong to the article (via entityrelation) - */ - public SimpleList getComments(EntityContent entC) { - SimpleList comments=null; - try { - comments = relationComments.getManyAsSimpleList(entC,"webdb_create"); - } - catch (StorageObjectException e) { - theLog.printError("DatabaseComments :: failed to get comments"); - } - return comments; - } - - /** - * returns the features that belong to the article (via entityrelation) - */ - public SimpleList getFeature(EntityContent entC) { - SimpleList feature=null; - try { - feature = relationFeature.getManyAsSimpleList(entC); - } - catch (StorageObjectException e) { - theLog.printError("DatabaseComments :: failed to get features"); - } - return feature; - } - - public boolean delete(String id) - throws StorageObjectException { - DatabaseComment.getInstance().deleteByContentId(id); - super.delete(id); - return true; - } + private static DatabaseContent instance; + private static EntityRelation relationComments; + private static EntityRelation relationFeature; + + // Contructors / Singleton + + public static DatabaseContent getInstance() + throws StorageObjectException { + + if (instance == null ) { + instance = new DatabaseContent(); + instance.myselfDatabase = instance; + } + return instance; + } + + private DatabaseContent() + throws StorageObjectException { + + super(); + this.theTable="content"; + this.theCoreTable="media"; + + relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY); + relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE); + try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); } + catch (Exception e) { throw new StorageObjectException(e.toString()); } + } + + // methods + + /** + * sets the database flag is_produced to unproduced + */ + + public void setUnproduced(String where) throws StorageObjectException + { + Connection con=null;Statement stmt=null; + String sql = "update content set is_produced='0' where " + where; + try { + con = getPooledCon(); + // should be a preparedStatement because is faster + stmt = con.createStatement(); + executeUpdate(stmt,sql); + } + catch (Exception e) {_throwStorageObjectException(e, "-- set unproduced failed");} + finally { freeConnection(con,stmt);} + } + + /** + * returns the comments that belong to the article (via entityrelation) + * where db-flag is_published is true + */ + public SimpleList getComments(EntityContent entC) throws StorageObjectException { + SimpleList comments=null; + try { + comments = relationComments.getManyAsSimpleList(entC,"webdb_create","is_published='1'"); + } + catch (StorageObjectException e) { + _throwStorageObjectException(e, "DatabaseComments :: failed to get comments"); + } + return comments; + } + + /** + * returns the features that belong to the article (via entityrelation) + */ + public SimpleList getFeature(EntityContent entC) throws StorageObjectException { + SimpleList feature=null; + try { + feature = relationFeature.getManyAsSimpleList(entC); + } + catch (StorageObjectException e) { + _throwStorageObjectException(e, "DatabaseComments :: failed to get features"); + } + return feature; + } + + public boolean delete(String id) throws StorageObjectException + { + DatabaseComment.getInstance().deleteByContentId(id); + super.delete(id); + return true; + } }