r9689 - helma/helma/trunk/src/helma/objectmodel/db

[email protected] Tue, 28 Apr 2009 17:14:32 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090428151432.D9A1A3D0D6@mia>
Author: hannes
Date: 2009-04-28 17:14:32 +0200 (Tue, 28 Apr 2009)
New Revision: 9689

Modified:
   helma/helma/trunk/src/helma/objectmodel/db/Node.java
Log:
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

Details at http://dev.helma.org/trac/helma/changeset/9689

Modified: helma/helma/trunk/src/helma/objectmodel/db/Node.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-04-28 13:30:29 UTC (rev 9688)
+++ helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-04-28 15:14:32 UTC (rev 9689)
@@ -841,8 +841,9 @@
             node.checkWriteLock();
         }
 
+        Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation();
         // 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);
         }
 
@@ -853,7 +854,7 @@
 
         // only mark this node as modified if subnodes are not in relational db
         // pointing to this node.
-        if (!ignoreSubnodeChange() && ((state == CLEAN) || (state == DELETED))) {
+        if (!ignoreSubnodeChange() && (state == CLEAN || state == DELETED)) {
             markAs(MODIFIED);
         }
 
@@ -874,7 +875,7 @@
 
         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
             synchronized (subnodes) {
                 subnodes.remove(nhandle);
@@ -2493,11 +2494,15 @@
      * so that the Transactor knows they are to be persistified.
      */
     private void makeChildrenPersistable() {
+        Relation subrel = dbmap == null ? null : dbmap.getSubnodeRelation();
         for (Enumeration e = getSubnodes(); e.hasMoreElements();) {
             Node n = (Node) e.nextElement();
 
             if (n.state == TRANSIENT) {
                 n.makePersistable();
+                if (subrel != null && subrel.countConstraints() > 1) {
+                    subrel.setConstraints(this, n);
+                }
             }
         }