I've done some more searching myself ... and am completely confused
about MMObjectNode.java, and particularly the 'setValue()' method.
Please see inline comments...
quoted from MMObjectNode.java (1.7)
/**
* Sets a key/value pair in the main values of this node.
* Note that if this node is a node in cache, the changes are immediately
visible to
* everyone, even if the changes are not committed.
* The fieldName is added to the (public) 'changed' vector to track
changes.
* @param fieldName the name of the field to change
* @param fieldValue the value to assign
* @return <code>true</code> When the field was changed, false otherwise.
*/
public boolean setValue(String fieldName, Object fieldValue) {
// check the value also when the parent thing is null
Object originalValue = values.get(fieldName);
// if we have an XML-dbtype field, we always have to store it inside an
Element.
if(parent != null && getDBType(fieldName) == FieldDefs.TYPE_XML &&
!(fieldValue instanceof Document)) {
log.debug("im called far too often");
if (fieldValue == null &&
parent.getField(fieldName).getDBNotNull()) {
throw new RuntimeException("field with name '" + fieldName + "' may
not be null");
}
String value = Casting.toString(fieldValue);
value = value.trim();
if(value.length()==0 && parent.getField(fieldName).getDBNotNull()) {
throw new RuntimeException("field with name '" + fieldName + "' may
not be empty");
}
Document doc = toXML(value, fieldName);
if(doc != null) {
// store the document inside the field.. much faster...
fieldValue = doc;
}
}
if (log.isDebugEnabled()) {
log.debug("Setting " + fieldName + " to " +
Casting.toString(fieldValue));
}
// put the key/value in the value hashtable
storeValue(fieldName, fieldValue);
Why store the value already without waiting what the parent (builder)
will return?
// process the changed value (?)
if (parent != null) {
if(!parent.setValue(this, fieldName, originalValue)) {
// setValue of parent returned false, no update needed...
return false;
ok in this case: the value has been stored so the next call to
values.get(fieldName) will return the new value even though the
parent.setValue returned false. And no setUpdate has been called. This
couldn't be the desired behaviour could it?
}
} else {
log.error("parent was null for node with number" + getNumber());
}
setUpdate(fieldName);
return true;
}
What actually is the meaning of the (boolean) return value of
parent.setValue() and who is responsible for doing the updates?
In case of the UserBuilder.java class it looks like both MMObjectNode
and UserBuilder do set values in values Hashtable, and there are
situations in which UserBuilder.setValue returns false but the
storeValue method of MMObjectNode will always have been called before that.
Hoping for some enlightenment...
cheers,
Simon
_______________________________________________
Developers mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/developers