import java.util.HashMap;
import java.util.List;
-import java.util.Map;
+import java.util.*;
import mir.config.MirPropertiesConfiguration;
import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
* an entity. Entities are used to represent rows of a database table.<p>
* Interfacing TemplateHashModel and TemplateModelRoot to be freemarker compliant
*
- * @version $Id: Entity.java,v 1.21.2.1 2003/05/22 03:15:07 zapata Exp $
+ * @version $Id: Entity.java,v 1.21.2.2 2003/05/22 19:45:06 zapata Exp $
* @author rk
*
*/
{
protected static MirPropertiesConfiguration configuration;
- protected Map theValuesHash; // tablekey / value
+// protected Map theValuesHash; // tablekey / value
+ protected Map values;
protected StorageObject theStorageObject;
protected List streamedInput = null;
protected LoggerWrapper logger;
public Entity() {
logger = new LoggerWrapper("Entity");
+
+ values = new HashMap();
}
/**
* Constructor
* @param StorageObject The StorageObject of the Entity.
*/
+
public Entity(StorageObject StorageObject) {
this();
+
setStorage(StorageObject);
}
- /*
- * Sets the StorageObject of the Entity.
+ /**
+ *
+ * @param storage
*/
+
public void setStorage(StorageObject storage) {
this.theStorageObject = storage;
}
/**
* Sets the values of the Entity. (Only to be called by the Storage Object)
- * @param theStringValues Map containing the new values of the Entity
+ *
+ * @param aMap Map containing the new values of the Entity
*/
- public void setValues(Map theStringValues) {
- /** @todo should be synchronized */
+ public void setValues(Map aMap) {
+ if (aMap!=null) {
+ Iterator i = aMap.entrySet().iterator();
+ logger.info("aMap = " + aMap.toString());
+
+ synchronized(this) {
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ logger.info("setting " + entry.getKey());
+
+ setValueForProperty( (String) entry.getKey(), (String) entry.getValue());
+ }
+ }
+ }
+/*
if (theStringValues != null) {
theValuesHash = new HashMap();
theValuesHash.putAll(theStringValues);
}
else
logger.warn("Entity.setValues called with null Map");
+*/
}
/**
* @param id
*/
public void setId(String id) {
+
+ setValueForProperty(theStorageObject.getIdName(), id);
+/*
theValuesHash.put(theStorageObject.getIdName(), id);
+ */
}
/**
*/
public String getValue(String field) {
String returnValue = null;
+
if (field != null) {
+/*
if (field.equals("webdb_create_formatted")) {
if (hasValueForField("webdb_create"))
returnValue = StringUtil.dateToReadableDate(getValue("webdb_create"));
returnValue = StringUtil.dateToReadableDate(getValue(
"webdb_lastchange"));
}
- else
- returnValue = (String) theValuesHash.get(field);
+ else */
+ returnValue = (String) values.get(field);
}
return returnValue;
}
public boolean hasValueForField(String field) {
- if (theValuesHash != null)
- return theValuesHash.containsKey(field);
- return false;
+ return values.containsKey(field);
}
/**
*/
public String insert() throws StorageObjectExc {
logger.debug("Entity: trying to insert ...");
+
if (theStorageObject != null) {
return theStorageObject.insert(this);
}
* @exception StorageObjectException
*/
public void setValueForProperty(String theProp, String theValue) throws StorageObjectFailure {
- if (isField(theProp))
- theValuesHash.put(theProp, theValue);
- else {
- logger.warn("Entity.setValueForProperty: Property not found: " + theProp + " (" + theValue + ")");
+ try {
+ logger.info("setting " + theProp + " to (" + theValue + ")");
+ if (isField(theProp))
+ values.put(theProp, theValue);
+ else {
+ logger.warn("Entity.setValueForProperty: Property not found: " + theProp + " (" + theValue + ")");
+ }
+ }
+ catch (Throwable t) {
+ logger.error("Entity.setValueForProperty: " + t.toString());
+ t.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE));
+
+ throw new StorageObjectFailure(t);
}
}
// 2. public TemplateModel get(java.lang.String key) throws TemplateModelException
public boolean isEmpty() throws TemplateModelException {
- return (theValuesHash == null || theValuesHash.isEmpty()) ? true : false;
+ return false;
}
public TemplateModel get(java.lang.String key) throws TemplateModelException {
}
public void remove(java.lang.String key) {
- // do we need this?
+ logger.warn("remove is called on entity!");
}
//////////////////////////////////////////////////////////////////////////////////