- 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,19 +1971,27 @@ 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
// check if this may have an effect on the node's parerent's child collection
// in combination with the accessname or order field.
Node parent = (parentHandle == null) ? null : (Node) getParent(); Node parent = (parentHandle == null) ? null : (Node) getParent();
if ((dbmap != null) && (parent != null) && (parent.getDbMapping() != null)) { 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(); DbMapping parentmap = parent.getDbMapping();
Relation propRel = parentmap.getSubnodeRelation(); Relation subrel = parentmap.getSubnodeRelation();
String dbcolumn = dbmap.propertyToColumnName(propname); String dbcolumn = dbmap.propertyToColumnName(propname);
if ((propRel != null) && (propRel.accessName != null) && if (subrel != null && dbcolumn != null) {
propRel.accessName.equals(dbcolumn)) { // inlined version of notifyPropertyChange();
if (subrel.order != null && subrel.order.indexOf(dbcolumn) > -1) {
parent.registerSubnodeChange();
}
// check if accessname has changed
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); INode n = (INode) parent.getChildElement(value);
if ((n != null) && (n != this)) { if ((n != null) && (n != this)) {
@ -1967,6 +1999,8 @@ public final class Node implements INode, Serializable {
parent.removeNode(n); parent.removeNode(n);
} }
// check if this node is already registered with the old name;
// if so, remove it, then add again with the new acessname
if (oldvalue != null) { if (oldvalue != null) {
n = (INode) parent.getChildElement(oldvalue); n = (INode) parent.getChildElement(oldvalue);
@ -1982,12 +2016,11 @@ public final class Node implements INode, Serializable {
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();