2 * <b>abstrakte Basisklasse der Entity-Klassen</b><p>
17 * abstrakte Basisklasse der Entity-Klassen
24 public class AbstractEntity implements Entity
26 private boolean changed;
27 protected HashMap theValuesHash; // tablekey / value
28 protected StorageObject theStorageObject;
29 protected static Logfile theLog;
30 protected ArrayList streamedInput=null;
31 private static int instances = 0;
33 public AbstractEntity() {
34 theLog = Logfile.getInstance(this.getClass().getName());
37 Integer i = new Integer(instances);
38 System.err.println("New abstract entity instance: "+i.toString());
44 public AbstractEntity (StorageObject StorageObject) {
46 setStorage(StorageObject);
50 * Setzt das StorageObject der Entity.
52 public void setStorage (StorageObject storage) {
53 this.theStorageObject = storage;
57 * Setzt die Werte der Entity
58 * @param theStringValues
61 public void setValues(HashMap theStringValues)
63 /** @todo should be synchronized */
64 theValuesHash = new HashMap();
66 Set set = theStringValues.keySet();
67 Iterator it = set.iterator();
68 int size = set.size();
69 for (int i = 0; i < size; i++) {
70 aKey = (String)it.next();
71 theValuesHash.put(aKey, (String)theStringValues.get(aKey));
76 * Liefert boolschen Wert, ob sich der Inhalt der Entity geändert hat.
77 * @return true wenn ja, sonst false
79 public boolean changed () {
84 * Liefert den Primärschluessel der Entity zurueck
87 public String getId () {
88 return (String)getValue(theStorageObject.getIdName());
92 * Setzt den Primaerschluessel der Entity
95 public void setId (String id) {
96 theValuesHash.put(theStorageObject.getIdName(), id);
100 * Liefert den Wert für einen Feldnamen zurueck
101 * @param theFieldString
102 * @return Wert für Feld
104 public String getValue (String theFieldString) {
105 return (String)theValuesHash.get(theFieldString);
109 * Fügt Entity via StorageObject in Datenbank ein.
110 * @return Primary Key der Entity
111 * @exception StorageObjectException
113 public String insert () throws StorageObjectException {
114 theLog.printDebugInfo("Entity: trying to insert ...");
115 if (theStorageObject != null) {
116 return theStorageObject.insert((Entity)this);
119 throw new StorageObjectException("Kein StorageObject gesetzt!");
123 * Aktualisiert Aenderungen an der Entity in der Datenbank
124 * @exception StorageObjectException
126 public void update () throws StorageObjectException {
127 theStorageObject.update((Entity)this);
131 * Setzt den Wert fuer ein Feld
134 * @exception StorageObjectException
136 public void setValueForProperty (String theProp, String theValue) throws StorageObjectException {
138 if (isField(theProp))
139 theValuesHash.put(theProp, theValue);
141 theLog.printWarning("Property not found: " + theProp+theValue);
146 * Gibt die Feldnamen der Entity als ArrayList zurueck
147 * @return ArrayList mit Feldnamen
148 * @exception StorageObjectException wird geworfen, wenn kein Zugriff auf die Datenbank
151 public ArrayList getFields () throws StorageObjectException {
152 return theStorageObject.getFields();
156 * Liefert ein int[] mit den Typen der Felder zurueck
157 * @return int[] mit den Feldtypen
158 * @exception StorageObjectException
160 public int[] getTypes () throws StorageObjectException {
161 return theStorageObject.getTypes();
165 * Liefert ArrayListe mit Feldnamen zurueck.
166 * @return Liste mit Feldnamen
167 * @exception StorageObjectException
169 public ArrayList getLabels () throws StorageObjectException {
170 return theStorageObject.getLabels();
174 * Liefert eine Hashmap mit allen Werten der Entity zurueck
175 * @return HashMap mit Feldname/Wert
177 public HashMap getValues() {
178 return theValuesHash;
182 * Liefert einen ArrayList mit allen Datenbankfeldern, die
183 * als streamedInput ausgelesen werden muessen.
184 * Waere automatisierbar ueber die types (blob, etc.)
185 * Bisher manuell anzulegen in der erbenden Klasse
188 public ArrayList streamedInput() {
189 return streamedInput;
192 /* Fragt ab, ob fieldName einem Feld entspricht
194 * @return true, wennn ja, sonst false
195 * @exception StorageObjectException
197 public boolean isField (String fieldName) throws StorageObjectException {
198 return theStorageObject.getFields().contains(fieldName);
201 /** Liefert Anzahl der Instanzen zurück
204 public int getInstances() {
208 * Gibt eine Instanz frei
210 public void finalize () {
214 } catch (Throwable t) {
215 System.err.println(t.toString());