/*
- * Copyright (C) 2001, 2002 The Mir-coders group
+ * Copyright (C) 2001-2006 The Mir-coders group
*
* This file is part of Mir.
*
*
* 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.producer;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
import mir.entity.Entity;
import mir.entity.adapter.EntityAdapter;
import mir.entity.adapter.EntityAdapterModel;
import mir.log.LoggerWrapper;
+import mir.util.JDBCStringRoutines;
import mir.util.ParameterExpander;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
-public class EntityModifyingProducerNode implements ProducerNode {
+
+public class EntityModifyingProducerNode extends AbstractProducerNode {
private String entityExpression;
private String definition;
private Map fields;
Object value = ParameterExpander.evaluateExpression(aValueMap, valueExpression);
if (value instanceof String)
- entity.setValueForProperty(entityField, (String) value);
+ entity.setFieldValue(entityField, (String) value);
else if (value instanceof EntityAdapter)
- entity.setValueForProperty(entityField, ((EntityAdapter) value).getEntity().getId());
+ entity.setFieldValue(entityField, ((EntityAdapter) value).getEntity().getId());
+ else if (value instanceof Date) {
+ entity.setFieldValue(entityField, JDBCStringRoutines.formatDate((Date) value));
+ }
else
- aLogger.warn("Can't set value " + value.toString() + " for field " + entityField);
+ aLogger.warn("Can't set value " + value + " for field " + entityField);
}
- entity.update();
+
+ if (create)
+ entity.insert();
+ else
+ entity.update();
}
else
throw new ProducerExc( entityExpression + " does not evaluate to an entity");
}
catch (Throwable t) {
- aLogger.error("Error while performing entity modification operation: " + t.getMessage());
+ aLogger.error("Error while performing entity modification operation: " + t.getMessage(), t);
throw new ProducerFailure(t.getMessage(), t);
}