2 * put your module comment here
10 import freemarker.template.*;
17 * Abstrakte Klasse, von denen die Modules die Basisfunktionalität erben.
18 * Die Moduleschicht dient dazu, Funktionalitaeten zur Verfügung zu stellen,
19 * die von mehreren ServletModulen verwendet werden.
21 public class AbstractModule {
22 protected StorageObject theStorage;
23 protected Logfile theLog;
25 public void setStorage(StorageObject storage) {
26 this.theStorage = storage;
30 * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist.
31 * @return Standard-StorageObject
33 public StorageObject getStorageObject () {
38 * Holt eine Entity anhand der Id via StorageObject
39 * @param String der Entity
42 public Entity getById (String id) throws ModuleException {
44 if (theStorage == null)
45 throw new ModuleException("Kein StorageObject gesetzt");
46 Entity entity = (Entity)theStorage.selectById(id);
48 throw new ModuleException("Objekt nicht vorhanden: ID=" + id);
51 catch (StorageObjectException e){
52 throw new ModuleException(e.toString());
57 * Holt eine EntityListe anhand des WhereClause via StorageObject
58 * @param String whereclause
59 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
60 * @return EntityList Liste der gematchten Datensätze
62 public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException {
64 if (theStorage == null)
65 throw new ModuleException("Kein StorageObject gesetzt");
66 theLog = Logfile.getInstance(MirConfig.getProp("Home") + "log/media.log");
67 theLog.printError("aboot to run getByWhere...");
68 return theStorage.selectByWhereClause(whereClause, offset);
70 catch (StorageObjectException e){
71 throw new ModuleException(e.toString());
76 * Holt eine EntityListe anhand des WhereClause aus dem StorageObject
77 * @param String where WhereClause
78 * @param String order Sortierreihenfolge
79 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
80 * @return EntityList Liste der gematchten Datensätze
82 public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException {
84 if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt");
85 return theStorage.selectByWhereClause(where, order, offset);
87 catch (StorageObjectException e){
88 throw new ModuleException(e.toString());
92 * Executes a where clause on the StorageObject with order criteria
93 * fetching from offset the number of limit objects
102 public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException
105 if (theStorage==null) throw new ModuleException("StorageObject not set!");
106 return theStorage.selectByWhereClause(where, order, offset, limit);
108 catch (StorageObjectException e){
109 throw new ModuleException(e.toString());
114 * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject
115 * @param String aField - Feldname im StorageObject
116 * @param String aValue - Wert in Feld im StorageObject
117 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
118 * @return EntityList Liste der gematchten Datensätze
120 public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException {
122 whereClause = aField + " like '%" + aValue + "%'";
123 return getByWhereClause(whereClause, offset);
127 * Standardfunktion, um einen Datensatz via StorageObject einzufügen
128 * @param theValues Hash mit Spalte/Wert-Paaren
129 * @return Id des eingefügten Objekts
130 * @exception ModuleException
132 public String add (HashMap theValues) throws ModuleException {
134 Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
135 theEntity.setStorage(theStorage);
136 theEntity.setValues(theValues);
137 return theEntity.insert();
138 } catch (Exception e) {
139 throw new ModuleException(e.toString());
144 * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
145 * @param theValues Hash mit Spalte/Wert-Paaren
146 * @return Id des eingefügten Objekts
147 * @exception ModuleException
149 public String set (HashMap theValues) throws ModuleException {
151 Entity theEntity = theStorage.selectById((String)theValues.get("id"));
152 if (theEntity == null)
153 throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
154 theEntity.setValues(theValues);
156 return theEntity.getId();
158 catch (StorageObjectException e){
159 e.printStackTrace(System.err);
160 throw new ModuleException(e.toString());
165 * Löscht einen Datensatz anhand seiner Id
167 * @exception ModuleException
169 public void deleteById (String idParam) throws ModuleException {
171 theStorage.delete(idParam);
172 } catch (StorageObjectException e){
173 throw new ModuleException(e.toString());
178 * Liefert den Lookuptable aller Objekte des StorageObjects
179 * @return freemarker.template.SimpleHash
181 public SimpleHash getHashData() {
182 return theStorage.getHashData();
186 * returns the number of rows
188 public int getSize(String where)
189 throws SQLException,StorageObjectException {
190 return theStorage.getSize(where);