[exo-jcr-commits] exo-jcr SVN: r1384 - jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Jan 14 03:46:46 EST 2010


Author: nzamosenchuk
Date: 2010-01-14 03:46:46 -0500 (Thu, 14 Jan 2010)
New Revision: 1384

Modified:
   jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
Log:
EXOJCR-391: List of child properties is not modified on single item get from DB, modified onSaveItems if parent is present in CHILD_x_LISTS/parentID and force-written if list of child is read from DB.

Modified: jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java
===================================================================
--- jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-01-14 08:44:21 UTC (rev 1383)
+++ jcr/branches/1.12.0-JBCCACHE/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/jbosscache/JBossCacheWorkspaceStorageCache.java	2010-01-14 08:46:46 UTC (rev 1384)
@@ -379,7 +379,15 @@
     */
    public void put(ItemData item)
    {
-      putItem(item);
+      // TODO: Omit writing to list!
+      if (item.isNode())
+      {
+         putNode((NodeData)item, ModifyChildOption.NOT_MODIFY);
+      }
+      else
+      {
+         putProperty((PropertyData)item, ModifyChildOption.NOT_MODIFY);
+      }
    }
 
    /**
@@ -457,7 +465,7 @@
          // add all new
          for (NodeData child : childs)
          {
-            putNode(child);
+            putNode(child, ModifyChildOption.FORCE_MODIFY);
          }
       }
       else
@@ -474,13 +482,12 @@
    {
       // remove previous all (to be sure about consistency)
       cache.removeNode(makeChildListFqn(childPropsList, parent.getIdentifier()));
-
       if (childs.size() > 0)
       {
          // add all new
          for (PropertyData child : childs)
          {
-            putProperty(child);
+            putProperty(child, ModifyChildOption.FORCE_MODIFY);
          }
       }
       else
@@ -703,11 +710,11 @@
    {
       if (item.isNode())
       {
-         return putNode((NodeData)item);
+         return putNode((NodeData)item, ModifyChildOption.MODIFY);
       }
       else
       {
-         return putProperty((PropertyData)item);
+         return putProperty((PropertyData)item, ModifyChildOption.MODIFY);
       }
    }
 
@@ -717,7 +724,7 @@
     * @param node, NodeData, new data to put in the cache
     * @return NodeData, previous data or null
     */
-   protected ItemData putNode(NodeData node)
+   protected ItemData putNode(NodeData node, ModifyChildOption modifyListsOfChild)
    {
       if (node.getParentIdentifier() != null)
       {
@@ -735,7 +742,14 @@
          //         {
          //            cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
          //         }
-         cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+         if (modifyListsOfChild == ModifyChildOption.MODIFY || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+         {
+            if (cache.getNode(makeChildListFqn(childNodesList, node.getParentIdentifier())) != null
+               || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+            {
+               cache.put(makeChildListFqn(childNodesList, node.getParentIdentifier(), node.getIdentifier()), NULL_DATA);
+            }
+         }
       }
 
       // add in ITEMS
@@ -748,7 +762,7 @@
     * @param node, PropertyData, new data to put in the cache
     * @return PropertyData, previous data or null
     */
-   protected PropertyData putProperty(PropertyData prop)
+   protected PropertyData putProperty(PropertyData prop, ModifyChildOption modifyListsOfChild)
    {
       // add in CHILD_PROPS
       cache.put(makeChildFqn(childProps, prop.getParentIdentifier(), prop.getQPath().getEntries()[prop.getQPath()
@@ -762,7 +776,14 @@
       //      {
       //         cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
       //      }
-      cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+      if (modifyListsOfChild == ModifyChildOption.MODIFY || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+      {
+         if (cache.getNode(makeChildListFqn(childPropsList, prop.getParentIdentifier())) != null
+            || modifyListsOfChild == ModifyChildOption.FORCE_MODIFY)
+         {
+            cache.put(makeChildListFqn(childPropsList, prop.getParentIdentifier(), prop.getIdentifier()), NULL_DATA);
+         }
+      }
 
       // TODO REFERENCEs hadnling
       //if (prop.getType() == PropertyType.REFERENCE)
@@ -1007,4 +1028,13 @@
    {
       return true;
    }
+
+   /**
+    * <li>NOT_MODIFY - node(property) is not added to the parent's list (no persistent changes performed, cache used as cache)</li>
+    * <li>MODIFY - node(property) is added to the parent's list if parent in the cache (new item is added to persistent, add to list if it is present)</li>
+    * <li>FORCE_MODIFY - node(property) is added to the parent's list anyway (when list is read from DB, forcing write)</li>
+    */
+   private enum ModifyChildOption {
+      NOT_MODIFY, MODIFY, FORCE_MODIFY
+   }
 }



More information about the exo-jcr-commits mailing list