[exo-jcr-commits] exo-jcr SVN: r440 - in jcr/branches/1.12.0-JBC/component/core: src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache and 1 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Wed Oct 28 15:21:31 EDT 2009
Author: pnedonosko
Date: 2009-10-28 15:21:30 -0400 (Wed, 28 Oct 2009)
New Revision: 440
Modified:
jcr/branches/1.12.0-JBC/component/core/pom.xml
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: WorkspaceStorageConnection impl parts
Modified: jcr/branches/1.12.0-JBC/component/core/pom.xml
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/pom.xml 2009-10-28 16:24:19 UTC (rev 439)
+++ jcr/branches/1.12.0-JBC/component/core/pom.xml 2009-10-28 19:21:30 UTC (rev 440)
@@ -568,10 +568,10 @@
</property>
</systemProperties>
<includes>
- <include>**/**/TestErrorMultithreading__.java</include>
<include>**/**/JBossCacheServiceTest__.java</include>
-
- <include>**/**/TestItem.java</include>
+ <include>**/**/TestItem_.java</include>
+
+ <include>**/**/JBossCacheStorageConnectionTest.java</include>
</includes>
</configuration>
</plugin>
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-28 16:24:19 UTC (rev 439)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-10-28 19:21:30 UTC (rev 440)
@@ -142,8 +142,7 @@
Fqn<String> parentFqn = makeParentFqn(data.getQPath());
// add an attr to the parent node as key=PropertyName value=PropertyId
- cache.put(parentFqn, data.getQPath().getEntries()[data.getQPath().getEntries().length - 1].getAsString(true),
- data.getIdentifier());
+ cache.put(parentFqn, data.getQPath().getName().getAsString(), data.getIdentifier());
cache.put(makeIdFqn(data.getIdentifier()), ITEM_DATA, data);
}
@@ -217,12 +216,13 @@
List<PropertyData> childs = new ArrayList<PropertyData>();
// TODO keys Serializable shoudl be!!!
- for (Object key : parentNode.getKeys())
+ for (Serializable key : parentNode.getKeys())
{
if (!key.equals(ITEM_ID))
{
+ String propId = (String) parentNode.get(key);
// TODO NodeData or PropertyData? As ItemData check then and cast.
- PropertyData property = (PropertyData)cache.get(makeIdFqn((String)key), ITEM_DATA);
+ PropertyData property = (PropertyData)cache.get(makeIdFqn(propId), ITEM_DATA);
if (property == null)
{
throw new RepositoryException("One of childs is null. Parent " + parent.getQPath().getAsString());
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-28 16:24:19 UTC (rev 439)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-10-28 19:21:30 UTC (rev 440)
@@ -36,20 +36,25 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import java.io.Serializable;
+import java.util.List;
+
import junit.framework.TestCase;
import org.exoplatform.services.jcr.access.AccessControlList;
import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.PropertyData;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.datamodel.QPathEntry;
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.jboss.cache.Cache;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import java.io.Serializable;
-
/**
* Created by The eXo Platform SAS.
*
@@ -77,7 +82,7 @@
super.setUp();
// JBossCache
- String jbcConfig = "/conf/portal/exojcr-jboss-cache-conf.xml";
+ String jbcConfig = "conf/portal/exojcr-jboss-cache-conf.xml";
cache = new DefaultCacheFactory<Serializable, Object>().createCache(jbcConfig);
@@ -108,23 +113,274 @@
super.tearDown();
}
+ private void treePrint(Node<Serializable, Object> node)
+ {
+ for (Node<Serializable, Object> child : node.getChildren())
+ {
+ System.out.println(child.toString());
+ for (Serializable key : child.getKeys())
+ {
+ System.out.println("\t" + key + "=" + child.get(key));
+ }
+ if (!child.isLeaf())
+ {
+ treePrint(child);
+ }
+ }
+ }
+
+ private Fqn<String> makeFqn(Node<Serializable, Object> root, QPath nodePath)
+ {
+ QPathEntry[] path = nodePath.getEntries();
+ String[] fqns = new String[path.length];
+
+ for (int i = 0; i < path.length; i++)
+ {
+ fqns[i] = path[i].getAsString(true);
+ }
+
+ return Fqn.fromRelativeFqn(root.getFqn(), Fqn.fromElements(fqns));
+ }
+
public void testAddNode() throws Exception
{
- // add
- conn.add(new TransientNodeData(QPath.parse("[]:node:1"), "1", 1, Constants.NT_UNSTRUCTURED, new InternalQName[0],
- 0, Constants.ROOT_UUID, new AccessControlList()));
-
+ // 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()));
+
+ // 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()));
+
// test
- tree.getChildren();
+ treePrint(tree);
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode =
+ tree.getChild(Fqn.fromElements(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
+ .getAsString(true)));
+
+ assertNotNull("Node expected", rootNode);
+
+ assertEquals("Childs expected", 2, rootNode.getChildren().size());
+
+ for (Node<Serializable, Object> child : rootNode.getChildren())
+ {
+ String nodeName = child.getFqn().getLastElementAsString();
+ String nodeId = (String)child.get(JBossCacheStorageConnection.ITEM_ID);
+ if (nodeName.equals(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)))
+ {
+ assertEquals("Node id wrong", node1id, nodeId);
+ }
+ else if (nodeName
+ .equals(Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1]
+ .getAsString(true)))
+ {
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, nodeId);
+ }
+ else
+ {
+ fail("Wrong Node name " + nodeName);
+ }
+ }
}
- public void testGetChildNodesData()
+ public void testAddProperty() 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()));
- // prepare
+ // 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));
+ // 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));
+
+ // test
+ 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", 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);
+
+ pid = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
+ assertNotNull("Property ID should exists", pid);
+ assertEquals("Property ID wrong", propId2, pid);
+
+ // TODO check order
+ int index = 0;
+ for (Serializable key : rootNode.getKeys())
+ {
+ //System.out.println(key);
+ //index++;
+ }
+ }
+
+ public void testDeleteNode() 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()));
+
+ // 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()));
+
+ // get root node ([]:1)
+ Node<Serializable, Object> rootNode =
+ tree.getChild(Fqn.fromElements(Constants.ROOT_PATH.getEntries()[Constants.ROOT_PATH.getEntries().length - 1]
+ .getAsString(true)));
+
+ assertEquals("Childs expected", 2, rootNode.getChildren().size());
+
+ // delete /node
+ conn.delete(new TransientNodeData(node1path, node1id, 1, Constants.NT_UNSTRUCTURED, new InternalQName[0], 0,
+ Constants.ROOT_UUID, new AccessControlList()));
+
+ // test
+ treePrint(tree);
+
+ Node<Serializable, Object> node =
+ rootNode.getChild(Fqn
+ .fromElements(node1path.getEntries()[node1path.getEntries().length - 1].getAsString(true)));
+
+ assertNull("Node should be deleted", node);
+
+ assertEquals("Childs expected", 1, rootNode.getChildren().size());
+
+ Node<Serializable, Object> child = rootNode.getChildren().iterator().next();
+ assertEquals("Node name wrong",
+ Constants.JCR_SYSTEM_PATH.getEntries()[Constants.JCR_SYSTEM_PATH.getEntries().length - 1].getAsString(true),
+ child.getFqn().getLastElementAsString());
+
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, (String)child.get(JBossCacheStorageConnection.ITEM_ID));
+ }
+
+ public void testGetChildNodes() throws Exception
+ {
+ // prepare using JCR WDC API (not right way, JBC API better... but read assumes the write works)
+ // 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()));
+
+ // 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()));
+
// check
+ List<NodeData> childs =
+ conn.getChildNodesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+ assertEquals("Childs amount wrong", 2, childs.size());
+
+ for (NodeData child : childs)
+ {
+ if (child.getQPath().equals(node1path))
+ {
+ assertEquals("Node id wrong", node1id, child.getIdentifier());
+ }
+ else if (child.getQPath().equals(Constants.JCR_SYSTEM_PATH))
+ {
+ assertEquals("Node id wrong", Constants.SYSTEM_UUID, child.getIdentifier());
+ }
+ else
+ {
+ fail("Wrong Node found");
+ }
+ }
}
+ public void testGetChildProperties() throws Exception
+ {
+ // prepare using JCR WDC API (not right way, JBC API better... but read assumes the write works)
+ // 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 (/jcr:primaryType)
+ String propId1 = "1";
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, Constants.JCR_PRIMARYTYPE), propId1,
+ 1, 1, Constants.ROOT_UUID, false));
+
+ // 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));
+
+ // add property (/a)
+ String propId3 = "3";
+ InternalQName propName3 = InternalQName.parse("[]a");
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName3), propId3, 1, 1,
+ Constants.ROOT_UUID, false));
+
+ // add property (/b)
+ String propId4 = "4";
+ InternalQName propName4 = InternalQName.parse("[]b");
+ conn.add(new TransientPropertyData(QPath.makeChildPath(Constants.ROOT_PATH, propName4), propId4, 1, 1,
+ Constants.ROOT_UUID, false));
+
+ // check
+ treePrint(tree);
+
+ List<PropertyData> childs =
+ conn.getChildPropertiesData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID, 1,
+ Constants.NT_UNSTRUCTURED, new InternalQName[0], 0, Constants.ROOT_PARENT_UUID, new AccessControlList()));
+
+ assertEquals("Childs amount wrong", 4, childs.size());
+
+ for (PropertyData child : childs)
+ {
+ if (child.getQPath().getName().equals(Constants.JCR_PRIMARYTYPE))
+ {
+ assertEquals("Property id wrong", propId1, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(Constants.JCR_MIXINTYPES))
+ {
+ assertEquals("Property id wrong", propId2, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(propName3))
+ {
+ assertEquals("Property id wrong", propId3, child.getIdentifier());
+ }
+ else if (child.getQPath().getName().equals(propName4))
+ {
+ assertEquals("Property id wrong", propId4, child.getIdentifier());
+ }
+ else
+ {
+ fail("Wrong Property found");
+ }
+ }
+ }
+
}
More information about the exo-jcr-commits
mailing list