* abstrakte Basisklasse der Entity-Klassen
*
* @author RK
- * @version 29.6.1999
+ * @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;
- static {
- theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile"));
- }
-
- public AbstractEntity() {
- this.changed = false;
- instances++;
- }
-
- /**
- * 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));
- }
+ 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() {
+ /**
+ * 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 () {
+ /**
+ * Gibt eine Instanz frei
+ */
+ public void finalize () {
instances--;
try {
super.finalize();