public class EntityRelation {
- public String fromId;
- public String toId;
- public StorageObject storage;
- public int type;
-
- public final static int TO_ONE = 1;
- public final static int TO_MANY = 2;
-
-
- /**
- * Kontruktor fuer EntityRelation
- * @param fromId ist der Feldname in der ausgehenden Tabelle fuer die Relation
- * @param toId ist der Feldname in der Zieltablle
- * @param storage ist das StorageObject, ueber das der Zugriff auf die abhaengige
- * Tabelle erfolgt.
- * @param type ist der Typ der EntityRelation (TO_ONE oder TO_MANY)
- */
-
- public EntityRelation(String fromId, String toId, StorageObject storage, int type) {
- this.fromId = fromId;
- this.toId = toId;
- this.storage = storage;
- this.type = type;
- }
-
- /**
- * @return Liefert eine abhaengige Entity mit den verknuepften
- * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten
- * null.
- */
-
- public Entity getOne(Entity entity) throws StorageObjectException {
- if (type==TO_ONE) {
- return storage.selectById(entity.getValue(fromId));
- }
- else return null;
- }
-
- /**
- * @return Liefert ein freemarker.template.SimpleHash mit den verknuepften
- * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten
- * null.
- */
-
- public SimpleHash getOneAsSimpleHash(Entity entity) throws StorageObjectException {
- if (type==TO_ONE) {
- Entity returnEntity = getOne(entity);
- if (returnEntity!=null) return HTMLTemplateProcessor.makeSimpleHash(returnEntity);
- }
- return null;
- }
-
- /**
- * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
- * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
- * null.
- */
-
- public EntityList getMany(Entity entity) throws StorageObjectException{
- if (type==TO_MANY) {
- return storage.selectByFieldValue(toId, entity.getValue(fromId));
- }
- else return null;
- }
-
- /**
- * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
- * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
- * null.
- */
-
- public EntityList getMany(Entity entity, String order) throws StorageObjectException{
- if (type==TO_MANY) {
- return storage.selectByWhereClause(toId+"="+entity.getValue(fromId), order,-1);
- }
- else return null;
- }
-
- /**
- * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
- * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
- * null.
- */
-
- public SimpleList getManyAsSimpleList(Entity entity)
- throws StorageObjectException {
-
- if (type==TO_MANY) {
- EntityList returnList = getMany(entity);
- if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList);
- }
- return null;
- }
-
- /**
- * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
- * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
- * null.
- */
-
- public SimpleList getManyAsSimpleList(Entity entity, String order)
- throws StorageObjectException {
-
- if (type==TO_MANY) {
- EntityList returnList = getMany(entity, order);
- if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList);
- }
- return null;
- }
-
- /**
- * @return Liefert den Referenznamen der abhaengigen Tabelle
- */
-
- public String getName() {
- return "to" + storage.getTableName();
- }
-
-
-}
\ No newline at end of file
+ public String fromId;
+ public String toId;
+ public StorageObject storage;
+ public int type;
+
+ public final static int TO_ONE = 1;
+ public final static int TO_MANY = 2;
+
+
+ /**
+ * Kontruktor fuer EntityRelation
+ * @param fromId ist der Feldname in der ausgehenden Tabelle fuer die Relation
+ * @param toId ist der Feldname in der Zieltablle
+ * @param storage ist das StorageObject, ueber das der Zugriff auf die abhaengige
+ * Tabelle erfolgt.
+ * @param type ist der Typ der EntityRelation (TO_ONE oder TO_MANY)
+ */
+
+ public EntityRelation(String fromId, String toId, StorageObject storage, int type) {
+ this.fromId = fromId;
+ this.toId = toId;
+ this.storage = storage;
+ this.type = type;
+ }
+
+ /**
+ * @return Liefert eine abhaengige Entity mit den verknuepften
+ * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten
+ * null.
+ */
+
+ public Entity getOne(Entity entity) throws StorageObjectException {
+ if (type==TO_ONE) {
+ return storage.selectById(entity.getValue(fromId));
+ }
+ else return null;
+ }
+
+ /**
+ * @return Liefert ein freemarker.template.SimpleHash mit den verknuepften
+ * Entities, wenn es sich um eine TO_ONE Beziehung handelt, ansonsten
+ * null.
+ */
+
+ public SimpleHash getOneAsSimpleHash(Entity entity) throws StorageObjectException {
+ if (type==TO_ONE) {
+ Entity returnEntity = getOne(entity);
+ if (returnEntity!=null) return HTMLTemplateProcessor.makeSimpleHash(returnEntity);
+ }
+ return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public EntityList getMany(Entity entity) throws StorageObjectException{
+ if (type==TO_MANY) {
+ return storage.selectByFieldValue(toId, entity.getValue(fromId));
+ }
+ else return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public EntityList getMany(Entity entity, String order) throws StorageObjectException{
+ if (type==TO_MANY) {
+ return storage.selectByWhereClause(toId+"="+entity.getValue(fromId), order,-1);
+ }
+ else return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public EntityList getMany(Entity entity, String order, String whereClause) throws StorageObjectException{
+ if (type==TO_MANY) {
+ return storage.selectByWhereClause(toId + "=" + entity.getValue(fromId) + " and " + whereClause, order,-1);
+ }
+ else return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public SimpleList getManyAsSimpleList(Entity entity)
+ throws StorageObjectException {
+
+ if (type==TO_MANY) {
+ EntityList returnList = getMany(entity);
+ if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList);
+ }
+ return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public SimpleList getManyAsSimpleList(Entity entity, String order)
+ throws StorageObjectException {
+
+ if (type==TO_MANY) {
+ EntityList returnList = getMany(entity, order);
+ if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList);
+ }
+ return null;
+ }
+
+ /**
+ * @return Liefert eine freemarker.template.SimpleList mit den verknuepften
+ * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten
+ * null.
+ */
+
+ public SimpleList getManyAsSimpleList(Entity entity, String order, String whereClause)
+ throws StorageObjectException {
+
+ if (type==TO_MANY) {
+ EntityList returnList = getMany(entity, order, whereClause);
+ if (returnList!=null) return HTMLTemplateProcessor.makeSimpleList(returnList);
+ }
+ return null;
+ }
+ /**
+ * @return Liefert den Referenznamen der abhaengigen Tabelle
+ */
+
+ public String getName() {
+ return "to" + storage.getTableName();
+ }
+
+
+}
public class ModuleComment extends AbstractModule
{
- static Logfile theLog;
-
- // Contructor
- public ModuleComment(StorageObject theStorage)
- {
- if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Comment.Logfile"));
- if (theStorage == null) theLog.printWarning("StorageObject was null!");
- this.theStorage = theStorage;
- }
-
- // Methoden
- public SimpleList getCommentAsSimpleList() {
- return ((DatabaseComment)theStorage).getPopupData();
- }
+ static Logfile theLog;
+
+ // Contructor
+ public ModuleComment(StorageObject theStorage)
+ {
+ if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Comment.Logfile"));
+ if (theStorage == null) theLog.printWarning("StorageObject was null!");
+ this.theStorage = theStorage;
+ }
+
+ // Methoden
+ public SimpleList getCommentAsSimpleList() {
+ return ((DatabaseComment)theStorage).getPopupData();
+ }
+
+ /**
+ * setValues in the Entity and updates them on the StorageObject
+ */
+ public String set(HashMap theValues) throws ModuleException
+ {
+ try {
+ Entity theEntity = theStorage.selectById((String)theValues.get("id"));
+ if (theEntity == null)
+ throw new ModuleException("No Objekt with id in Database id: " + theValues.get("id"));
+ theEntity.setValues(theValues);
+ theEntity.update();
+ //set content to unproduced
+ DatabaseContent.getInstance().setUnproduced("id=" + theEntity.getValue("to_media"));
+ return theEntity.getId();
+ }
+ catch (StorageObjectException e){
+ e.printStackTrace(System.err);
+ throw new ModuleException(e.toString());
+ }
+ }
}
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)
+ {
+ 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) {theLog.printDebugInfo("-- 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) {
+ SimpleList comments=null;
+ try {
+ comments = relationComments.getManyAsSimpleList(entC,"webdb_create","is_published='1'");
+ }
+ 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;
+ }
}
<table border="0" cellpadding="2" cellspacing="1">
<tr>
- <td colspan="5"><form method="post" action="${actionRoot}">
+ <td colspan="5">
+ <form method="post" action="${actionRoot}">
<input type="hidden" name="module" value="Comment">
<input type="hidden" name="do" value="list">
+ <input type="hidden" name="offset" value="${offset}">
<input type="text" size="10" maxlength="20" name="query_text" value="${query_text}">
<select name="query_field">
<option value="title"<if query_field=="title"> selected</if>>Titel</option>
<td>
<font size="-1">${entry.description}</font>
- <a href="${actionRoot}?module=Comment&do=edit&id=${entry.id}">edit</a>
+ <a href="${actionRoot}?module=Comment&do=edit&order=${order}&offset=${offset}&id=${entry.id}">edit</a>
</td>
<td>
<td colspan="5"><form method="post" action="${actionRoot}">\r
<input type="hidden" name="module" value="Comment">\r
<input type="hidden" name="do" value="list">\r
- <input type="hidden" name="order" value="webdb_create">\r
+ <input type="hidden" name="order" value="webdb_create">\r
+ <input type="hidden" name="offset" value="${offset}">
<input type="text" size="10" maxlength="20" name="query_text" value="${query_text}">\r
<select name="query_field">\r
<option value="title"<if query_field=="title"> selected</if>>Titel</option>\r
\r
<td>\r
<font size="-1">${entry.description}</font>\r
- <a href="${actionRoot}?module=Comment&do=edit&id=${entry.id}">edit</a>\r
+ <a href="${actionRoot}?module=Comment&do=edit&id=${entry.id}&order=${order}&offset=${offset}">edit</a>\r
</td>\r
\r
<td>\r