1 package mircoders.storage;
8 import freemarker.template.*;
14 import mircoders.entity.*;
17 * <b>this class implements the access to the content-table</b>
22 public class DatabaseContent extends Database implements StorageObject {
24 private static DatabaseContent instance;
25 private static EntityRelation relationComments;
26 private static EntityRelation relationFeature;
28 // Contructors / Singleton
30 public static DatabaseContent getInstance()
31 throws StorageObjectException {
33 if (instance == null ) {
34 instance = new DatabaseContent();
35 instance.myselfDatabase = instance;
40 private DatabaseContent()
41 throws StorageObjectException {
44 this.theTable="content";
45 this.theCoreTable="media";
46 relationComments = new EntityRelation("id", "to_media", DatabaseComment.getInstance(), EntityRelation.TO_MANY);
47 relationFeature = new EntityRelation("id", "to_feature", DatabaseFeature.getInstance(), EntityRelation.TO_ONE);
48 try { this.theEntityClass = Class.forName("mircoders.entity.EntityContent"); }
49 catch (Exception e) { throw new StorageObjectException(e.toString()); }
55 * sets the database flag is_produced to unproduced
58 public void setUnproduced(String where)
60 Connection con=null;Statement stmt=null;
61 String sql = "update content set is_produced='0' where " + where;
64 // should be a preparedStatement because is faster
65 stmt = con.createStatement();
66 executeUpdate(stmt,sql);
68 catch (Exception e) {theLog.printDebugInfo("-- set unproduced failed");}
69 finally { freeConnection(con,stmt);}
73 * returns the comments that belong to the article (via entityrelation)
74 * where db-flag is_published is true
76 public SimpleList getComments(EntityContent entC) {
77 SimpleList comments=null;
79 comments = relationComments.getManyAsSimpleList(entC,"webdb_create","is_published='1'");
81 catch (StorageObjectException e) {
82 theLog.printError("DatabaseComments :: failed to get comments");
88 * returns the features that belong to the article (via entityrelation)
90 public SimpleList getFeature(EntityContent entC) {
91 SimpleList feature=null;
93 feature = relationFeature.getManyAsSimpleList(entC);
95 catch (StorageObjectException e) {
96 theLog.printError("DatabaseComments :: failed to get features");
101 public boolean delete(String id)
102 throws StorageObjectException {
103 DatabaseComment.getInstance().deleteByContentId(id);