[exo-jcr-commits] exo-jcr SVN: r455 - 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 Oct 30 10:25:11 EDT 2009


Author: pnedonosko
Date: 2009-10-30 10:25:11 -0400 (Fri, 30 Oct 2009)
New Revision: 455

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/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java
Log:
EXOJCR-200: storage connection add, update

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-10-30 13:37:26 UTC (rev 454)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java	2009-10-30 14:25:11 UTC (rev 455)
@@ -355,9 +355,7 @@
 
       // TODO it's put anyway.. but with check?
       Fqn<String> parentFqn = makeParentFqn(data.getQPath());
-      Object prev =
-         cache.put(parentFqn, data.getQPath().getEntries()[data.getQPath().getEntries().length - 1].getAsString(true),
-            data.getIdentifier());
+      Object prev = cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
       if (prev == null)
       {
          throw new IllegalStateException("Property was deleted (tree)");
@@ -402,7 +400,7 @@
       {
          LOG.debug("rollback " + batchStarted);
       }
-      
+
       // rollback batch
       if (batchStarted)
       {

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-10-30 13:37:26 UTC (rev 454)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java	2009-10-30 14:25:11 UTC (rev 455)
@@ -48,6 +48,7 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 import org.jboss.cache.Cache;
 import org.jboss.cache.DefaultCacheFactory;
 import org.jboss.cache.Fqn;
@@ -196,6 +197,13 @@
 
       Node<Serializable, Object> itemsNode = items.getChild(Fqn.fromElements(node1id));
       assertNotNull("Node item data should exists", itemsNode);
+
+      Object dataObject = itemsNode.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertTrue("Node item data is not a Node", dataObject instanceof NodeData);
+
+      NodeData data = (NodeData)dataObject;
+      assertEquals("Node id wrong", node1id, data.getIdentifier());
+      assertEquals("Node path wrong", node1path, data.getQPath());
    }
 
    public void testAddProperty() throws Exception
@@ -206,13 +214,19 @@
 
       // 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));
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValue1 = "Property value #1";
+      propData1.setValue(new TransientValueData(propValue1));
+      conn.add(propData1);
 
       // add property (/jcr:mixinTypes)
       String propId2 = "2";
-      conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES), propId2,
-         1, 1, Constants.ROOT_UUID, false));
+      QPath propPath2 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_MIXINTYPES);
+      TransientPropertyData propData2 = new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID, false);
+      String propValue2 = "Property value #2";
+      propData2.setValue(new TransientValueData(propValue2));
+      conn.add(propData2);
 
       // check in tree
       treePrint(tree);
@@ -223,13 +237,13 @@
 
       assertEquals("Attributes ammount wrong", 3, rootNode.getKeys().size());
 
-      String pid = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
-      assertNotNull("Property ID should exists", pid);
-      assertEquals("Property ID wrong", propId1, pid);
+      String pid1 = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+      assertNotNull("Property ID should exists", pid1);
+      assertEquals("Property ID wrong", propId1, pid1);
 
-      pid = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
-      assertNotNull("Property ID should exists", pid);
-      assertEquals("Property ID wrong", propId2, pid);
+      String pid2 = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
+      assertNotNull("Property ID should exists", pid2);
+      assertEquals("Property ID wrong", propId2, pid2);
 
       // TODO check order
       int index = 0;
@@ -242,8 +256,27 @@
       // check in items
       treePrint(items);
 
