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 return theStorage.selectByWhereClause(whereClause, offset);
68 catch (StorageObjectException e){
69 throw new ModuleException(e.toString());
74 * Holt eine EntityListe anhand des WhereClause aus dem StorageObject
75 * @param String where WhereClause
76 * @param String order Sortierreihenfolge
77 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
78 * @return EntityList Liste der gematchten Datensätze
80 public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException {
82 if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt");
83 return theStorage.selectByWhereClause(where, order, offset);
85 catch (StorageObjectException e){
86 throw new ModuleException(e.toString());
90 * Executes a where clause on the StorageObject with order criteria
91 * fetching from offset the number of limit objects
100 public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException
103 if (theStorage==null) throw new ModuleException("StorageObject not set!");
104 return theStorage.selectByWhereClause(where, order, offset, limit);
106 catch (StorageObjectException e){
107 throw new ModuleException(e.toString());
112 * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject
113 * @param String aField - Feldname im StorageObject
114 * @param String aValue - Wert in Feld im StorageObject
115 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
116 * @return EntityList Liste der gematchten Datensätze
118 public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException {
120 whereClause = aField + " like '%" + aValue + "%'";
121 return getByWhereClause(whereClause, offset);
125 * Standardfunktion, um einen Datensatz via StorageObject einzufügen
126 * @param theValues Hash mit Spalte/Wert-Paaren
127 * @return Id des eingefügten Objekts
128 * @exception ModuleException
130 public String add (HashMap theValues) throws ModuleException {
132 Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
133 theEntity.setStorage(theStorage);
134 theEntity.setValues(theValues);
135 return theEntity.insert();
136 } catch (Exception e) {
137 throw new ModuleException(e.toString());
142 * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
143 * @param theValues Hash mit Spalte/Wert-Paaren
144 * @return Id des eingefügten Objekts
145 * @exception ModuleException
147 public String set (HashMap theValues) throws ModuleException {
149 Entity theEntity = theStorage.selectById((String)theValues.get("id"));
150 if (theEntity == null)
151 throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
152 theEntity.setValues(theValues);
154 return theEntity.getId();
156 catch (StorageObjectException e){
157 e.printStackTrace(System.err);
158 throw new ModuleException(e.toString());
163 * Löscht einen Datensatz anhand seiner Id
165 * @exception ModuleException
167 public void deleteById (String idParam) throws ModuleException {
169 theStorage.delete(idParam);
170 } catch (StorageObjectException e){
171 throw new ModuleException(e.toString());
176 * Liefert den Lookuptable aller Objekte des StorageObjects
177 * @return freemarker.template.SimpleHash
179 public SimpleHash getHashData() {
180 return theStorage.getHashData();
184 * returns the number of rows
186 public int getSize(String where)
187 throws SQLException,StorageObjectException {
188 return theStorage.getSize(where);