2 * put your module comment here
10 import freemarker.template.*;
17 * This class provides the base functionality for the derived Module-Classes.
18 * These classes should provide methods to make more or less complex actions
19 * on Database and Entity classes. The modules are used by ServletModules.
20 * Future possibility could be access via Applications.
22 * Abstrakte Klasse, von denen die Modules die Basisfunktionalität erben.
23 * Die Moduleschicht dient dazu, Funktionalitaeten zur Verfügung zu stellen,
24 * die von mehreren ServletModulen verwendet werden.
28 public class AbstractModule {
29 protected StorageObject theStorage;
31 public void setStorage(StorageObject storage) {
32 this.theStorage = storage;
36 * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist.
37 * @return Standard-StorageObject
39 public StorageObject getStorageObject () {
44 * Holt eine Entity anhand der Id via StorageObject
45 * @param String der Entity
48 public Entity getById (String id) throws ModuleException {
50 if (theStorage == null)
51 throw new ModuleException("No StorageObject set!");
52 Entity entity = (Entity)theStorage.selectById(id);
54 throw new ModuleException("No object for id = " + id);
57 catch (StorageObjectException e){
58 throw new ModuleException(e.toString());
63 * Holt eine EntityListe anhand des WhereClause via StorageObject
64 * @param String whereclause
65 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
66 * @return EntityList Liste der gematchten Datensätze
68 public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException {
70 if (theStorage == null)
71 throw new ModuleException("Kein StorageObject gesetzt");
72 return theStorage.selectByWhereClause(whereClause, offset);
74 catch (StorageObjectException e){
75 throw new ModuleException(e.toString());
80 * Holt eine EntityListe anhand des WhereClause aus dem StorageObject
81 * @param String where WhereClause
82 * @param String order Sortierreihenfolge
83 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
84 * @return EntityList Liste der gematchten Datensätze
86 public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException {
88 if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt");
89 return theStorage.selectByWhereClause(where, order, offset);
91 catch (StorageObjectException e){
92 throw new ModuleException(e.toString());
96 * Executes a where clause on the StorageObject with order criteria
97 * fetching from offset the number of limit objects
100 * @param String order
106 public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException
109 if (theStorage==null) throw new ModuleException("StorageObject not set!");
110 return theStorage.selectByWhereClause(where, order, offset, limit);
112 catch (StorageObjectException e){
113 throw new ModuleException(e.toString());
118 * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject
119 * @param String aField - Feldname im StorageObject
120 * @param String aValue - Wert in Feld im StorageObject
121 * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
122 * @return EntityList Liste der gematchten Datensätze
124 public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException {
126 whereClause = aField + " like '%" + aValue + "%'";
127 return getByWhereClause(whereClause, offset);
131 * Standardfunktion, um einen Datensatz via StorageObject einzufügen
132 * @param theValues Hash mit Spalte/Wert-Paaren
133 * @return Id des eingefügten Objekts
134 * @exception ModuleException
136 public String add (HashMap theValues) throws ModuleException {
138 Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
139 theEntity.setStorage(theStorage);
140 theEntity.setValues(theValues);
141 return theEntity.insert();
142 } catch (Exception e) {
143 throw new ModuleException(e.toString());
148 * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
149 * @param theValues Hash mit Spalte/Wert-Paaren
150 * @return Id des eingefügten Objekts
151 * @exception ModuleException
153 public String set (HashMap theValues) throws ModuleException {
155 Entity theEntity = theStorage.selectById((String)theValues.get("id"));
156 if (theEntity == null)
157 throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
158 theEntity.setValues(theValues);
160 return theEntity.getId();
162 catch (StorageObjectException e){
163 e.printStackTrace(System.err);
164 throw new ModuleException(e.toString());
169 * Löscht einen Datensatz anhand seiner Id
171 * @exception ModuleException
173 public void deleteById (String idParam) throws ModuleException {
175 theStorage.delete(idParam);
176 } catch (StorageObjectException e){
177 throw new ModuleException(e.toString());
182 * Liefert den Lookuptable aller Objekte des StorageObjects
183 * @return freemarker.template.SimpleHash
185 public SimpleHash getHashData() {
186 return theStorage.getHashData();
190 * returns the number of rows
192 public int getSize(String where)
193 throws SQLException,StorageObjectException {
194 return theStorage.getSize(where);