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 theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Entity.Logfile"));
36 public AbstractEntity() {
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);
145 * Gibt die Feldnamen der Entity als ArrayList zurueck
146 * @return ArrayList mit Feldnamen
147 * @exception StorageObjectException wird geworfen, wenn kein Zugriff auf die Datenbank
150 public ArrayList getFields () throws StorageObjectException {
151 return theStorageObject.getFields();
155 * Liefert ein int[] mit den Typen der Felder zurueck
156 * @return int[] mit den Feldtypen
157 * @exception StorageObjectException
159 public int[] getTypes () throws StorageObjectException {
160 return theStorageObject.getTypes();
164 * Liefert ArrayListe mit Feldnamen zurueck.
165 * @return Liste mit Feldnamen
166 * @exception StorageObjectException
168 public ArrayList getLabels () throws StorageObjectException {
169 return theStorageObject.getLabels();
173 * Liefert eine Hashmap mit allen Werten der Entity zurueck
174 * @return HashMap mit Feldname/Wert
176 public HashMap getValues() {
177 return theValuesHash;
181 * Liefert einen ArrayList mit allen Datenbankfeldern, die
182 * als streamedInput ausgelesen werden muessen.
183 * Waere automatisierbar ueber die types (blob, etc.)
184 * Bisher manuell anzulegen in der erbenden Klasse
187 public ArrayList streamedInput() {
188 return streamedInput;
191 /* Fragt ab, ob fieldName einem Feld entspricht
193 * @return true, wennn ja, sonst false
194 * @exception StorageObjectException
196 public boolean isField (String fieldName) throws StorageObjectException {
197 return theStorageObject.getFields().contains(fieldName);
200 /** Liefert Anzahl der Instanzen zurück
203 public int getInstances() {
207 * Gibt eine Instanz frei
209 public void finalize () {
213 } catch (Throwable t) {
214 System.err.println(t.toString());