[exo-jcr-commits] exo-jcr SVN: r670 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/dataflow/session and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Nov 16 04:47:33 EST 2009


Author: tolusha
Date: 2009-11-16 04:47:33 -0500 (Mon, 16 Nov 2009)
New Revision: 670

Modified:
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java
   jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestBulkItemsAdd.java
Log:
EXOJCR-221: SessionChangesLog improvement

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java	2009-11-16 08:31:56 UTC (rev 669)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java	2009-11-16 09:47:33 UTC (rev 670)
@@ -676,23 +676,29 @@
     */
    public int getChildNodesCount(NodeData parent) throws RepositoryException
    {
-      int childsCount = 0;
+      int childsCount = changesLog.getChildNodesCount(parent.getIdentifier());
 
-      for (ItemState change : changesLog.getAllStates())
-      {
-         if (change.isNode() && change.isPersisted()
-            && change.getData().getParentIdentifier().equals(parent.getIdentifier()))
-         {
-            if (change.isDeleted())
-            {
-               childsCount--;
-            }
-            else if (change.isAdded())
-            {
-               childsCount++;
-            }
-         }
-      }
+      //      for (ItemState change : changesLog.getAllStates())
+      //      {
+      //         if (change.isNode() && change.isPersisted()
+      //            && parent.getIdentifier().equals(change.getData().getParentIdentifier()))
+      //         {
+      //            if (change.isDeleted())
+      //            {
+      //               childsCount--;
+      //            }
+      //            else if (change.isAdded())
+      //            {
+      //               childsCount++;
+      //            }
+      //         }
+      //      }
+      //
+      //      if (childsCount != changesLog.getChildNodesCount(parent.getIdentifier()))
+      //      {
+      //         System.out.println("");
+      //         changesLog.getChildNodesCount(parent.getIdentifier());
+      //      }
 
       childsCount = transactionableManager.getChildNodesCount(parent) + childsCount;
       if (childsCount < 0)

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java	2009-11-16 08:31:56 UTC (rev 669)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/session/SessionChangesLog.java	2009-11-16 09:47:33 UTC (rev 670)
@@ -61,6 +61,8 @@
    protected Map<String, Map<String, ItemState>> lastChildPropertyStates =
       new HashMap<String, Map<String, ItemState>>();
 
+   protected Map<String, int[]> childNodesCount = new HashMap<String, int[]>();
+
    /**
     * Create empty ChangesLog.
     * 
@@ -120,6 +122,7 @@
       index.clear();
       lastChildNodeStates.clear();
       lastChildPropertyStates.clear();
+      childNodesCount.clear();
    }
 
    /**
@@ -144,17 +147,44 @@
             index.remove(new ParentIDQPathBasedKey(item));
             index.remove(new IDStateBasedKey(item.getData().getIdentifier(), item.getState()));
 
+            if (item.isNode() && item.isPersisted())
+            {
+               int childCount[] = childNodesCount.get(item.getData().getParentIdentifier());
+               if (childCount != null)
+               {
+                  childNodesCount.remove(item.getData().getIdentifier());
+
+                  if (item.isDeleted())
+                     childCount[0]++;
+                  else if (item.isAdded())
+                     childCount[0]--;
+
+                  if (childCount[0] == 0)
+                     childNodesCount.remove(item.getData().getParentIdentifier());
+                  else
+                     childNodesCount.put(item.getData().getParentIdentifier(), childCount);
+               }
+            }
+
             if (item.getData().isNode())
             {
                Map<String, ItemState> children = lastChildNodeStates.get(item.getData().getParentIdentifier());
                if (children != null)
+               {
                   children.remove(item.getData().getIdentifier());
+                  if (children.size() == 0)
+                     lastChildNodeStates.remove(item.getData().getParentIdentifier());
+               }
             }
             else
             {
                Map<String, ItemState> children = lastChildPropertyStates.get(item.getData().getParentIdentifier());
                if (children != null)
+               {
                   children.remove(item.getData().getIdentifier());
+                  if (children.size() == 0)
+                     lastChildNodeStates.remove(item.getData().getParentIdentifier());
+               }
             }
          }
       }
@@ -344,6 +374,12 @@
       return list;
    }
 
+   public int getChildNodesCount(String rootIdentifier)
+   {
+      int[] childCount = childNodesCount.get(rootIdentifier);
+      return childCount == null ? 0 : childCount[0];
+   }
+
    /**
     * Collect last in ChangesLog order item child changes.
     * 
@@ -588,6 +624,20 @@
          }
          children.put(item.getData().getIdentifier(), item);
       }
+
+      if (item.isNode() && item.isPersisted())
+      {
+         int[] childCount = childNodesCount.get(item.getData().getParentIdentifier());
+         if (childCount == null)
+            childCount = new int[1];
+
+         if (item.isDeleted())
+            childCount[0] -= 1;
+         else if (item.isAdded())
+            childCount[0] += 1;
+
+         childNodesCount.put(item.getData().getParentIdentifier(), childCount);
+      }
    }
 
    /**

Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestBulkItemsAdd.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestBulkItemsAdd.java	2009-11-16 08:31:56 UTC (rev 669)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestBulkItemsAdd.java	2009-11-16 09:47:33 UTC (rev 670)
@@ -39,7 +39,7 @@
    public void testNodeAdd() throws Exception
    {
       StringBuilder stats = new StringBuilder();
-      
+
       Node testRoot = session.getRootNode().addNode("testRoot");
       session.save();
       long startTime = System.currentTimeMillis();
@@ -49,28 +49,35 @@
          long addTime = System.currentTimeMillis();
          String nodeName = "_" + i + "_node";
          Node n = testRoot.addNode(nodeName);
-         long finishTime = System.currentTimeMillis();
          //log.info("add node " + nodeName + ", " + (System.currentTimeMillis() - addTime) + "ms, "
          //   + (finishTime - startTime) + "ms");
          //String stat = (System.currentTimeMillis() - addTime) + ";" + (finishTime - startTime);
-         stats.append(i);
-         stats.append(";");
-         stats.append((System.currentTimeMillis() - addTime));
-         stats.append(";");
-         stats.append((finishTime - startTime));
-         stats.append("\r\n");
+         if ((i % 100) == 0)
+         {
+            stats.append(i);
+            stats.append(";");
+            stats.append((System.currentTimeMillis() - addTime));
+            //            stats.append(";");
+            //            stats.append((System.currentTimeMillis() - startTime));
+            stats.append("\r\n");
+         }
       }
+      //      stats.append(nodesCount);
+      //      stats.append(";");
+      //      stats.append((System.currentTimeMillis() - startTime));
+      //      stats.append("\r\n");
+
       log.info("Nodes added " + nodesCount + ", " + (System.currentTimeMillis() - startTime) + "ms");
       startTime = System.currentTimeMillis();
       log.info("Nodes will be saved, wait few minutes...");
       testRoot.save();
       log.info("Nodes saved " + nodesCount + ", " + (System.currentTimeMillis() - startTime) + "ms");
-      
+
       // save stats
       PrintWriter statFile = new PrintWriter(new File("stats.txt"));
       statFile.write(stats.toString());
       statFile.close();
-      
+
       log.info("Test done");
    }
 



More information about the exo-jcr-commits mailing list