r9853 - helma/helma/trunk/src/helma/objectmodel/db

[email protected] Fri, 14 Aug 2009 13:42:42 +0200 (CEST)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20090814114242.B26A43D0E3@mia>
Author: hannes
Date: 2009-08-14 13:42:42 +0200 (Fri, 14 Aug 2009)
New Revision: 9853

Modified:
   helma/helma/trunk/src/helma/objectmodel/db/Node.java
   helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java
   helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java
   helma/helma/trunk/src/helma/objectmodel/db/SubnodeList.java
Log:
* Reenable prefetchChildren() for grouped subnodes.
* Make Subnodelist.add()/get() type-safe by using NodeHandle instead of java.lang.Object.

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

Modified: helma/helma/trunk/src/helma/objectmodel/db/Node.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-08-14 09:56:16 UTC (rev 9852)
+++ helma/helma/trunk/src/helma/objectmodel/db/Node.java	2009-08-14 11:42:42 UTC (rev 9853)
@@ -1119,7 +1119,7 @@
 
             for (int i = 0; i < l; i++)
                 try {
-                    NodeHandle shandle = (NodeHandle) subnodes.get(i);
+                    NodeHandle shandle = subnodes.get(i);
 
                     if (subid.equals(shandle.getID())) {
                         // System.err.println ("FOUND SUBNODE: "+shandle);

Modified: helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java	2009-08-14 09:56:16 UTC (rev 9852)
+++ helma/helma/trunk/src/helma/objectmodel/db/NodeManager.java	2009-08-14 11:42:42 UTC (rev 9853)
@@ -1039,7 +1039,7 @@
     protected List collectMissingKeys(SubnodeList list, int start, int length) {
         List retval = null;
         for (int i = start; i < start + length; i++) {
-            NodeHandle handle = (NodeHandle) list.get(i);
+            NodeHandle handle = list.get(i);
             if (handle != null && !cache.containsKey(handle.getKey())) {
                 if (retval == null) {
                     retval = new ArrayList();
@@ -1121,19 +1121,26 @@
                         // group nodes.
                         String groupName = null;
 
-                        /* if (groupbyProp != null) {
+                        if (groupbyProp != null) {
                             groupName = node.getString(groupbyProp);
+                            if (groupName != null) {
+                                Node groupNode = (Node) groupbySubnodes.get(groupName);
 
-                            SubnodeList sn = (SubnodeList) groupbySubnodes.get(groupName);
+                                if (groupNode == null) {
+                                    groupNode = home.getGroupbySubnode(groupName, true);
+                                    groupbySubnodes.put(groupName, groupNode);
+                                }
 
-                            if (sn == null) {
-                                sn = new SubnodeList(safe, rel);
-                                groupbySubnodes.put(groupName, sn);
+                                SubnodeList subnodes = groupNode.getSubnodeList();
+                                if (subnodes == null) {
+                                    subnodes = groupNode.createSubnodeList();
+                                    // mark subnodes as up-to-date
+                                    subnodes.lastSubnodeFetch = subnodes.getLastSubnodeChange();
+                                }
+                                subnodes.add(new NodeHandle(key));
                             }
+                        }
 
-                            sn.add(new NodeHandle(key));
-                        } */
-
                         // if relation doesn't use primary key as accessName, get secondary key
                         if (accessProp != null) {
                             String accessName = node.getString(accessProp);
@@ -1151,28 +1158,9 @@
                         // register new nodes with the cache. If an up-to-date copy
                         // existed in the cache, use that.
                         registerNewNode(node, secondaryKey);
-
                         fetchJoinedNodes(rs, joins, columns.length);
                     }
 
-                    // If these are grouped nodes, build the intermediary group nodes
-                    // with the subnod lists we created
-                    /* if (groupbyProp != null) {
-                        for (Iterator i = groupbySubnodes.keySet().iterator();
-                                 i.hasNext();) {
-                            String groupname = (String) i.next();
-
-                            if (groupname == null) {
-                                continue;
-                            }
-
-                            Node groupnode = home.getGroupbySubnode(groupname, true);
-
-                            groupnode.setSubnodes((SubnodeList) groupbySubnodes.get(groupname));
-                            groupnode.lastSubnodeFetch = 
-                                    groupnode.getLastSubnodeChange(groupnode.dbmap.getSubnodeRelation());
-                        }
-                    } */
                 } catch (Exception x) {
                     app.logError("Error in prefetchNodes()", x);
                 } finally {

Modified: helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java	2009-08-14 09:56:16 UTC (rev 9852)
+++ helma/helma/trunk/src/helma/objectmodel/db/SegmentedSubnodeList.java	2009-08-14 11:42:42 UTC (rev 9853)
@@ -33,34 +33,34 @@
      * Adds the specified object to this list performing
      * custom ordering
      *
-     * @param obj element to be inserted.
+     * @param handle element to be inserted.
      */
-    public synchronized boolean add(Object obj) {
+    public synchronized boolean add(NodeHandle handle) {
         if (!hasRelationalNodes() || segments == null) {
-            return super.add(obj);
+            return super.add(handle);
         }
         if (subnodeCount == -1) {
             update();
         }
         subnodeCount++;
         segments[segments.length - 1].length += 1;
-        return list.add(obj);
+        return list.add(handle);
     }
     /**
      * Adds the specified object to the list at the given position
      * @param index the index to insert the element at
-     * @param obj the object t add
+     * @param handle the object to add
      */
-    public synchronized void add(int index, Object obj) {
+    public synchronized void add(int index, NodeHandle handle) {
         if (!hasRelationalNodes() || segments == null) {
-            super.add(index, obj);
+            super.add(index, handle);
             return;
         }
         if (subnodeCount == -1) {
             update();
         }
         subnodeCount++;
-        list.add(index, obj);
+        list.add(index, handle);
         // shift segment indices by one
         int s = getSegment(index);
         segments[s].length += 1;
@@ -69,7 +69,7 @@
         }
     }
 
-    public Object get(int index) {
+    public NodeHandle get(int index) {
         if (!hasRelationalNodes() || segments == null) {
             return super.get(index);
         }
@@ -77,7 +77,7 @@
             return null;
         }
         loadSegment(getSegment(index), false);
-        return list.get(index);
+        return (NodeHandle) list.get(index);
     }
 
     public synchronized boolean contains(Object object) {

Modified: helma/helma/trunk/src/helma/objectmodel/db/SubnodeList.java
===================================================================
--- helma/helma/trunk/src/helma/objectmodel/db/SubnodeList.java	2009-08-14 09:56:16 UTC (rev 9852)
+++ helma/helma/trunk/src/helma/objectmodel/db/SubnodeList.java	2009-08-14 11:42:42 UTC (rev 9853)
@@ -50,30 +50,30 @@
      * Adds the specified object to this list performing
      * custom ordering
      *
-     * @param obj element to be inserted.
+     * @param handle element to be inserted.
      */
-    public boolean add(Object obj) {
-        return list.add(obj);
+    public boolean add(NodeHandle handle) {
+        return list.add(handle);
     }
     /**
      * Adds the specified object to the list at the given position
      * @param idx the index to insert the element at
-     * @param obj the object t add
+     * @param handle the object to add
      */
-    public void add(int idx, Object obj) {
-        list.add(idx, obj);
+    public void add(int idx, NodeHandle handle) {
+        list.add(idx, handle);
     }
 
-    public Object get(int index) {
+    public NodeHandle get(int index) {
         if (index < 0 || index >= list.size()) {
             return null;
         }
-        return list.get(index);
+        return (NodeHandle) list.get(index);
     }
 
     public Node getNode(int index) {
         Node retval = null;
-        NodeHandle handle = (NodeHandle) get(index);
+        NodeHandle handle = get(index);
 
         if (handle != null) {
             retval = handle.getNode(node.nmgr);
@@ -149,12 +149,11 @@
         }
 
         DbMapping dbmap = getSubnodeMapping();
-        Relation rel = getSubnodeRelation();
 
-        if (!dbmap.isRelational() || rel.getGroup() != null) {
-            return;
+        if (dbmap.isRelational()) {
+            Relation rel = getSubnodeRelation();
+            node.nmgr.prefetchNodes(node, rel, this, start, length);
         }
-        node.nmgr.prefetchNodes(node, rel, this, start, length);
     }
 
     /**