X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmodule%2FAbstractModule.java;h=eb4f9dab725d065ee96556c1c691019e795eb2b1;hb=e700d303f1487bd12a7e185a79dc877c21fab7e9;hp=c777715e0456abfd6ccc5b8d2f65972931dfcd51;hpb=e368bbb50c99177c97d0f3c7de877accc014a4b3;p=mir.git diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index c777715e..eb4f9dab 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2001, 2002 The Mir-coders group * * This file is part of Mir. * @@ -18,29 +18,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with the com.oreilly.servlet library, any library - * licensed under the Apache Software License, The Sun (tm) Java Advanced - * Imaging library (JAI), The Sun JIMI library (or with modified versions of - * the above that use the same license as the above), and distribute linked - * combinations including the two. You must obey the GNU General Public - * License in all respects for all of the code used other than the above - * mentioned libraries. If you modify this file, you may extend this exception - * to your version of the file, but you are not obligated to do so. If you do - * not wish to do so, delete this exception statement from your version. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. + * If you do not wish to do so, delete this exception statement from your version. */ - package mir.module; -import java.sql.SQLException; -import java.util.HashMap; - import mir.entity.Entity; import mir.entity.EntityList; -import mir.storage.StorageObject; -import mir.storage.StorageObjectExc; -import mir.storage.StorageObjectFailure; -import freemarker.template.SimpleHash; +import mir.storage.Database; +import java.util.Map; /** * This class provides the base functionality for the derived Module-Classes. @@ -55,172 +48,84 @@ import freemarker.template.SimpleHash; */ public class AbstractModule { - protected StorageObject theStorage; + protected Database database; - public void setStorage(StorageObject storage) { - this.theStorage = storage; + public AbstractModule(Database aDatabase) { + database = aDatabase; } /** - * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist. - * @return Standard-StorageObject + * Returns the database object associated with this module */ - public StorageObject getStorageObject () { - return theStorage; + public Database getStorageObject () { + return database; } - /** - * Holt eine Entity anhand der Id via StorageObject - * @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!"); - Entity entity = (Entity)theStorage.selectById(id); + if (database == null) + throw new ModuleExc("AbstractModule.getById: No Database set!"); + Entity entity = database.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); + return entity; } - catch (StorageObjectExc 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 - */ - 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"); - return theStorage.selectByWhereClause(whereClause, offset); - } - catch (StorageObjectFailure e){ - throw new ModuleException(e.toString()); - } - } + if (database == null) + throw new ModuleExc("AbstractModule.getByWhereClause: No Database set!"); - /** - * 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 ModuleException { - try { - if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt"); - return theStorage.selectByWhereClause(where, order, offset); + return database.selectByWhereClause(whereClause, offset); } - catch (StorageObjectFailure e){ - throw new ModuleException(e.toString()); + 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 ModuleException - { + public String add(Map theValues) throws ModuleExc, ModuleFailure { try { - if (theStorage==null) throw new ModuleException("StorageObject not set!"); - return theStorage.selectByWhereClause(where, order, offset, limit); - } - catch (StorageObjectFailure e){ - throw new ModuleException(e.toString()); - } - } - - /** - * 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 ModuleException { - String whereClause; - whereClause = aField + " like '%" + aValue + "%'"; - return getByWhereClause(whereClause, offset); - } + Entity entity = database.createNewEntity(); + entity.setFieldValues(theValues); - /** - * Standardfunktion, um einen Datensatz via StorageObject einzuf?gen - * @param theValues Hash mit Spalte/Wert-Paaren - * @return Id des eingef?gten Objekts - * @exception ModuleException - */ - public String add (HashMap theValues) throws ModuleException { - try { - Entity theEntity = (Entity)theStorage.getEntityClass().newInstance(); - theEntity.setStorage(theStorage); - theEntity.setValues(theValues); - return theEntity.insert(); - } catch (Exception e) { - throw new ModuleException(e.toString()); + return entity.insert(); + } + 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 - */ - public String set (HashMap theValues) throws ModuleException { + public String set (Map theValues) throws ModuleExc, ModuleFailure { try { - Entity theEntity = theStorage.selectById((String)theValues.get("id")); + Entity theEntity = database.selectById((String) theValues.get("id")); if (theEntity == null) - throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id")); - theEntity.setValues(theValues); + throw new ModuleExc("No object found with id " + theValues.get("id")); + theEntity.setFieldValues(theValues); theEntity.update(); return theEntity.getId(); } - catch (StorageObjectExc 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 (StorageObjectFailure e){ - throw new ModuleException(e.toString()); + database.delete(idParam); + } + catch (Throwable e) { + throw new ModuleFailure(e); } } - - /** - * Liefert den Lookuptable aller Objekte des StorageObjects - * @return freemarker.template.SimpleHash - */ - public SimpleHash getHashData() { - return theStorage.getHashData(); - } - - /** - * returns the number of rows - */ - public int getSize(String where) - throws SQLException,StorageObjectFailure { - return theStorage.getSize(where); - } - }