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 $Id: Entity.java,v 1.10 2002/11/04 04:35:21 mh Exp $
+ * @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());
}
/**
* @return String Id
*/
public String getId () {
- return (String)getValue(theStorageObject.getIdName());
+ return (String) getValue(theStorageObject.getIdName());
}
/**
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);
}
* @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);
}
* @exception StorageObjectException
*/
public void setValueForProperty (String theProp, String theValue)
- throws StorageObjectException {
+ throws StorageObjectFailure {
this.changed = true;
if (isField(theProp))
theValuesHash.put(theProp, theValue);
* @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();
}
* @return int[] that contains the types of the fields
* @exception StorageObjectException
*/
- public int[] getTypes () throws StorageObjectException {
+ public int[] getTypes () throws StorageObjectFailure {
return theStorageObject.getTypes();
}
* @return List with field names
* @exception StorageObjectException
*/
- public ArrayList getLabels () throws StorageObjectException {
+ public ArrayList getLabels () throws StorageObjectFailure {
return theStorageObject.getLabels();
}
* @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
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