package mir.module;
-import java.util.*;
-import java.sql.*;
-import freemarker.template.*;
-import mir.storage.*;
-import mir.misc.*;
-import mir.entity.*;
+import java.util.Map;
+
+import mir.entity.Entity;
+import mir.entity.EntityList;
+import mir.storage.StorageObject;
+import freemarker.template.SimpleHash;
/**
* on Database and Entity classes. The modules are used by ServletModules.
* Future possibility could be access via Applications.
*
- * Abstrakte Klasse, von denen die Modules die Basisfunktionalität erben.
- * Die Moduleschicht dient dazu, Funktionalitaeten zur Verfügung zu stellen,
+ * Abstrakte Klasse, von denen die Modules die Basisfunktionalit?t erben.
+ * Die Moduleschicht dient dazu, Funktionalitaeten zur Verf?gung zu stellen,
* die von mehreren ServletModulen verwendet werden.
*
*/
}
/**
- * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist.
+ * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist.
* @return Standard-StorageObject
*/
public StorageObject getStorageObject () {
* @param String der Entity
* @return Entity
*/
- public Entity getById (String id) throws ModuleException {
+ public Entity getById (String id) throws ModuleExc, ModuleFailure {
try {
if (theStorage == null)
- throw new ModuleException("No StorageObject set!");
+ throw new ModuleExc("AbstractModule.getById: No StorageObject set!");
Entity entity = (Entity)theStorage.selectById(id);
+
if (entity == null)
- throw new ModuleException("No object for id = " + id);
- else return entity;
+ throw new ModuleExc("AbstractModule.getById: No object for id = " + id);
+ else
+ return entity;
}
- catch (StorageObjectException e){
- throw new ModuleException(e.toString());
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
* Holt eine EntityListe anhand des WhereClause via StorageObject
* @param String whereclause
* @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
- * @return EntityList Liste der gematchten Datensätze
+ * @return EntityList Liste der gematchten Datens?tze
*/
- public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException {
+ public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure {
try {
if (theStorage == null)
- throw new ModuleException("Kein StorageObject gesetzt");
+ throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!");
+
return theStorage.selectByWhereClause(whereClause, offset);
}
- catch (StorageObjectException e){
- throw new ModuleException(e.toString());
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
* @param String where WhereClause
* @param String order Sortierreihenfolge
* @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
- * @return EntityList Liste der gematchten Datensätze
+ * @return EntityList Liste der gematchten Datens?tze
*/
- public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException {
+ public EntityList getByWhereClause (String where, String order, int offset) throws ModuleExc, ModuleFailure {
try {
- if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt");
+ if (theStorage==null)
+ throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!");
+
return theStorage.selectByWhereClause(where, order, offset);
}
- catch (StorageObjectException e){
- throw new ModuleException(e.toString());
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
/**
* @return EntityList
*/
- public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException
- {
+ public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleExc, ModuleFailure {
try {
- if (theStorage==null) throw new ModuleException("StorageObject not set!");
+ if (theStorage==null)
+ throw new ModuleExc("AbstractModule.getByWhereClause: StorageObject not set!");
+
return theStorage.selectByWhereClause(where, order, offset, limit);
}
- catch (StorageObjectException e){
- throw new ModuleException(e.toString());
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
* @param String aField - Feldname im StorageObject
* @param String aValue - Wert in Feld im StorageObject
* @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden
- * @return EntityList Liste der gematchten Datensätze
+ * @return EntityList Liste der gematchten Datens?tze
*/
- public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException {
+ public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleExc, ModuleFailure {
String whereClause;
whereClause = aField + " like '%" + aValue + "%'";
return getByWhereClause(whereClause, offset);
}
/**
- * Standardfunktion, um einen Datensatz via StorageObject einzufügen
+ * * Standardfunktion, um einen Datensatz via StorageObject einzuf?gen
* @param theValues Hash mit Spalte/Wert-Paaren
- * @return Id des eingefügten Objekts
- * @exception ModuleException
+ * @return Id des eingef?gten Objekts
+ * @exception ModuleExc
+ * @exception ModuleFailure
*/
- public String add (HashMap theValues) throws ModuleException {
+ public String add (Map theValues) throws ModuleExc, ModuleFailure {
try {
Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
theEntity.setStorage(theStorage);
theEntity.setValues(theValues);
return theEntity.insert();
- } catch (Exception e) {
- throw new ModuleException(e.toString());
+ }
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
/**
* Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren
* @param theValues Hash mit Spalte/Wert-Paaren
- * @return Id des eingefügten Objekts
- * @exception ModuleException
+ * @return Id des eingef?gten Objekts
+ * @exception ModuleExc
+ * @exception ModuleFailure
*/
- public String set (HashMap theValues) throws ModuleException {
+ public String set (Map theValues) throws ModuleExc, ModuleFailure {
try {
Entity theEntity = theStorage.selectById((String)theValues.get("id"));
if (theEntity == null)
- throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id"));
+ throw new ModuleExc("No object found with id " + theValues.get("id"));
theEntity.setValues(theValues);
theEntity.update();
return theEntity.getId();
}
- catch (StorageObjectException e){
- e.printStackTrace(System.err);
- throw new ModuleException(e.toString());
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
/**
* Deletes a record using an id
* @param idParam
- * @exception ModuleException
+ * @exception ModuleExc
+ * @exception ModuleFailure
*/
- public void deleteById (String idParam) throws ModuleException {
+ public void deleteById (String idParam) throws ModuleExc, ModuleFailure {
try {
theStorage.delete(idParam);
- } catch (StorageObjectException e){
- throw new ModuleException(e.toString());
+ }
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
}
}
/**
* returns the number of rows
*/
- public int getSize(String where)
- throws SQLException,StorageObjectException {
- return theStorage.getSize(where);
+ public int getSize(String where) throws ModuleExc, ModuleFailure {
+ try {
+ return theStorage.getSize(where);
+ }
+ catch (Throwable e) {
+ throw new ModuleFailure(e);
+ }
}
}