-      assertNotNull("Property item data should exists", items.getChild(Fqn.fromElements(propId1)));
-      assertNotNull("Property item data should exists", items.getChild(Fqn.fromElements(propId2)));
+      Node<Serializable, Object> itemsProp1 = items.getChild(Fqn.fromElements(propId1));
+      Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data1Object);
+      assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+      PropertyData data1 = (PropertyData)data1Object;
+      assertEquals("Property id wrong", propId1, data1.getIdentifier());
+      assertEquals("Property path wrong", propPath1, data1.getQPath());
+      assertEquals("Property Value wrong", propValue1, new String(data1.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
+
+      Node<Serializable, Object> itemsProp2 = items.getChild(Fqn.fromElements(propId2));
+      Object data2Object = itemsProp2.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data2Object);
+      assertTrue("Property item data is not a Property", data2Object instanceof PropertyData);
+
+      PropertyData data2 = (PropertyData)data2Object;
+      assertEquals("Property id wrong", propId2, data2.getIdentifier());
+      assertEquals("Property path wrong", propPath2, data2.getQPath());
+      assertEquals("Property Value wrong", propValue2, new String(data2.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
    }
 
    public void testDeleteNode() throws Exception
@@ -339,6 +372,98 @@
       assertNotNull("Property item data should exists", items.getChild(Fqn.fromElements(propId2)));
    }
 
+   public void testUpdateNode() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, 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()));
+
+      // get root node ([]:1)
+      Node<Serializable, Object> rootNode =
+         tree.getChild(Fqn.fromElements(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
+            .getAsString(true)));
+
+      // update /node (order number)
+      int nodeOrderNumb = 1;
+      conn.update(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
+         nodeOrderNumb, Constants.ROOT_UUID, new AccessControlList()));
+
+      // check in tree
+      treePrint(tree);
+
+      Node<Serializable, Object> node =
+         rootNode.getChild(Fqn
+            .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+
+      assertNotNull("Node should exists", node);
+      assertEquals("Child expected", 1, rootNode.getChildren().size());
+
+      // check in items
+      treePrint(items);
+
+      Node<Serializable, Object> itemNode = items.getChild(Fqn.fromElements(node1id));
+      assertNotNull("Node item data should exists", itemNode);
+
+      Object dataObject = itemNode.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertTrue("Node item data should be a NodeData", dataObject instanceof NodeData);
+      assertEquals("Node id wrong", node1id, ((NodeData)dataObject).getIdentifier());
+      assertEquals("Node path wrong", node1path, ((NodeData)dataObject).getQPath());
+      assertEquals("Node order number wrong", nodeOrderNumb, ((NodeData)dataObject).getOrderNumber());
+   }
+
+   public void testUpdateProperty() throws Exception
+   {
+      // add root (/)
+      conn.add(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1, Constants.NT_UNSTRUCTURED,
+         new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+      // add property (/prop1)
+      String propId1 = "1";
+      QPath propPath1 = QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE);
+      TransientPropertyData propData1 = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValue1 = "Property value #1";
+      propData1.setValue(new TransientValueData(propValue1));
+      conn.add(propData1);
+
+      // update property (/prop1) with new value
+      TransientPropertyData propDataU = new TransientPropertyData(propPath1, propId1, 1, 1, Constants.ROOT_UUID, false);
+      String propValueU = "Updated Property value #1";
+      propDataU.setValue(new TransientValueData(propValueU));
+      conn.update(propDataU);
+
+      // check in tree
+      treePrint(tree);
+
+      Node<Serializable, Object> rootNode =
+         tree.getChild(Fqn.fromElements(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
+            .getAsString(true)));
+
+      assertEquals("Attributes ammount wrong", 2, rootNode.getKeys().size());
+
+      String pid = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
+      assertEquals("Property ID wrong", propId1, pid);
+
+      // check in items
+      treePrint(items);
+
+      Node<Serializable, Object> itemsProp1 = items.getChild(Fqn.fromElements(propId1));
+      Object data1Object = itemsProp1.get(JBossCacheStorageConnection.ITEM_DATA);
+      assertNotNull("Property item data should exists", data1Object);
+      assertTrue("Property item data is not a Property", data1Object instanceof PropertyData);
+
+      PropertyData data1 = (PropertyData)data1Object;
+      assertEquals("Property id wrong", propId1, data1.getIdentifier());
+      assertEquals("Property path wrong", propPath1, data1.getQPath());
+      assertEquals("Property Value wrong", propValueU, new String(data1.getValues().get(0).getAsByteArray(),
+         Constants.DEFAULT_ENCODING));
+   }
+
    public void testGetNodeByName() throws Exception
    {
       // TODO prepare using JCR WDC API (not a right way, JBC API better... but read assumes the write works)



More information about the exo-jcr-commits mailing list