Also check for multi-constraint relations when adding child nodes and defer setting of constraints until nodes are persisted. Fixes a bug reported by Simon Oberhammer on the mailing list: http://groups.google.com/group/helma/browse_frm/thread/8026700caf582560

This commit is contained in:
hns 2009-04-28 15:14:32 +00:00
parent 3c44bb305d
commit 9c123b41e9

View file

@ -841,8 +841,9 @@ public final class Node implements INode, Serializable {
node.checkWriteLock(); node.checkWriteLock();
} }
Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation();
// if subnodes are defined via relation, make sure its constraints are enforced. // if subnodes are defined via relation, make sure its constraints are enforced.
if ((dbmap != null) && (dbmap.getSubnodeRelation() != null)) { if (subrel != null && subrel.countConstraints() < 2) {
dbmap.getSubnodeRelation().setConstraints(this, node); dbmap.getSubnodeRelation().setConstraints(this, node);
} }
@ -853,7 +854,7 @@ public final class Node implements INode, Serializable {
// only mark this node as modified if subnodes are not in relational db // only mark this node as modified if subnodes are not in relational db
// pointing to this node. // pointing to this node.
if (!ignoreSubnodeChange() && ((state == CLEAN) || (state == DELETED))) { if (!ignoreSubnodeChange() && (state == CLEAN || state == DELETED)) {
markAs(MODIFIED); markAs(MODIFIED);
} }
@ -874,7 +875,7 @@ public final class Node implements INode, Serializable {
NodeHandle nhandle = node.getHandle(); NodeHandle nhandle = node.getHandle();
if ((subnodes != null) && subnodes.contains(nhandle)) { if (subnodes != null && subnodes.contains(nhandle)) {
// Node is already subnode of this - just move to new position // Node is already subnode of this - just move to new position
synchronized (subnodes) { synchronized (subnodes) {
subnodes.remove(nhandle); subnodes.remove(nhandle);
@ -2493,11 +2494,15 @@ public final class Node implements INode, Serializable {
* so that the Transactor knows they are to be persistified. * so that the Transactor knows they are to be persistified.
*/ */
private void makeChildrenPersistable() { private void makeChildrenPersistable() {
Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation();
for (Enumeration e = getSubnodes(); e.hasMoreElements();) { for (Enumeration e = getSubnodes(); e.hasMoreElements();) {
Node n = (Node) e.nextElement(); Node n = (Node) e.nextElement();
if (n.state == TRANSIENT) { if (n.state == TRANSIENT) {
n.makePersistable(); n.makePersistable();
if (subrel != null && subrel.countConstraints() > 1) {
subrel.setConstraints(this, n);
}
} }
} }