From 1e06f519c12e542b61df7a19ceec7871011112c7 Mon Sep 17 00:00:00 2001 From: rk Date: Thu, 24 Jan 2002 22:38:04 +0000 Subject: [PATCH] Got rid of AbstractEntity.java / deprecated Entity.getValues() and HTMLTemplateProcessor.makeSimpleHash(Entity) --- source/mir/entity/AbstractEntity.java | 219 ------------ source/mir/entity/Entity.java | 395 ++++++++++++++------- source/mir/entity/EntityRelation.java | 10 +- source/mir/entity/GenericEntity.java | 4 +- source/mir/misc/HTMLTemplateProcessor.java | 22 +- source/mir/servlet/ServletModule.java | 14 - source/mir/servlet/ServletModuleMonitor.java | 2 +- source/mir/storage/Database.java | 14 +- source/mircoders/entity/EntityBreaking.java | 42 +-- source/mircoders/entity/EntityComment.java | 9 +- source/mircoders/entity/EntityContent.java | 25 +- source/mircoders/entity/EntityFeature.java | 2 +- source/mircoders/entity/EntityImages.java | 4 +- source/mircoders/entity/EntityLinksImcs.java | 2 +- source/mircoders/entity/EntityMedia.java | 2 +- source/mircoders/entity/EntityTopics.java | 2 +- source/mircoders/entity/EntityUploadedMedia.java | 2 +- source/mircoders/entity/EntityUsers.java | 2 +- source/mircoders/entity/EntityVideo.java | 2 +- source/mircoders/producer/ProducerAll.java | 2 - source/mircoders/producer/ProducerContent.java | 10 +- source/mircoders/producer/ProducerFeature.java | 2 +- source/mircoders/producer/ProducerStartPage.java | 2 + source/mircoders/producer/ProducerTopics.java | 4 +- source/mircoders/servlet/ServletModuleContent.java | 4 +- .../mircoders/servlet/ServletModuleLinksImcs.java | 2 +- source/mircoders/servlet/ServletModuleUsers.java | 7 +- source/mircoders/storage/DatabaseLinksImcs.java | 18 +- 28 files changed, 346 insertions(+), 479 deletions(-) delete mode 100755 source/mir/entity/AbstractEntity.java diff --git a/source/mir/entity/AbstractEntity.java b/source/mir/entity/AbstractEntity.java deleted file mode 100755 index 632fc396..00000000 --- a/source/mir/entity/AbstractEntity.java +++ /dev/null @@ -1,219 +0,0 @@ -/** - * abstrakte Basisklasse der Entity-Klassen

- */ - - -package mir.entity; - -import java.lang.*; -import java.io.*; -import java.util.*; -import java.sql.*; - -import mir.storage.*; -import mir.misc.*; - -/** - * abstrakte Basisklasse der Entity-Klassen - * - * @author RK - * @version 29.6.1999 - * - */ - -public class AbstractEntity implements Entity -{ - private boolean changed; - protected HashMap theValuesHash; // tablekey / value - protected StorageObject theStorageObject; - protected static Logfile theLog; - protected ArrayList streamedInput=null; - private static int instances = 0; - - public AbstractEntity() { - theLog = Logfile.getInstance(this.getClass().getName()); - this.changed = false; - instances++; - Integer i = new Integer(instances); - System.err.println("New abstract entity instance: "+i.toString()); - } - - /** - * Konstruktor - */ - public AbstractEntity (StorageObject StorageObject) { - this(); - setStorage(StorageObject); - } - - /* - * Setzt das StorageObject der Entity. - */ - public void setStorage (StorageObject storage) { - this.theStorageObject = storage; - } - - /** - * Setzt die Werte der Entity - * @param theStringValues - */ - - public void setValues(HashMap theStringValues) - { - /** @todo should be synchronized */ - theValuesHash = new HashMap(); - String aKey; - Set set = theStringValues.keySet(); - Iterator it = set.iterator(); - int size = set.size(); - for (int i = 0; i < size; i++) { - aKey = (String)it.next(); - theValuesHash.put(aKey, (String)theStringValues.get(aKey)); - } - } - - /** - * Liefert boolschen Wert, ob sich der Inhalt der Entity geändert hat. - * @return true wenn ja, sonst false - */ - public boolean changed () { - return changed; - } - - /** - * Liefert den Primärschluessel der Entity zurueck - * @return String Id - */ - public String getId () { - return (String)getValue(theStorageObject.getIdName()); - } - - /** - * Setzt den Primaerschluessel der Entity - * @param id - */ - public void setId (String id) { - theValuesHash.put(theStorageObject.getIdName(), id); - } - - /** - * Liefert den Wert für einen Feldnamen zurueck - * @param theFieldString - * @return Wert für Feld - */ - public String getValue (String theFieldString) { - return (String)theValuesHash.get(theFieldString); - } - - /** - * Fügt Entity via StorageObject in Datenbank ein. - * @return Primary Key der Entity - * @exception StorageObjectException - */ - public String insert () throws StorageObjectException { - theLog.printDebugInfo("Entity: trying to insert ..."); - if (theStorageObject != null) { - return theStorageObject.insert((Entity)this); - } - else - throw new StorageObjectException("Kein StorageObject gesetzt!"); - } - - /** - * Aktualisiert Aenderungen an der Entity in der Datenbank - * @exception StorageObjectException - */ - public void update () throws StorageObjectException { - theStorageObject.update((Entity)this); - } - - /** - * Setzt den Wert fuer ein Feld - * @param theProp - * @param theValue - * @exception StorageObjectException - */ - public void setValueForProperty (String theProp, String theValue) throws StorageObjectException { - this.changed = true; - if (isField(theProp)) - theValuesHash.put(theProp, theValue); - else - theLog.printWarning("Property not found: " + theProp+theValue); - - } - - /** - * Gibt die Feldnamen der Entity als ArrayList zurueck - * @return ArrayList mit Feldnamen - * @exception StorageObjectException wird geworfen, wenn kein Zugriff auf die Datenbank - * möglich. - */ - public ArrayList getFields () throws StorageObjectException { - return theStorageObject.getFields(); - } - - /** - * Liefert ein int[] mit den Typen der Felder zurueck - * @return int[] mit den Feldtypen - * @exception StorageObjectException - */ - public int[] getTypes () throws StorageObjectException { - return theStorageObject.getTypes(); - } - - /** - * Liefert ArrayListe mit Feldnamen zurueck. - * @return Liste mit Feldnamen - * @exception StorageObjectException - */ - public ArrayList getLabels () throws StorageObjectException { - return theStorageObject.getLabels(); - } - - /** - * Liefert eine Hashmap mit allen Werten der Entity zurueck - * @return HashMap mit Feldname/Wert - */ - public HashMap getValues() { - return theValuesHash; - } - - /** - * Liefert einen ArrayList mit allen Datenbankfeldern, die - * als streamedInput ausgelesen werden muessen. - * Waere automatisierbar ueber die types (blob, etc.) - * Bisher manuell anzulegen in der erbenden Klasse - */ - - public ArrayList streamedInput() { - return streamedInput; - } - - /* Fragt ab, ob fieldName einem Feld entspricht - * @param fieldName - * @return true, wennn ja, sonst false - * @exception StorageObjectException - */ - public boolean isField (String fieldName) throws StorageObjectException { - return theStorageObject.getFields().contains(fieldName); - } - - /** Liefert Anzahl der Instanzen zurück - * @return int - */ - public int getInstances() { - return instances; - } - /** - * Gibt eine Instanz frei - */ - public void finalize () { - instances--; - try { - super.finalize(); - } catch (Throwable t) { - System.err.println(t.toString()); - } - } -} - diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index bff5eb22..c6790d72 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -1,139 +1,286 @@ -/* - * put your module comment here +/** + * Base class the entities are derived from. Provides base functionality of + * an entity

*/ -package mir.entity; +package mir.entity; import java.lang.*; +import java.io.*; import java.util.*; +import java.sql.*; + +import freemarker.template.*; + import mir.storage.*; +import mir.misc.*; /** - * Interface-Definition für Entities + * Base Class of Entities + * Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant + * + * @author rk + * @version 29.6.1999 + * */ -public interface Entity { - - /** - * Eine Entity muss setStorage implementieren, mit der eine Entity mit einem - * StorageObject assoziiert wird. - * - * @param st - */ - public abstract void setStorage (StorageObject st); - - - - /** - * Eine Entity muss setValues implementieren, mit der die Werte der Entity gesetzt werden - * können. - * - * @param ht - */ - public abstract void setValues(HashMap ht); - - - - /** - * Eine Entity muss getValues implementieren, mit der die Werte der Entity - * als HashMap zurueckgeliefert werden - * @return Werte der Entity - */ - public abstract HashMap getValues(); - - - - /** - * Eine Entity muss getFields implementieren, mit der die Feldnamen der - * Entity zurueckgegeben werden. - * @return ArrayList der Feldnamen - * @exception StorageObjectException - */ - public abstract ArrayList getFields () throws StorageObjectException; - - - - /** - * Eine Entity muss getTypes implementieren, mit der die Feldtype der - * Entity zurueckgegeben werden. - * @return int[] der Feldtypen - * @exception StorageObjectException - */ - public abstract int[] getTypes () throws StorageObjectException; - - - - /** - * Eine Entity muss getLabels implementieren, mit der die Feldnamen der - * Entity zurueckgegeben werden. - * @return ArrayList der Feldnamen - * @exception StorageObjectException - */ - public abstract ArrayList getLabels () throws StorageObjectException; - - - - /** - * Eine Entity muss getId implementieren, um den Primaerschuessel der - * Entity zurueckgeliefert zu bekommen. - * - * @return Primary-Key der Entity - */ - public abstract String getId(); - - - - /** - * Eine Entity muss setId implementieren, um den Primaerschuessel der - * Entity zu setzen - * - * @param str - */ - public abstract void setId(String str); - - - /** - * Eine Entity muss getValue implementieren, um den Wert eines - * Feldes zurueckzugeben - * - * @param field - * @return Wert von Feld field - */ - public abstract String getValue (String field); - - - - /** - * Einfügen der Entity in StorageObject - * - * @return Primary-Key der eingefügten Entity - * @exception StorageObjectException - */ - public abstract String insert () throws StorageObjectException; - - - - /** - * Aktualisieren der Entity via StorageObject - * @exception StorageObjectException - */ - public abstract void update () throws StorageObjectException; - - - - /** - * ArrayListe mit Feldern, die einer Sonderbehandlung bedürfen (blobs) - * @return Liste der Feldnamen - */ - public abstract ArrayList streamedInput (); - - - public abstract void setValueForProperty (String theProp, String theValue) throws StorageObjectException; +public class Entity implements TemplateHashModel, TemplateModelRoot +{ + private boolean changed; + protected HashMap theValuesHash; // tablekey / value + protected StorageObject theStorageObject; + protected static Logfile theLog; + protected ArrayList streamedInput=null; + private static int instances = 0; + + public Entity() { + theLog = Logfile.getInstance(this.getClass().getName()); + this.changed = false; + instances++; + Integer i = new Integer(instances); + System.err.println("New abstract entity instance: "+i.toString()); + } + + /** + * Konstruktor + */ + public Entity (StorageObject StorageObject) { + this(); + setStorage(StorageObject); + } + + /* + * Setzt das StorageObject der Entity. + */ + public void setStorage (StorageObject storage) { + this.theStorageObject = storage; + } + + /** + * Setzt die Werte der Entity + * @param theStringValues + */ + + public void setValues(HashMap theStringValues) + { + /** @todo should be synchronized */ + theValuesHash = new HashMap(); + String aKey; + Set set = theStringValues.keySet(); + Iterator it = set.iterator(); + int size = set.size(); + for (int i = 0; i < size; i++) { + aKey = (String)it.next(); + theValuesHash.put(aKey, (String)theStringValues.get(aKey)); + } + } + + /** + * Liefert boolschen Wert, ob sich der Inhalt der Entity geändert hat. + * @return true wenn ja, sonst false + */ + public boolean changed () { + return changed; + } + + /** + * Liefert den Primärschluessel der Entity zurueck + * @return String Id + */ + public String getId () { + return (String)getValue(theStorageObject.getIdName()); + } + + /** + * Setzt den Primaerschluessel der Entity + * @param id + */ + public void setId (String id) { + theValuesHash.put(theStorageObject.getIdName(), id); + } + + /** + * Liefert den Wert für einen Feldnamen zurueck + * @param theFieldString + * @return Wert für Feld + */ + public String getValue (String field) { + String returnValue = null; + if (field != null) + { + if (field.equals("webdb_create_formatted")) + { + if (hasValueForField("webdb_create")) + returnValue=StringUtil.dateToReadableDate(getValue("webdb_create")); + } + else if (field.equals("webdb_lastchange_formatted")) + { + if (hasValueForField("webdblast_change")) + returnValue=StringUtil.dateToReadableDate(getValue("webdb_lastchange")); + } + else + returnValue = (String)theValuesHash.get(field); + } + return returnValue; + } + + + public boolean hasValueForField(String field) + { + if (theValuesHash!=null) + return theValuesHash.containsKey(field); + return false; + } + + /** + * Fügt Entity via StorageObject in Datenbank ein. + * @return Primary Key der Entity + * @exception StorageObjectException + */ + public String insert () throws StorageObjectException { + theLog.printDebugInfo("Entity: trying to insert ..."); + if (theStorageObject != null) { + return theStorageObject.insert((Entity)this); + } + else + throw new StorageObjectException("Kein StorageObject gesetzt!"); + } + + /** + * Aktualisiert Aenderungen an der Entity in der Datenbank + * @exception StorageObjectException + */ + public void update () throws StorageObjectException { + theStorageObject.update((Entity)this); + } + + /** + * Setzt den Wert fuer ein Feld + * @param theProp + * @param theValue + * @exception StorageObjectException + */ + public void setValueForProperty (String theProp, String theValue) throws StorageObjectException { + this.changed = true; + if (isField(theProp)) + theValuesHash.put(theProp, theValue); + else + theLog.printWarning("Property not found: " + theProp+theValue); + + } + + /** + * Gibt die Feldnamen der Entity als ArrayList zurueck + * @return ArrayList mit Feldnamen + * @exception StorageObjectException wird geworfen, wenn kein Zugriff auf die Datenbank + * möglich. + */ + public ArrayList getFields () throws StorageObjectException { + return theStorageObject.getFields(); + } + + /** + * Liefert ein int[] mit den Typen der Felder zurueck + * @return int[] mit den Feldtypen + * @exception StorageObjectException + */ + public int[] getTypes () throws StorageObjectException { + return theStorageObject.getTypes(); + } + + /** + * Liefert ArrayListe mit Feldnamen zurueck. + * @return Liste mit Feldnamen + * @exception StorageObjectException + */ + public ArrayList getLabels () throws StorageObjectException { + return theStorageObject.getLabels(); + } + + /** + * Liefert eine Hashmap mit allen Werten der Entity zurueck + * @return HashMap mit Feldname/Wert + * + * @deprecated This method is deprecated and will be deleted in the next release. + * AbstractEntity interfaces freemarker.template.TemplateHashModel now and can + * be used in the same way as SimpleHash. + + */ + public HashMap getValues() { + return theValuesHash; + } + + /** + * Liefert einen ArrayList mit allen Datenbankfeldern, die + * als streamedInput ausgelesen werden muessen. + * Waere automatisierbar ueber die types (blob, etc.) + * Bisher manuell anzulegen in der erbenden Klasse + */ + + public ArrayList streamedInput() { + return streamedInput; + } + + /* Fragt ab, ob fieldName einem Feld entspricht + * @param fieldName + * @return true, wennn ja, sonst false + * @exception StorageObjectException + */ + public boolean isField (String fieldName) throws StorageObjectException { + return theStorageObject.getFields().contains(fieldName); + } + + /** Liefert Anzahl der Instanzen zurück + * @return int + */ + public int getInstances() { + return instances; + } + /** + * Gibt eine Instanz frei + */ + public void finalize () { + instances--; + try { + super.finalize(); + } catch (Throwable t) { + System.err.println(t.toString()); + } + } + + + // Now implements freemarkers TemplateHashModel + // two methods have to be overridden: + // 1. public boolean isEmpty() throws TemplateModelException + // 2. public TemplateModel get(java.lang.String key) throws TemplateModelException + + public boolean isEmpty() throws TemplateModelException + { + if (theValuesHash==null || theValuesHash.isEmpty()) + return true; + return false; + } + + public TemplateModel get(java.lang.String key) throws TemplateModelException + { + theLog.printDebugInfo("trying to get: " + key); + return new SimpleScalar(getValue(key)); + } + + public void put(java.lang.String key, TemplateModel model) + { + // empty for testing + } + + public void remove(java.lang.String key) + { + // empty for testing + } + + + ////////////////////////////////////////////////////////////////////////////////// } - - - diff --git a/source/mir/entity/EntityRelation.java b/source/mir/entity/EntityRelation.java index 161855db..fa7e0652 100755 --- a/source/mir/entity/EntityRelation.java +++ b/source/mir/entity/EntityRelation.java @@ -50,10 +50,10 @@ public class EntityRelation { * null. */ - public SimpleHash getOneAsSimpleHash(Entity entity) throws StorageObjectException { + public Entity getOneAsSimpleHash(Entity entity) throws StorageObjectException { if (type==TO_ONE) { - Entity returnEntity = getOne(entity); - if (returnEntity!=null) return HTMLTemplateProcessor.makeSimpleHash(returnEntity); + Entity returnEntity = (Entity)getOne(entity); + if (returnEntity!=null) return returnEntity; } return null; } @@ -83,7 +83,7 @@ public class EntityRelation { } else return null; } - + /** * @return Liefert eine freemarker.template.SimpleList mit den verknuepften * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten @@ -128,7 +128,7 @@ public class EntityRelation { } return null; } - + /** * @return Liefert eine freemarker.template.SimpleList mit den verknuepften * Entities, wenn es sich um eine TO_MANY Liste handelt, ansonsten diff --git a/source/mir/entity/GenericEntity.java b/source/mir/entity/GenericEntity.java index 12f3d562..a52015bc 100755 --- a/source/mir/entity/GenericEntity.java +++ b/source/mir/entity/GenericEntity.java @@ -11,8 +11,8 @@ package mir.entity; * @author /rk * @version 1.2 */ -public class GenericEntity extends AbstractEntity - implements Entity {} +public class GenericEntity extends Entity + {} diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 56747aa4..1e47adc7 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -42,9 +42,12 @@ public final class HTMLTemplateProcessor { templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir"); templateCache = new FileTemplateCache(templateDir); templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND); - templateCache.startAutoUpdate(); + // gone in freemarker 1.71 + // templateCache.startAutoUpdate(); + docRoot = MirConfig.getProp("RootUri"); theLog=Logfile.getInstance("HTMLTemplateProcessor"); + //the quick hack is back in effect as it was more broken than ever before // -mh // sorry: nadir back in town, i have to debug the mirbase.jar in the @@ -231,7 +234,7 @@ public final class HTMLTemplateProcessor { SimpleList simpleList = new SimpleList(); if (aList != null) { for(int i=0;i