/**
* Base class the entities are derived from. Provides base functionality of
- * an entity<p>
+ * an entity. Entities are used to represent rows of a database table.<p>
*/
* Base Class of Entities
* Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant
*
- * @author rk
- * @version 29.6.1999
+ * @version $Revision: 1.7 $ $Date: 2002/06/28 20:35:38 $
+ * @author $Author: mh $
+ *
+ * $Log: Entity.java,v $
+ * Revision 1.7 2002/06/28 20:35:38 mh
+ * use some cvs macros/id's
+ *
*
*/
protected static Logfile theLog;
protected ArrayList streamedInput=null;
private static int instances = 0;
+ static {
+ theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
+ }
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());
+ //System.err.println("New abstract entity instance: "+i.toString());
}
/**
- * Konstruktor
+ * Constructor
+ * @param StorageObject The StorageObject of the Entity.
*/
public Entity (StorageObject StorageObject) {
this();
}
/*
- * Setzt das StorageObject der Entity.
+ * Sets the StorageObject of the Entity.
*/
public void setStorage (StorageObject storage) {
this.theStorageObject = storage;
}
/**
- * Setzt die Werte der Entity
- * @param theStringValues
+ * Sets the values of the Entity.
+ * @param theStringValues HashMap containing the new values of the Entity
*/
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));
+ if (theStringValues!=null) {
+ 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));
+ }
}
+ else theLog.printWarning("Entity.setValues called with null HashMap");
}
/**
- * Liefert boolschen Wert, ob sich der Inhalt der Entity geändert hat.
+ * Returns whether the content of the Entity has changed.
* @return true wenn ja, sonst false
*/
public boolean changed () {
}
/**
- * Liefert den Primärschluessel der Entity zurueck
+ * Returns the primary key of the Entity.
* @return String Id
*/
public String getId () {
}
/**
- * Setzt den Primaerschluessel der Entity
+ * Defines the primary key of the Entity
* @param id
*/
public void setId (String id) {
}
/**
- * Liefert den Wert für einen Feldnamen zurueck
- * @param theFieldString
- * @return Wert für Feld
+ * Returns the value of a field by field name.
+ * @param field The name of the field
+ * @return value of the field
*/
public String getValue (String field) {
String returnValue = null;
{
if (field.equals("webdb_create_formatted"))
{
- if (hasValueForField("webdb_create"))
- returnValue=StringUtil.dateToReadableDate(getValue("webdb_create"));
+ 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"));
+ returnValue=StringUtil.dateToReadableDate(getValue("webdb_lastchange"));
+ }
+ else if (field.equals("webdb_create_dc"))
+ {
+ if (hasValueForField("webdb_create"))
+ returnValue=StringUtil.webdbdateToDCDate(getValue("webdb_create"));
}
else
returnValue = (String)theValuesHash.get(field);
return returnValue;
}
-
public boolean hasValueForField(String field)
{
if (theValuesHash!=null)
}
/**
- * Fügt Entity via StorageObject in Datenbank ein.
- * @return Primary Key der Entity
+ * Insers Entity into the database via StorageObject
+ * @return Primary Key of the Entity
* @exception StorageObjectException
*/
public String insert () throws StorageObjectException {
}
/**
- * Aktualisiert Aenderungen an der Entity in der Datenbank
+ * Saves changes of this Entity to the database
* @exception StorageObjectException
*/
public void update () throws StorageObjectException {
}
/**
- * Setzt den Wert fuer ein Feld
- * @param theProp
- * @param theValue
+ * Sets the value for a field. Issues a log message if the field name
+ * supplied was not found in the Entity.
+ * @param theProp The field name whose value has to be set
+ * @param theValue The new value of the field
* @exception StorageObjectException
*/
- public void setValueForProperty (String theProp, String theValue) throws StorageObjectException {
+ public void setValueForProperty (String theProp, String theValue)
+ throws StorageObjectException {
this.changed = true;
if (isField(theProp))
theValuesHash.put(theProp, theValue);
- else
+ 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.
+ * Returns the field names of the Entity as ArrayListe.
+ * @return ArrayList with field names
+ * @exception StorageObjectException is throuwn if database access was impossible
*/
public ArrayList getFields () throws StorageObjectException {
return theStorageObject.getFields();
}
/**
- * Liefert ein int[] mit den Typen der Felder zurueck
- * @return int[] mit den Feldtypen
+ * Returns an int[] with the types of the fields
+ * @return int[] that contains the types of the fields
* @exception StorageObjectException
*/
public int[] getTypes () throws StorageObjectException {
}
/**
- * Liefert ArrayListe mit Feldnamen zurueck.
- * @return Liste mit Feldnamen
+ * Returns an ArrayList with field names
+ * @return List with field names
* @exception StorageObjectException
*/
public ArrayList getLabels () throws StorageObjectException {
}
/**
- * Liefert eine Hashmap mit allen Werten der Entity zurueck
- * @return HashMap mit Feldname/Wert
+ * Returns a Hashmap with all values of the Entity.
+ * @return HashMap with field name as key and the corresponding values
*
* @deprecated This method is deprecated and will be deleted in the next release.
- * AbstractEntity interfaces freemarker.template.TemplateHashModel now and can
+ * Entity interfaces freemarker.template.TemplateHashModel now and can
* be used in the same way as SimpleHash.
*/
public HashMap getValues() {
+ theLog.printWarning("## using deprecated Entity.getValues() - a waste of resources");
return theValuesHash;
}
/**
+ * Returns an ArrayList with all database fields that can
+ * be evaluated as streamedInput.
+ * Could be automated by the types (blob, etc.)
+ * Until now to be created manually in the inheriting class
+ *
* Liefert einen ArrayList mit allen Datenbankfeldern, die
* als streamedInput ausgelesen werden muessen.
* Waere automatisierbar ueber die types (blob, etc.)
return streamedInput;
}
- /* Fragt ab, ob fieldName einem Feld entspricht
+ /** Returns whether fieldName is a valid field name of this Entity.
* @param fieldName
- * @return true, wennn ja, sonst false
+ * @return true in case fieldName is a field name, else false.
* @exception StorageObjectException
*/
public boolean isField (String fieldName) throws StorageObjectException {
return theStorageObject.getFields().contains(fieldName);
}
- /** Liefert Anzahl der Instanzen zurück
- * @return int
+ /** Returns the number of instances of this Entity
+ * @return int The number of instances
*/
public int getInstances() {
return instances;
}
+
+ protected void throwStorageObjectException (Exception e, String wo) throws StorageObjectException {
+ theLog.printError( e.toString() + " Funktion: "+ wo);
+ throw new StorageObjectException("Storage Object Exception in entity" +e.toString());
+ }
+
/**
- * Gibt eine Instanz frei
+ * Frees an instance
*/
- public void finalize () {
+ /*public void finalize () {
instances--;
+ Integer i = new Integer(instances);
+ System.err.println("Removing abstract entity instance: "+i.toString());
try {
super.finalize();
} catch (Throwable t) {
System.err.println(t.toString());
}
- }
+ }*/
// Now implements freemarkers TemplateHashModel
public boolean isEmpty() throws TemplateModelException
{
- if (theValuesHash==null || theValuesHash.isEmpty())
- return true;
- return false;
+ return (theValuesHash==null || theValuesHash.isEmpty()) ? true : false;
}
public TemplateModel get(java.lang.String key) throws TemplateModelException
{
- theLog.printDebugInfo("trying to get: " + key);
- return new SimpleScalar(getValue(key));
+ return new SimpleScalar(getValue(key));
}
-
- public void put(java.lang.String key, TemplateModel model)
+
+ public void put(java.lang.String key, TemplateModel model)
{
- // empty for testing
+ // putting should only take place via setValue and is limited to the
+ // database fields associated with the entity. no additional freemarker
+ // stuff will be available via Entity.
+ theLog.printWarning("### put is called on entity! - the values will be lost!");
}
public void remove(java.lang.String key)
{
- // empty for testing
+ // do we need this?
}