[exo-jcr-commits] exo-jcr SVN: r799 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 20 12:01:07 EST 2009


Author: pnedonosko
Date: 2009-11-20 12:01:06 -0500 (Fri, 20 Nov 2009)
New Revision: 799

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-248: fixes of SNS delete/update (not final: OrderBefore/Move tests fail)

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-20 16:39:32 UTC (rev 798)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-11-20 17:01:06 UTC (rev 799)
@@ -151,7 +151,8 @@
          Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
          if (parent == null)
          {
-            throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
+            throw new InvalidItemStateException("Node's parent doesn't exist or removed by another Session "
+               + data.getQPath().getAsString());
          }
 
          final Fqn<String> name =
@@ -188,7 +189,8 @@
       Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
       if (parent == null)
       {
-         throw new RepositoryException("Property's parent doesn't exist " + data.getQPath().getAsString());
+         throw new InvalidItemStateException("Property's parent doesn't exist or removed by another Session "
+            + data.getQPath().getAsString());
       }
 
       if (data.getType() == PropertyType.REFERENCE)
@@ -272,26 +274,48 @@
       //         }
       //      }
 
-      if (data.getParentIdentifier() != null)
+      // get parent
+      Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
+      if (parent == null)
       {
-         // check if parent is cached
-         Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
-         if (parent == null)
+         throw new InvalidItemStateException("Node's parent doesn't exist or removed by another Session "
+            + data.getQPath().getAsString());
+      }
+
+      // remove child on Parent
+      if (!parent.removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1])))
+      {
+         // TODO [PN] if not removed, try by Id stored in the cache (seems it's workaround, better solution should be)
+         Node<Serializable, Object> thisStoredNode = nodesRoot.getChild(makeNodeFqn(data.getIdentifier()));
+         if (thisStoredNode != null)
          {
-            throw new RepositoryException("Node parent doesn't exist " + data.getQPath().getAsString());
+            NodeData storedData = (NodeData)thisStoredNode.get(ITEM_DATA);
+            if (storedData != null)
+            {
+               // it's same-name siblings re-ordering, delete previous child
+               if (!parent.removeChild(makeChildNodeFqn(storedData.getQPath().getEntries()[storedData.getQPath()
+                  .getEntries().length - 1])))
+               {
+                  throw new InvalidItemStateException(
+                     "Node's doesn't exist or deleted by another Session but listed in children nodes "
+                        + data.getQPath().getAsString());
+               }
+            }
          }
-
-         // remove child on Parent
-         if (!parent
-            .removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1])))
+         else
          {
             throw new InvalidItemStateException("Node's doesn't exist or deleted by another Session "
                + data.getQPath().getAsString());
          }
       }
 
+      //treePrint(parent);
+
       // remove from NODES
