- Implemented notifyPropertyChange() function which is called from all property setters in order to fix bug 424.

- Refactored DbMapping related checks in setString() a little bit.
This commit is contained in:
hns 2005-05-24 10:21:48 +00:00
parent f671a6b838
commit fe455cb556

View file

@ -324,6 +324,30 @@ public final class Node implements INode, Serializable {
} }
} }
/**
* Notify the node's parent that its child collection needs to be reloaded
* in case the changed property has an affect on collection order or content.
*
* @param propname the name of the property being changed
*/
void notifyPropertyChange(String propname) {
Node parent = (parentHandle == null) ? null : (Node) getParent();
if ((parent != null) && (parent.getDbMapping() != null)) {
// check if this node is already registered with the old name; if so, remove it.
// then set parent's property to this node for the new name value
DbMapping parentmap = parent.getDbMapping();
Relation subrel = parentmap.getSubnodeRelation();
String dbcolumn = dbmap.propertyToColumnName(propname);
if (subrel == null || dbcolumn == null)
return;
if (subrel.order != null && subrel.order.indexOf(dbcolumn) > -1) {
parent.registerSubnodeChange();
}
}
}
/** /**
* Called by the transactor on registered parent nodes to mark the * Called by the transactor on registered parent nodes to mark the
* child index as changed * child index as changed
@ -1947,47 +1971,56 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
// check if this may have an effect on the node's URL when using accessname if (dbmap != null) {
// but only do this if we already have a parent set, i.e. if we are already stored in the db
Node parent = (parentHandle == null) ? null : (Node) getParent();
if ((dbmap != null) && (parent != null) && (parent.getDbMapping() != null)) { // check if this may have an effect on the node's parerent's child collection
// check if this node is already registered with the old name; if so, remove it. // in combination with the accessname or order field.
// then set parent's property to this node for the new name value Node parent = (parentHandle == null) ? null : (Node) getParent();
DbMapping parentmap = parent.getDbMapping();
Relation propRel = parentmap.getSubnodeRelation();
String dbcolumn = dbmap.propertyToColumnName(propname);
if ((propRel != null) && (propRel.accessName != null) && if ((parent != null) && (parent.getDbMapping() != null)) {
propRel.accessName.equals(dbcolumn)) { DbMapping parentmap = parent.getDbMapping();
INode n = (INode) parent.getChildElement(value); Relation subrel = parentmap.getSubnodeRelation();
String dbcolumn = dbmap.propertyToColumnName(propname);
if ((n != null) && (n != this)) { if (subrel != null && dbcolumn != null) {
parent.unset(value); // inlined version of notifyPropertyChange();
parent.removeNode(n); if (subrel.order != null && subrel.order.indexOf(dbcolumn) > -1) {
} parent.registerSubnodeChange();
}
if (oldvalue != null) { // check if accessname has changed
n = (INode) parent.getChildElement(oldvalue); if (subrel.accessName != null &&
subrel.accessName.equals(dbcolumn)) {
// if any other node is contained with the new value, remove it
INode n = (INode) parent.getChildElement(value);
if (n == this) { if ((n != null) && (n != this)) {
parent.unset(oldvalue); parent.unset(value);
parent.addNode(this); parent.removeNode(n);
}
// let the node cache know this key's not for this node anymore. // check if this node is already registered with the old name;
nmgr.evictKey(new SyntheticKey(parent.getKey(), oldvalue)); // if so, remove it, then add again with the new acessname
if (oldvalue != null) {
n = (INode) parent.getChildElement(oldvalue);
if (n == this) {
parent.unset(oldvalue);
parent.addNode(this);
// let the node cache know this key's not for this node anymore.
nmgr.evictKey(new SyntheticKey(parent.getKey(), oldvalue));
}
}
setName(value);
} }
} }
setName(value);
} }
}
// check if the property we're setting specifies the prototype of this object. // check if the property we're setting specifies the prototype of this object.
if ((dbmap != null) && (dbmap.getPrototypeField() != null)) { if (dbmap.getPrototypeField() != null &&
String pn = dbmap.columnNameToProperty(dbmap.getPrototypeField()); propname.equals(dbmap.columnNameToProperty(dbmap.getPrototypeField()))) {
if (propname.equals(pn)) {
DbMapping newmap = nmgr.getDbMapping(value); DbMapping newmap = nmgr.getDbMapping(value);
if (newmap != null) { if (newmap != null) {
@ -2042,6 +2075,8 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
notifyPropertyChange(propname);
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();
if (state == CLEAN) { if (state == CLEAN) {
@ -2077,6 +2112,8 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
notifyPropertyChange(propname);
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();
if (state == CLEAN) { if (state == CLEAN) {
@ -2112,6 +2149,8 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
notifyPropertyChange(propname);
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();
if (state == CLEAN) { if (state == CLEAN) {
@ -2147,6 +2186,8 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
notifyPropertyChange(propname);
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();
if (state == CLEAN) { if (state == CLEAN) {
@ -2182,6 +2223,8 @@ public final class Node implements INode, Serializable {
propMap.put(p2, prop); propMap.put(p2, prop);
} }
notifyPropertyChange(propname);
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();
if (state == CLEAN) { if (state == CLEAN) {
@ -2355,6 +2398,7 @@ public final class Node implements INode, Serializable {
if (relational) { if (relational) {
p.setStringValue(null); p.setStringValue(null);
notifyPropertyChange(propname);
} }
lastmodified = System.currentTimeMillis(); lastmodified = System.currentTimeMillis();