1.1 restoration
[mir.git] / source / mir / module / AbstractModule.java
index 7d0c5c5..aea424b 100755 (executable)
  */
 package  mir.module;
 
-import java.util.Map;\r
-\r
-import mir.entity.Entity;\r
-import mir.entity.EntityList;\r
+import java.util.Map;
+import java.sql.SQLException;
+
+import mir.entity.Entity;
+import mir.entity.EntityList;
 import mir.storage.StorageObject;
 
 
@@ -49,30 +50,24 @@ import mir.storage.StorageObject;
  */
 
 public class AbstractModule {
-  protected StorageObject theStorage;
+  protected StorageObject storage;
 
-  public void setStorage(StorageObject storage) {
-    this.theStorage = storage;
+  public AbstractModule(StorageObject aStorageObject) {
+    storage = aStorageObject;
   }
 
   /**
-   * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist.
-   * @return Standard-StorageObject
+   * Returns the storage object associated with this module
    */
   public StorageObject getStorageObject () {
-    return theStorage;
+    return storage;
   }
 
-  /**
-   *   Holt eine Entity anhand der Id via StorageObject
-   *   @param String der Entity
-   *   @return Entity
-   */
   public Entity getById (String id) throws ModuleExc, ModuleFailure {
     try {
-      if (theStorage == null)
+      if (storage == null)
         throw  new ModuleExc("AbstractModule.getById: No StorageObject set!");
-      Entity entity = (Entity)theStorage.selectById(id);
+      Entity entity = storage.selectById(id);
 
       if (entity == null)
         throw new ModuleExc("AbstractModule.getById: No object for id = " + id);
@@ -84,18 +79,12 @@ public class AbstractModule {
     }
   }
 
-  /**
-   *   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
-   */
   public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure {
     try {
-      if (theStorage == null)
+      if (storage == null)
         throw  new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!");
 
-      return theStorage.selectByWhereClause(whereClause, offset);
+      return storage.selectByWhereClause(whereClause, offset);
     }
     catch (Throwable e) {
       throw new ModuleFailure(e);
@@ -103,60 +92,6 @@ public class AbstractModule {
   }
 
   /**
-   *   Holt eine EntityListe anhand des WhereClause aus dem StorageObject
-   *   @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
-   */
-  public EntityList getByWhereClause (String where, String order, int offset) throws ModuleExc, ModuleFailure {
-    try {
-      if (theStorage==null)
-        throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!");
-
-      return theStorage.selectByWhereClause(where, order, offset);
-    }
-    catch (Throwable e) {
-      throw new ModuleFailure(e);
-    }
-  }
-  /**
-   *   Executes a where clause on the StorageObject with order criteria
-   *   fetching from offset the number of limit objects
-   *
-   *   @param String where
-   *   @param String order
-   *   @param int offset
-   *   @param int limit
-   *   @return EntityList
-   */
-
-  public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleExc, ModuleFailure   {
-    try {
-      if (theStorage==null)
-        throw new ModuleExc("AbstractModule.getByWhereClause: StorageObject not set!");
-
-      return theStorage.selectByWhereClause(where, order, offset, limit);
-    }
-    catch (Throwable e) {
-      throw new ModuleFailure(e);
-    }
-  }
-
-  /**
-   *   Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject
-   *   @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
-   */
-  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
    * @param theValues Hash mit Spalte/Wert-Paaren
    * @return Id des eingef?gten Objekts
@@ -165,9 +100,9 @@ public class AbstractModule {
    */
   public String add (Map theValues) throws ModuleExc, ModuleFailure {
     try {
-      Entity theEntity = (Entity)theStorage.getEntityClass().newInstance();
-      theEntity.setStorage(theStorage);
-      theEntity.setValues(theValues);
+      Entity theEntity = (Entity)storage.getEntityClass().newInstance();
+      theEntity.setStorage(storage);
+      theEntity.setFieldValues(theValues);
       return theEntity.insert();
     }
     catch (Throwable e) {
@@ -177,16 +112,11 @@ public class AbstractModule {
 
   /**
    * This function creates an Entity without yet storing it in the database
-   *
-   * @param theValues
-   * @return
-   * @throws ModuleExc
-   * @throws ModuleFailure
    */
   public Entity createNew() throws ModuleExc, ModuleFailure {
     try {
-      Entity result = (Entity)theStorage.getEntityClass().newInstance();
-      result.setStorage(theStorage);
+      Entity result = (Entity)storage.getEntityClass().newInstance();
+      result.setStorage(storage);
 
       return result;
     }
@@ -204,10 +134,10 @@ public class AbstractModule {
    */
   public String set (Map theValues) throws ModuleExc, ModuleFailure {
     try {
-      Entity theEntity = theStorage.selectById((String)theValues.get("id"));
+      Entity theEntity = storage.selectById((String)theValues.get("id"));
       if (theEntity == null)
         throw new ModuleExc("No object found with id " + theValues.get("id"));
-      theEntity.setValues(theValues);
+      theEntity.setFieldValues(theValues);
       theEntity.update();
       return theEntity.getId();
     }
@@ -224,7 +154,7 @@ public class AbstractModule {
    */
   public void deleteById (String idParam) throws ModuleExc, ModuleFailure {
     try {
-      theStorage.delete(idParam);
+      storage.delete(idParam);
     }
     catch (Throwable e) {
       throw new ModuleFailure(e);
@@ -236,10 +166,10 @@ public class AbstractModule {
    */
   public int getSize(String where) throws ModuleExc, ModuleFailure {
     try {
-      return theStorage.getSize(where);
+      return storage.getSize(where);
     }
-    catch (Throwable e) {
-      throw new ModuleFailure(e);
+    catch (SQLException e) {
+      throw new ModuleFailure("Can't retrieve number of entities: " + e.toString(), e);
     }
   }