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;
24 public void setStorage(StorageObject storage) {
25 this.theStorage = storage;
29 * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist.
30 * @return Standard-StorageObject
32 public StorageObject getStorageObject () {
37 * Holt eine Entity anhand der Id via StorageObject
38 * @param String der Entity
41 public Entity getById (String id) throws ModuleException {
43 if (theStorage == null)
44 throw new ModuleException("Kein StorageObject gesetzt");
45 Entity entity = (Entity)theStorage.selectById(id);
47 throw new ModuleException("Objekt nicht vorhanden: ID=" + id);
50 catch (StorageObjectException e){
51 throw new ModuleException(e.toString());
56 * Holt eine EntityListe anhand des WhereClause via StorageObject
57 * @param String whereclause
58 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
59 * @return EntityList Liste der gematchten Datensätze
61 public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException {
63 if (theStorage == null)
64 throw new ModuleException("Kein StorageObject gesetzt");
65 return theStorage.selectByWhereClause(whereClause, offset);
67 catch (StorageObjectException e){
68 throw new ModuleException(e.toString());
73 * Holt eine EntityListe anhand des WhereClause aus dem StorageObject
74 * @param String where WhereClause
75 * @param String order Sortierreihenfolge
76 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
77 * @return EntityList Liste der gematchten Datensätze
79 public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException {
81 if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt");
82 return theStorage.selectByWhereClause(where, order, offset);
84 catch (StorageObjectException e){
85 throw new ModuleException(e.toString());
89 * Executes a where clause on the StorageObject with order criteria
90 * fetching from offset the number of limit objects
99 public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException
102 if (theStorage==null) throw new ModuleException("StorageObject not set!");
103 return theStorage.selectByWhereClause(where, order, offset, limit);
105 catch (StorageObjectException e){
106 throw new ModuleException(e.toString());
111 * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject
112 * @param String aField - Feldname im StorageObject
113 * @param String aValue - Wert in Feld im StorageObject
114 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
115 * @return EntityList Liste der gematchten Datensätze
117 public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException {
119 whereClause = aField + " like '%" + aValue + "%'";
120 return getByWhereClause(whereClause, offset);
124 * Standardfunktion, um einen Datensatz via StorageObject einzufügen
125 * @param theValues Hash mit Spalte/Wert-Paaren
126 * @return Id des eingefügten Objekts
127 * @exception ModuleException
129 public String add (HashMap theValues) throws ModuleException {
131 Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
132 theEntity.setStorage(theStorage);
133 theEntity.setValues(theValues);
134 return theEntity.insert();
135 } catch (Exception e) {
136 throw new ModuleException(e.toString());
141 * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
142 * @param theValues Hash mit Spalte/Wert-Paaren
143 * @return Id des eingefügten Objekts
144 * @exception ModuleException
146 public String set (HashMap theValues) throws ModuleException {
148 Entity theEntity = theStorage.selectById((String)theValues.get("id"));
149 if (theEntity == null)
150 throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
151 theEntity.setValues(theValues);
153 return theEntity.getId();
155 catch (StorageObjectException e){
156 e.printStackTrace(System.err);
157 throw new ModuleException(e.toString());
162 * Löscht einen Datensatz anhand seiner Id
164 * @exception ModuleException
166 public void deleteById (String idParam) throws ModuleException {
168 theStorage.delete(idParam);
169 } catch (StorageObjectException e){
170 throw new ModuleException(e.toString());
175 * Liefert den Lookuptable aller Objekte des StorageObjects
176 * @return freemarker.template.SimpleHash
178 public SimpleHash getHashData() {
179 return theStorage.getHashData();
183 * returns the number of rows
185 public int getSize(String where)
186 throws SQLException,StorageObjectException {
187 return theStorage.getSize(where);