X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fentity%2FEntity.java;h=5a69e3e2915ec047dfb2f6489aa3e236dcdbdf62;hb=e368bbb50c99177c97d0f3c7de877accc014a4b3;hp=b434b771161328be7be668e5d84230beb87018ad;hpb=79e18a4b9e29f1fb16fb804496d34b444930fdaf;p=mir.git diff --git a/source/mir/entity/Entity.java b/source/mir/entity/Entity.java index b434b771..5a69e3e2 100755 --- a/source/mir/entity/Entity.java +++ b/source/mir/entity/Entity.java @@ -1,56 +1,90 @@ +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * 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. + */ + /** * Base class the entities are derived from. Provides base functionality of * an entity. Entities are used to represent rows of a database table.

*/ - package mir.entity; -import java.lang.*; -import java.io.*; -import java.util.*; -import java.sql.*; - -import freemarker.template.*; - -import mir.storage.*; -import mir.misc.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.misc.Logfile; +import mir.misc.StringUtil; +import mir.storage.StorageObject; +import mir.storage.StorageObjectExc; +import mir.storage.StorageObjectFailure; +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateHashModel; +import freemarker.template.TemplateModel; +import freemarker.template.TemplateModelException; +import freemarker.template.TemplateModelRoot; /** * Base Class of Entities * Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant * - * @version $Revision: 1.8 $ $Date: 2002/06/28 22:56:37 $ - * @author $Author: mh $ - * - * $Log: Entity.java,v $ - * Revision 1.8 2002/06/28 22:56:37 mh - * fix so that webdb_lastchange appears in contentlist.template as it should - * - * Revision 1.7 2002/06/28 20:35:38 mh - * use some cvs macros/id's - * + * @version $Id: Entity.java,v 1.13 2003/01/25 17:45:17 idfx Exp $ + * @author rk * */ public class Entity implements TemplateHashModel, TemplateModelRoot { + protected static MirPropertiesConfiguration configuration; + protected static Logfile theLog; + private boolean changed; protected HashMap theValuesHash; // tablekey / value protected StorageObject theStorageObject; - protected static Logfile theLog; protected ArrayList streamedInput=null; - private static int instances = 0; - static { - theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Entity.Logfile")); + + + static { + try { + configuration = MirPropertiesConfiguration.instance(); + } catch (PropertiesConfigExc e) { + e.printStackTrace(); + } + theLog = Logfile.getInstance(configuration.getStringWithHome("Entity.Logfile")); } public Entity() { - this.changed = false; - instances++; - Integer i = new Integer(instances); - //System.err.println("New abstract entity instance: "+i.toString()); } /** @@ -104,7 +138,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return String Id */ public String getId () { - return (String)getValue(theStorageObject.getIdName()); + return (String) getValue(theStorageObject.getIdName()); } /** @@ -134,11 +168,6 @@ public class Entity implements TemplateHashModel, TemplateModelRoot if (hasValueForField("webdb_lastchange")) returnValue=StringUtil.dateToReadableDate(getValue("webdb_lastchange")); } - else if (field.equals("webdb_create_dc")) - { - if (hasValueForField("webdb_create")) - returnValue=StringUtil.webdbdateToDCDate(getValue("webdb_create")); - } else returnValue = (String)theValuesHash.get(field); } @@ -157,20 +186,20 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return Primary Key of the Entity * @exception StorageObjectException */ - public String insert () throws StorageObjectException { + public String insert () throws StorageObjectExc { theLog.printDebugInfo("Entity: trying to insert ..."); if (theStorageObject != null) { return theStorageObject.insert((Entity)this); } else - throw new StorageObjectException("Kein StorageObject gesetzt!"); + throw new StorageObjectExc("Kein StorageObject gesetzt!"); } /** * Saves changes of this Entity to the database * @exception StorageObjectException */ - public void update () throws StorageObjectException { + public void update () throws StorageObjectFailure { theStorageObject.update((Entity)this); } @@ -182,7 +211,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @exception StorageObjectException */ public void setValueForProperty (String theProp, String theValue) - throws StorageObjectException { + throws StorageObjectFailure { this.changed = true; if (isField(theProp)) theValuesHash.put(theProp, theValue); @@ -197,7 +226,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return ArrayList with field names * @exception StorageObjectException is throuwn if database access was impossible */ - public ArrayList getFields () throws StorageObjectException { + public ArrayList getFields () throws StorageObjectFailure { return theStorageObject.getFields(); } @@ -206,7 +235,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return int[] that contains the types of the fields * @exception StorageObjectException */ - public int[] getTypes () throws StorageObjectException { + public int[] getTypes () throws StorageObjectFailure { return theStorageObject.getTypes(); } @@ -215,7 +244,7 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return List with field names * @exception StorageObjectException */ - public ArrayList getLabels () throws StorageObjectException { + public ArrayList getLabels () throws StorageObjectFailure { return theStorageObject.getLabels(); } @@ -254,37 +283,19 @@ public class Entity implements TemplateHashModel, TemplateModelRoot * @return true in case fieldName is a field name, else false. * @exception StorageObjectException */ - public boolean isField (String fieldName) throws StorageObjectException { + public boolean isField (String fieldName) throws StorageObjectFailure { return theStorageObject.getFields().contains(fieldName); } - /** Returns the number of instances of this Entity - * @return int The number of instances - */ - public int getInstances() { - return instances; - } - protected void throwStorageObjectException (Exception e, String wo) throws StorageObjectException { + + protected void throwStorageObjectFailure (Exception e, String wo) + throws StorageObjectFailure { theLog.printError( e.toString() + " Funktion: "+ wo); - throw new StorageObjectException("Storage Object Exception in entity" +e.toString()); + e.printStackTrace(System.out); + throw new StorageObjectFailure("Storage Object Exception in entity", e); } - /** - * Frees an instance - */ - /*public void finalize () { - instances--; - Integer i = new Integer(instances); - System.err.println("Removing abstract entity instance: "+i.toString()); - try { - super.finalize(); - } catch (Throwable t) { - System.err.println(t.toString()); - } - }*/ - - // Now implements freemarkers TemplateHashModel // two methods have to be overridden: // 1. public boolean isEmpty() throws TemplateModelException @@ -297,10 +308,10 @@ public class Entity implements TemplateHashModel, TemplateModelRoot public TemplateModel get(java.lang.String key) throws TemplateModelException { - return new SimpleScalar(getValue(key)); + return new SimpleScalar(getValue(key)); } - - public void put(java.lang.String key, TemplateModel model) + + public void put(java.lang.String key, TemplateModel model) { // putting should only take place via setValue and is limited to the // database fields associated with the entity. no additional freemarker