-      boolean removed = nodesRoot.removeChild(makeNodeFqn(data.getIdentifier()));
+      if (!nodesRoot.removeChild(makeNodeFqn(data.getIdentifier())))
+      {
+         LOG.warn("Node was not deleted " + data.getQPath().getAsString());
+      }
    }
 
    /**
@@ -301,12 +325,13 @@
       InvalidItemStateException, IllegalStateException
    {
       startBatch();
-
+      // propsRoot.getChild(makePropFqn(data.getIdentifier()))
       // check if parent is cached
       Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
       if (parent == null)
       {
-         throw new RepositoryException("Property's parent doesn't exist " + data.getQPath().getAsString());
+         throw new InvalidItemStateException("Property's parent doesn't exist or removed by another Session "
+            + data.getQPath().getAsString());
       }
 
       if (data.getType() == PropertyType.REFERENCE)
@@ -355,7 +380,6 @@
                }
             }
          }
-
       }
 
       // remove from parent's properties attr
@@ -367,7 +391,10 @@
       }
 
       // remove from PROPERTIES
-      boolean removed = propsRoot.removeChild(makePropFqn(data.getIdentifier()));
+      if (!propsRoot.removeChild(makePropFqn(data.getIdentifier())))
+      {
+         LOG.warn("Property want not deleted " + data.getQPath().getAsString());
+      }
    }
 
    /**
@@ -771,26 +798,55 @@
          throw new InvalidItemStateException("Node was updated previously or removed " + data.getQPath().getAsString());
       }
 
-      if (data.getParentIdentifier() != null)
+      // check if parent is cached
+      Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
+      if (parent == null)
       {
-         // check if parent is cached
-         Node<Serializable, Object> parent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
-         if (parent == null)
+         throw new RepositoryException("FATAL Node's parent not found " + data.getQPath().getAsString());
+      }
+
+      // update child on Parent
+      NodeData prevData = (NodeData)node.get(ITEM_DATA);
+      if (prevData != null)
+      {
+         // TODO (new logic) get previously cached NodeData and using its name remove child on the parent
+         Fqn<String> prevPath =
+            makeChildNodeFqn(prevData.getQPath().getEntries()[prevData.getQPath().getEntries().length - 1]);
+         Node<Serializable, Object> prevNameNode = parent.getChild(prevPath);
+         if (prevNameNode != null)
          {
-            throw new RepositoryException("FATAL Node's parent not found " + data.getQPath().getAsString());
-         }
+            String prevNameNodeId = (String)prevNameNode.get(ITEM_ID);
+            if (prevNameNodeId != null)
+            {
+               if (prevNameNodeId.equals(data.getIdentifier()))
+               {
+                  // it's same-name siblings re-ordering, delete previous child
+                  if (!parent.removeChild(prevPath))
+                  {
+                     throw new RepositoryException("FATAL Node not extists as child but update asked "
+                        + data.getQPath().getAsString());
+                  }
+               } // else ok
+            }
+            else
+            {
+               throw new RepositoryException("FATAL Child Node extists but ITEM_ID is empty " + prevNameNode.getFqn()
+                  + ". Update of " + data.getQPath().getAsString());
+            }
+         } // else ok
+      }
+      else
+      {
+         throw new RepositoryException("FATAL Node's current data not found " + data.getQPath().getAsString());
+      }
 
-         // update child on Parent
-         // TODO (wrong logic) get previously cached NodeData and using its name remove child on the parent
-         //boolean removed =
-         //   parent.removeChild(makeChildNodeFqn(prevPath.getEntries()[prevPath.getEntries().length - 1]));
+      Node<Serializable, Object> childNode =
+         parent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
 
-         Node<Serializable, Object> childNode =
-            parent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+      // set child id attr 
+      childNode.put(ITEM_ID, data.getIdentifier());
 
-         // set child id attr 
-         childNode.put(ITEM_ID, data.getIdentifier());
-      }
+      //treePrint(parent);
 
       // update in NODES
       node.put(ITEM_DATA, data);

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-20 16:39:32 UTC (rev 798)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JDBCCacheLoader.java	2009-11-20 17:01:06 UTC (rev 799)
@@ -230,6 +230,10 @@
             conn.deleteProperty(identifier);
          }
       }
+      else
+      {
+         // remove of child node, we're not interested in such info for persistence
+      }
    }
 
    /**

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java	2009-11-20 16:39:32 UTC (rev 798)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java	2009-11-20 17:01:06 UTC (rev 799)
@@ -272,9 +272,9 @@
       treePrint(nodes);
 
       // get /snsNode:1 from childs of root /
-      checkChildNode(rootNode, node1id, node2path);
-      checkChildNode(rootNode, node2id, node1path);
-      checkChildNode(rootNode, node3id, node3path);
+      checkChildNode(rootNode, node1id, node2path, newNode1OrderNumb, newNode1version);
+      checkChildNode(rootNode, node2id, node1path, newNode2OrderNumb, newNode2version);
+      checkChildNode(rootNode, node3id, node3path, newNode3OrderNumb, newNode3version);
 
       //      Node<Serializable, Object> childNode1 =
       //         rootNode.getChild(Fqn
@@ -317,6 +317,78 @@
       //      assertEquals("Node order number wrong", nodeOrderNumb, ((NodeData)dataObject).getOrderNumber());
    }
 
+   public void testDeleteUpdateNode() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, null, new AccessControlList()));
+
+      // add node (/node)
+      String node1id = "1";
+      QPath node1path = QPath.parse("[]:1[]snsNode:1");
+      int node1OrderNumb = 0;
+      int node1version = 1;
+      conn.add(new TransientNodeData(node1path, node1id, node1version, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+         node1OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      String node2id = "2";
+      QPath node2path = QPath.parse("[]:1[]snsNode:2");
+      int node2OrderNumb = 1;
+      conn.add(new TransientNodeData(node2path, node2id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+         node2OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      String node3id = "3";
+      QPath node3path = QPath.parse("[]:1[]snsNode:3");
+      int node3OrderNumb = 2;
+      conn.add(new TransientNodeData(node3path, node3id, 1, Constants.NT_BASE, new InternalQName[0], node3OrderNumb,
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      // get root node ([]:1)
+      Node<Serializable, Object> rootNode = nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
+
+      // before
+      treePrint(nodes);
+
+      // do /snsNode:1 delete, 
+      // update /snsNode:2 -> /snsNode:1, /snsNode:3 -> /snsNode:2 (order number, version and index) 
+      conn.delete(new TransientNodeData(node1path, node1id, node1version, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], node1OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      // update /snsNode:2 (order number, version and index) to /snsNode:1 
+      QPath newNode2path = QPath.parse("[]:1[]snsNode:1");
+      int newNode2OrderNumb = 0;
+      int newNode2version = 2;
+      conn.update(new TransientNodeData(newNode2path, node2id, newNode2version, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], newNode2OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      // update /snsNode:3 (order number, version and index) to /snsNode:2 
+      QPath newNode3path = QPath.parse("[]:1[]snsNode:2");
+      int newNode3OrderNumb = 1;
+      int newNode3version = 2;
+      conn.update(new TransientNodeData(newNode3path, node3id, newNode3version, Constants.NT_BASE,
+         new InternalQName[0], newNode3OrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      // after
+      treePrint(nodes);
+
+      // check
+
+      // /snsNode:1 exists
+      assertEquals("Childs expected", 2, rootNode.getChildren().size());
+      assertNull("Child Node should be deleted", rootNode.getChild(Fqn.fromElements(node3path.getEntries()[node3path
+         .getEntries().length - 1].getAsString(true))));
+      assertNotNull("Child Node should exists", rootNode.getChild(Fqn.fromElements(node1path.getEntries()[node1path
+         .getEntries().length - 1].getAsString(true))));
+      assertNotNull("Child Node should exists", rootNode.getChild(Fqn.fromElements(node1path.getEntries()[node2path
+         .getEntries().length - 1].getAsString(true))));
+
+      // /snsNode:2 -> /snsNode:1
+      checkChildNode(rootNode, node2id, node1path, newNode2OrderNumb, newNode2version);
+
+      // /snsNode:3 -> /snsNode:2
+      checkChildNode(rootNode, node3id, node2path, newNode3OrderNumb, newNode3version);
+   }
+
    public void testUpdateProperty() throws Exception
    {
       // add root (/)
@@ -646,13 +718,15 @@
             new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
 
          conn.commit();
-         
+
          fail("The node jcr:system should not be save");
-      } catch (ItemExistsException e) {
+      }
+      catch (ItemExistsException e)
+      {
          //ok
       }
    }
-   
+
    public void testAddPropertyFail() throws Exception
    {
       // add root (/)
@@ -667,77 +741,84 @@
       propData1.setValue(new TransientValueData(propValue1));
       conn.add(propData1);
 
-      
-      
-      try {
+      try
+      {
          // add property (/jcr:primaryType) twice 
          conn.add(propData1);
-         
+
          conn.commit();
-         
+
          fail("The property (/jcr:primaryType) should not be save");
-      } catch (ItemExistsException e) {
+      }
+      catch (ItemExistsException e)
+      {
          //ok
       }
    }
-   
+
    public void testDeleteNodeFail() throws Exception
    {
       // add root (/)
       conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
-               new InternalQName[0], 0, null, new AccessControlList()));
+         new InternalQName[0], 0, null, new AccessControlList()));
 
       // add node (/node)
       String node1id = "1";
       QPath node1path = QPath.parse("[]:1[]node:1");
       conn.add(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
-               Constants.ROOT_UUID, new AccessControlList()));
+         Constants.ROOT_UUID, new AccessControlList()));
 
       // add /jcr:system
       conn.add(new TransientNodeData(Constants.JCR_SYSTEM_PATH, Constants.SYSTEM_UUID, 1, Constants.NT_UNSTRUCTURED,
-               new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
+         new InternalQName[0], 0, Constants.ROOT_UUID, new AccessControlList()));
 
       // delete /node
       conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
-               Constants.ROOT_UUID, new AccessControlList()));
-      
-      try {
+         Constants.ROOT_UUID, new AccessControlList()));
+
+      try
+      {
          // delete node /node twice 
          conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
-                  Constants.ROOT_UUID, new AccessControlList()));
-         
+            Constants.ROOT_UUID, new AccessControlList()));
+
          conn.commit();
-         
+
          fail("The node (/node) should not be delete");
-      } catch (InvalidItemStateException e) {
+      }
+      catch (InvalidItemStateException e)
+      {
          //ok
       }
    }
-   
+
    public void testDeletePropertyFail() throws Exception
    {
       // add root (/)
       conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
-               new InternalQName[0], 0, null, new AccessControlList()));
+         new InternalQName[0], 0, null, new AccessControlList()));
 
       // add property (/jcr:primaryType)
       String propId1 = "1";
       conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
-               1, 1, Constants.ROOT_UUID, false));
+         1, 1, Constants.ROOT_UUID, false));
 
       // delete /jcr:primaryType
       conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
-               propId1, 1, 1, Constants.ROOT_UUID, false));
+         propId1, 1, 1, Constants.ROOT_UUID, false));
 
-      try {
+      try
+      {
          // delete /jcr:primaryType twice 
          conn.delete(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE),
-                  propId1, 1, 1, Constants.ROOT_UUID, false));
-         
+            propId1, 1, 1, Constants.ROOT_UUID, false));
+
          conn.commit();
-         
+
          fail("The property (/jcr:primaryType) should not be delete");
-      } catch (InvalidItemStateException e) {
+      }
+      catch (InvalidItemStateException e)
+      {
          //ok
       }
    }



More information about the exo-jcr-commits mailing list