X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmodule%2FAbstractModule.java;h=d65dd2b331c920ad328463e71549c709a002dda0;hb=42680c1f9fe3250bcbd0f9ed5d9dee6188333b15;hp=aa9b6318dd2e869ac0d43baa9125a27b126093af;hpb=855ecf8acedb12afbab7a621b2e2c0cf45b2f98f;p=mir.git diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index aa9b6318..d65dd2b3 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-2006 The Mir-coders group * * This file is part of Mir. * @@ -19,22 +19,21 @@ * * In addition, as a special exception, The Mir-coders gives permission to link * 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.util.Map; +package mir.module; import mir.entity.Entity; import mir.entity.EntityList; -import mir.storage.StorageObject; +import mir.storage.Database; +import mir.storage.DatabaseExc; +import java.util.Map; /** * This class provides the base functionality for the derived Module-Classes. @@ -49,165 +48,68 @@ import mir.storage.StorageObject; */ public class AbstractModule { - protected StorageObject theStorage; + protected Database database; - public void setStorage(StorageObject storage) { - this.theStorage = storage; - } - - /** - * Liefert das Standard-StorageObject zur?ck, mit dem das Module assoziiert ist. - * @return Standard-StorageObject - */ - public StorageObject getStorageObject () { - return theStorage; + public AbstractModule(Database aDatabase) { + database = aDatabase; } /** - * Holt eine Entity anhand der Id via StorageObject - * @param String der Entity - * @return Entity + * Returns the database object associated with this module */ - public Entity getById (String id) throws ModuleExc, ModuleFailure { - try { - if (theStorage == null) - throw new ModuleExc("AbstractModule.getById: No StorageObject set!"); - Entity entity = (Entity)theStorage.selectById(id); - - if (entity == null) - throw new ModuleExc("AbstractModule.getById: No object for id = " + id); - else - return entity; - } - catch (Throwable e) { - throw new ModuleFailure(e); - } + public Database getStorageObject () { + return database; } - /** - * 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) - throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); + public Entity getById (String anId) throws ModuleFailure, EntityNotFoundExc { + if (database == null) { + throw new ModuleFailure("AbstractModule.getById: No Database set!"); + } - return theStorage.selectByWhereClause(whereClause, offset); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } + try { + Entity result = database.selectById(anId); - /** - * 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!"); + if (result == null) { + throw new EntityNotFoundExc("AbstractModule.getById: No object for id = " + anId); + } - return theStorage.selectByWhereClause(where, order, offset); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } + return result; + } + catch (DatabaseExc e) { + throw new ModuleFailure("Database exception while retrieving entity with id " + anId); + } } - /** - * 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 { + public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure { try { - if (theStorage==null) - throw new ModuleExc("AbstractModule.getByWhereClause: StorageObject not set!"); + if (database == null) + throw new ModuleExc("AbstractModule.getByWhereClause: No Database set!"); - return theStorage.selectByWhereClause(where, order, offset, limit); + return database.selectByWhereClause(whereClause, offset); } 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 - * @exception ModuleExc - * @exception ModuleFailure - */ - public String add (Map theValues) throws ModuleExc, ModuleFailure { + 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 (Throwable e) { - throw new ModuleFailure(e); - } - } + Entity entity = database.createNewEntity(); + entity.setFieldValues(theValues); - /** - * 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); - - return result; + 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 ModuleExc - * @exception ModuleFailure - */ 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 ModuleExc("No object found with id " + theValues.get("id")); - theEntity.setValues(theValues); + theEntity.setFieldValues(theValues); theEntity.update(); return theEntity.getId(); } @@ -224,23 +126,10 @@ public class AbstractModule { */ public void deleteById (String idParam) throws ModuleExc, ModuleFailure { try { - theStorage.delete(idParam); + database.delete(idParam); } catch (Throwable e) { throw new ModuleFailure(e); } } - - /** - * returns the number of rows - */ - public int getSize(String where) throws ModuleExc, ModuleFailure { - try { - return theStorage.getSize(where); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } - } - }