X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmodule%2FAbstractModule.java;fp=source%2Fmir%2Fmodule%2FAbstractModule.java;h=d65dd2b331c920ad328463e71549c709a002dda0;hb=c9ac8fa71b679f8d967aac901bbef945c13b94c9;hp=aea424ba99c97b034b985cbe1543970b875ec860;hpb=d63595f89aaa4b6a524dc0b4af9e0eef888f4c6b;p=mir.git diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index aea424ba..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,23 +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; -import java.sql.SQLException; +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. @@ -50,91 +48,65 @@ import mir.storage.StorageObject; */ public class AbstractModule { - protected StorageObject storage; + protected Database database; - public AbstractModule(StorageObject aStorageObject) { - storage = aStorageObject; + public AbstractModule(Database aDatabase) { + database = aDatabase; } /** - * Returns the storage object associated with this module + * Returns the database object associated with this module */ - public StorageObject getStorageObject () { - return storage; + public Database getStorageObject () { + return database; } - public Entity getById (String id) throws ModuleExc, ModuleFailure { - try { - if (storage == null) - throw new ModuleExc("AbstractModule.getById: No StorageObject set!"); - Entity entity = storage.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 Entity getById (String anId) throws ModuleFailure, EntityNotFoundExc { + if (database == null) { + throw new ModuleFailure("AbstractModule.getById: No Database set!"); + } - public EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure { - try { - if (storage == null) - throw new ModuleExc("AbstractModule.getByWhereClause: No StorageObject set!"); + try { + Entity result = database.selectById(anId); - return storage.selectByWhereClause(whereClause, offset); - } - catch (Throwable e) { - throw new ModuleFailure(e); - } + if (result == null) { + throw new EntityNotFoundExc("AbstractModule.getById: No object for id = " + anId); + } + + return result; + } + catch (DatabaseExc e) { + throw new ModuleFailure("Database exception while retrieving entity with id " + anId); + } } - /** - * * 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 EntityList getByWhereClause (String whereClause, int offset) throws ModuleExc, ModuleFailure { try { - Entity theEntity = (Entity)storage.getEntityClass().newInstance(); - theEntity.setStorage(storage); - theEntity.setFieldValues(theValues); - return theEntity.insert(); + if (database == null) + throw new ModuleExc("AbstractModule.getByWhereClause: No Database set!"); + + return database.selectByWhereClause(whereClause, offset); } catch (Throwable e) { throw new ModuleFailure(e); } } - /** - * This function creates an Entity without yet storing it in the database - */ - public Entity createNew() throws ModuleExc, ModuleFailure { + public String add(Map theValues) throws ModuleExc, ModuleFailure { try { - Entity result = (Entity)storage.getEntityClass().newInstance(); - result.setStorage(storage); + Entity entity = database.createNewEntity(); + entity.setFieldValues(theValues); - 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 = storage.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.setFieldValues(theValues); @@ -154,23 +126,10 @@ public class AbstractModule { */ public void deleteById (String idParam) throws ModuleExc, ModuleFailure { try { - storage.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 storage.getSize(where); - } - catch (SQLException e) { - throw new ModuleFailure("Can't retrieve number of entities: " + e.toString(), e); - } - } - }