Author: pnedonosko
Date: 2009-11-09 09:04:45 -0500 (Mon, 09 Nov 2009)
New Revision: 509
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: get childs impls
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-09
13:04:57 UTC (rev 508)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-09
14:04:45 UTC (rev 509)
@@ -148,6 +148,7 @@
}
// remove child on Parent
+ // TODO validate does deleted
boolean removed =
parent.removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length
- 1]));
}
@@ -172,6 +173,7 @@
}
// remove from parent's properties attr
+ // TODO validate does deleted
Object prev = parent.remove(data.getQPath().getName().getAsString());
// remove from PROPERTIES
@@ -187,7 +189,7 @@
Node<Serializable, Object> parentNode =
nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
if (parentNode == null)
{
- throw new IllegalStateException("Get child Nodes error: parent not found
" + parent.getQPath().getAsString());
+ throw new IllegalStateException("FATAL Get child Nodes: parent not found
" + parent.getQPath().getAsString());
}
Set<Node<Serializable, Object>> childNodes = parentNode.getChildren();
@@ -195,13 +197,18 @@
List<NodeData> childs = new ArrayList<NodeData>();
for (Node<Serializable, Object> child : childNodes)
{
- String childId = (String)child.get(ITEM_ID);
+ String nodeId = (String)child.get(ITEM_ID);
+ if (nodeId == null)
+ {
+ throw new RepositoryException("FATAL Child Node Id key is null. Parent
" + parent.getQPath().getAsString());
+ }
// TODO NodeData or PropertyData? As ItemData check then and cast.
- Node<Serializable, Object> node =
nodesRoot.getChild(makeNodeFqn(childId));
+ Node<Serializable, Object> node =
nodesRoot.getChild(makeNodeFqn(nodeId));
if (node == null)
{
- throw new RepositoryException("Child node is null. Parent " +
parent.getQPath().getAsString());
+ throw new RepositoryException("FATAL Node record not found(" +
nodeId + "), but listed in proprties of "
+ + parent.getQPath().getAsString());
}
NodeData nodeData = (NodeData)node.get(ITEM_DATA);
if (nodeData == null)
@@ -236,11 +243,10 @@
*/
public List<PropertyData> getChildPropertiesData(NodeData parent) throws
RepositoryException, IllegalStateException
{
- //TODO treeRoot.getChild(f) possible if f not a direct child???
Node<Serializable, Object> parentNode =
nodesRoot.getChild(makeNodeFqn(parent.getIdentifier()));
if (parentNode == null)
{
- throw new IllegalStateException("Get child Properties error: parent not
found "
+ throw new IllegalStateException("FATAL Get child Properties: parent not
found "
+ parent.getQPath().getAsString());
}
@@ -248,21 +254,26 @@
for (Serializable key : parentNode.getKeys())
{
- if (!key.equals(ITEM_ID))
+ if (!key.equals(ITEM_DATA))
{
String propId = (String)parentNode.get(key);
+ if (propId == null)
+ {
+ throw new RepositoryException("FATAL Child Property Id key is null.
Parent "
+ + parent.getQPath().getAsString());
+ }
Node<Serializable, Object> prop =
propsRoot.getChild(makePropFqn(propId));
if (prop == null)
{
- throw new RepositoryException("Child property is null. Parent "
+ parent.getQPath().getAsString());
+ throw new RepositoryException("FATAL Property record not found("
+ propId
+ + "), but listed in proprties of " +
parent.getQPath().getAsString());
}
PropertyData propData = (PropertyData)prop.get(ITEM_DATA);
if (propData == null)
{
- // TODO should not occurs by contract
- throw new RepositoryException("Child property data is null. Parent
" + parent.getQPath().getAsString());
+ throw new RepositoryException("FATAL Property data is null. Parent
" + parent.getQPath().getAsString());
}
childs.add(propData);
@@ -293,15 +304,31 @@
if (childNode != null)
{
String nodeId = (String)childNode.get(ITEM_ID);
- Node<Serializable, Object> node =
nodesRoot.getChild(makeNodeFqn(nodeId));
- Object itemData = node.get(ITEM_DATA);
- if (itemData != null)
+ if (nodeId != null)
{
- return (NodeData)itemData;
+ Node<Serializable, Object> node =
nodesRoot.getChild(makeNodeFqn(nodeId));
+ if (node != null)
+ {
+ Object itemData = node.get(ITEM_DATA);
+ if (itemData != null)
+ {
+ return (NodeData)itemData;
+ }
+ else
+ {
+ throw new RepositoryException("FATAL NodeData empty " +
parentData.getQPath()
+ + name.getAsString(true));
+ }
+ }
+ else
+ {
+ throw new RepositoryException("FATAL Node record not found (" +
name.getAsString(true)
+ + "), but listed in childs of " + parentData.getQPath());
+ }
}
else
{
- throw new RepositoryException("FATAL NodeData empty " +
parentData.getQPath() + name.getAsString(true));
+ throw new RepositoryException("FATAL Node Id empty " +
parentData.getQPath() + name.getAsString(true));
}
}
else
@@ -314,14 +341,31 @@
String propId = (String)parent.get(name.getAsString(false));
if (propId != null)
{
- return (PropertyData)propsRoot.get(makePropFqn(propId));
+ Node<Serializable, Object> prop =
propsRoot.getChild(makePropFqn(propId));
+ if (prop != null)
+ {
+ Object itemData = prop.get(ITEM_DATA);
+ if (itemData != null)
+ {
+ return (PropertyData)itemData;
+ }
+ else
+ {
+ throw new RepositoryException("FATAL PropertyData empty "
+ parentData.getQPath()
+ + name.getAsString(true));
+ }
+ }
+ else
+ {
+ throw new RepositoryException("FATAL Property record not
found(" + name.getAsString(true)
+ + "), but listed in proprties of " +
parentData.getQPath().getAsString());
+ }
}
}
else
{
- // TODO validation of ParentNotFound for Property
- throw new RepositoryException("Parent not found " +
parentData.getIdentifier() + ", "
- + parentData.getQPath().getAsString());
+ throw new RepositoryException("FATAL Parent not found " +
parentData.getQPath().getAsString() + " for "
+ + name.getAsString(true));
}
}
@@ -404,38 +448,20 @@
throw new InvalidItemStateException("Node was updated previously or removed
" + data.getQPath().getAsString());
}
- QPath prevPath;
-
- Object itemData = node.get(ITEM_DATA);
- if (itemData == null)
- {
- throw new RepositoryException("FATAL NodeData empty " +
node.getFqn());
- }
-
- if (itemData instanceof NodeData)
- {
- prevPath = ((NodeData)itemData).getQPath();
- }
- else
- {
- throw new RepositoryException("FATAL Node data is not NodeData " +
node.getFqn());
- }
-
if (data.getParentIdentifier() != null)
{
// check if parent is cached
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 RepositoryException("FATAL Node's parent not found "
+ data.getQPath().getAsString());
}
- // update child on Parent (remove prev, add new)
+ // 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]));
- // 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]));
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-09
13:04:57 UTC (rev 508)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnectionTest.java 2009-11-09
14:04:45 UTC (rev 509)
@@ -54,7 +54,9 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import java.io.IOException;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.util.List;
/**
@@ -90,16 +92,16 @@
cache = new DefaultCacheFactory<Serializable,
Object>().createCache(jbcConfig);
+ // run cache
+ cache.create();
+ cache.start();
+
Node<Serializable, Object> cacheRoot = cache.getRoot();
// prepare cache structures
nodes = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.NODES));
props = cacheRoot.addChild(Fqn.fromString(JBossCacheStorage.PROPS));
- // run cache
- cache.create();
- cache.start();
-
// JCR connection
conn = new JBossCacheStorageConnection(cache, nodes, props);
}
@@ -150,13 +152,39 @@
assertEquals("Node path wrong", nodePath, data.getQPath());
}
+ private void checkProp(String propId, QPath propPath, Object propValue) throws
UnsupportedEncodingException,
+ IllegalStateException, IOException
+ {
+ Node<Serializable, Object> prop = props.getChild(Fqn.fromElements(propId));
+ Object dataObject = prop.get(JBossCacheStorage.ITEM_DATA);
+ assertNotNull("Property item data should exists", dataObject);
+ assertTrue("Property item data is not a Property", dataObject instanceof
PropertyData);
+
+ PropertyData propData = (PropertyData)dataObject;
+ assertEquals("Property id wrong", propId, propData.getIdentifier());
+ assertEquals("Property path wrong", propPath, propData.getQPath());
+ assertEquals("Property Value wrong", propValue, new
String(propData.getValues().get(0).getAsByteArray(),
+ Constants.DEFAULT_ENCODING));
+ }
+
+ private void checkChildProp(Node<Serializable, Object> node, InternalQName
propName, String propId, QPath propPath,
+ Object propValue) throws UnsupportedEncodingException, IllegalStateException,
IOException
+ {
+ String pid = (String)node.get(propName.getAsString());
+
+ assertNotNull("Property ID should exists", pid);
+ assertEquals("Property ID wrong", propId, pid);
+
+ checkProp(propId, propPath, propValue);
+ }
+
private void checkChildNode(Node<Serializable, Object> rootNode, String childId,
QPath childPath)
{
- checkChildNode(rootNode, childId, childPath, null, null);
+ checkChildNode(rootNode, childId, childPath, -1, -1);
}
- private void checkChildNode(Node<Serializable, Object> rootNode, String childId,
QPath childPath, Integer orderNum,
- Integer version)
+ private void checkChildNode(Node<Serializable, Object> rootNode, String childId,
QPath childPath, int orderNum,
+ int version)
{
Node<Serializable, Object> childNode =
rootNode.getChild(Fqn
@@ -164,7 +192,7 @@
assertNotNull("Child Node should exists", childNode);
String childNodeId = (String)childNode.get(JBossCacheStorage.ITEM_ID);
- Node<Serializable, Object> node =
props.getChild(Fqn.fromElements(childNodeId));
+ Node<Serializable, Object> node =
nodes.getChild(Fqn.fromElements(childNodeId));
assertNotNull("Node by ID should exists", node);
Object childNodeObject = node.get(JBossCacheStorage.ITEM_DATA);
@@ -173,14 +201,14 @@
assertEquals("Node id wrong", childId, childNodeData.getIdentifier());
assertEquals("Node path wrong", childPath, childNodeData.getQPath());
- if (orderNum != null)
+ if (orderNum >= 0)
{
- //assertEquals("Node order number wrong", orderNum,
childNodeData.getOrderNumber());
+ assertEquals("Node order number wrong", orderNum,
childNodeData.getOrderNumber());
}
- if (version != null)
+ if (version >= 0)
{
- //assertEquals("Node persisted version wrong", version,
childNodeData.getPersistedVersion());
+ assertEquals("Node persisted version wrong", version,
childNodeData.getPersistedVersion());
}
}
@@ -238,21 +266,16 @@
propData2.setValue(new TransientValueData(propValue2));
conn.add(propData2);
- // check in nodes
- treePrint(nodes);
+ // check in props
+ treePrint(props);
Node<Serializable, Object> rootNode =
nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
assertEquals("Attributes ammount wrong", 3, rootNode.getKeys().size());
- String pid1 = (String)rootNode.get(Constants.JCR_PRIMARYTYPE.getAsString());
- assertNotNull("Property ID should exists", pid1);
- assertEquals("Property ID wrong", propId1, pid1);
-
- String pid2 = (String)rootNode.get(Constants.JCR_MIXINTYPES.getAsString());
- assertNotNull("Property ID should exists", pid2);
- assertEquals("Property ID wrong", propId2, pid2);
-
+ checkChildProp(rootNode, Constants.JCR_PRIMARYTYPE, propId1, propPath1,
propValue1);
+ checkChildProp(rootNode, Constants.JCR_MIXINTYPES, propId2, propPath2,
propValue2);
+
// TODO check order
int index = 0;
for (Serializable key : rootNode.getKeys())
@@ -260,31 +283,6 @@
//System.out.println(key);
//index++;
}
-
- // check in props
- treePrint(props);
-
- Node<Serializable, Object> itemsProp1 =
props.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 =
props.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
@@ -437,45 +435,45 @@
checkChildNode(rootNode, node2id, node1path);
checkChildNode(rootNode, node3id, node3path);
-// Node<Serializable, Object> childNode1 =
-// rootNode.getChild(Fqn
-// .fromElements(node1path.getEntries()[node1path.getEntries().length -
1].getAsString(true)));
-//
-// assertNotNull("Child Node should exists", childNode1);
-// String childNode1id = (String)childNode1.get(JBossCacheStorage.ITEM_ID);
-// Node<Serializable, Object> node1 =
props.getChild(Fqn.fromElements(childNode1id));
-// assertNotNull("Node by ID should exists", node1);
-//
-// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
-// assertTrue("Node item data is not a Node", childNode1Object instanceof
NodeData);
-// assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
-// assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
-//
-// // get /snsNode:2 from childs of root /
-// Node<Serializable, Object> childNode2 =
-// rootNode.getChild(Fqn
-// .fromElements(node2path.getEntries()[node2path.getEntries().length -
1].getAsString(true)));
-//
-// assertNotNull("Child Node should exists", childNode2);
-// String childNode2id = (String)childNode2.get(JBossCacheStorage.ITEM_ID);
-// Node<Serializable, Object> node2 =
props.getChild(Fqn.fromElements(childNode2id));
-// assertNotNull("Node by ID should exists", node2);
-//
-// Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
-// assertTrue("Node item data is not a Node", childNode1Object instanceof
NodeData);
-// assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
-// assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
-//
-// assertEquals("Child expected", 3, rootNode.getChildren().size());
-//
-// Node<Serializable, Object> itemNode =
nodes.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());
+ // Node<Serializable, Object> childNode1 =
+ // rootNode.getChild(Fqn
+ // .fromElements(node1path.getEntries()[node1path.getEntries().length -
1].getAsString(true)));
+ //
+ // assertNotNull("Child Node should exists", childNode1);
+ // String childNode1id = (String)childNode1.get(JBossCacheStorage.ITEM_ID);
+ // Node<Serializable, Object> node1 =
props.getChild(Fqn.fromElements(childNode1id));
+ // assertNotNull("Node by ID should exists", node1);
+ //
+ // Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+ // assertTrue("Node item data is not a Node", childNode1Object
instanceof NodeData);
+ // assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
+ // assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
+ //
+ // // get /snsNode:2 from childs of root /
+ // Node<Serializable, Object> childNode2 =
+ // rootNode.getChild(Fqn
+ // .fromElements(node2path.getEntries()[node2path.getEntries().length -
1].getAsString(true)));
+ //
+ // assertNotNull("Child Node should exists", childNode2);
+ // String childNode2id = (String)childNode2.get(JBossCacheStorage.ITEM_ID);
+ // Node<Serializable, Object> node2 =
props.getChild(Fqn.fromElements(childNode2id));
+ // assertNotNull("Node by ID should exists", node2);
+ //
+ // Object childNode1Object = node1.get(JBossCacheStorage.ITEM_DATA);
+ // assertTrue("Node item data is not a Node", childNode1Object
instanceof NodeData);
+ // assertEquals("Node id wrong", node2id,
((NodeData)childNode1Object).getIdentifier());
+ // assertEquals("Node path wrong", node2path,
((NodeData)childNode1Object).getQPath());
+ //
+ // assertEquals("Child expected", 3,
rootNode.getChildren().size());
+ //
+ // Node<Serializable, Object> itemNode =
nodes.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
@@ -498,29 +496,14 @@
propDataU.setValue(new TransientValueData(propValueU));
conn.update(propDataU);
- // check in tree
- treePrint(nodes);
-
+ // check
+ treePrint(props);
+
Node<Serializable, Object> rootNode =
nodes.getChild(Fqn.fromElements(Constants.ROOT_UUID));
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(nodes);
-
- Node<Serializable, Object> itemsProp1 =
props.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));
+
+ checkChildProp(rootNode, Constants.JCR_PRIMARYTYPE, propId1, propPath1,
propValueU);
}
public void testGetNodeByName() throws Exception
@@ -569,6 +552,9 @@
conn.add(new TransientPropertyData(propPath2, propId2, 1, 1, Constants.ROOT_UUID,
false));
// check
+ treePrint(props);
+
+ // check
ItemData propItem =
conn.getItemData(new TransientNodeData(Constants.ROOT_PATH, Constants.ROOT_UUID,
1, Constants.NT_UNSTRUCTURED,
new InternalQName[0], 0, null, new AccessControlList()),
@@ -629,7 +615,7 @@
assertEquals("Proeprty path wrong", propPath1, propItem.getQPath());
}
- public void _testGetChildNodes() throws Exception
+ public void testGetChildNodes() throws Exception
{
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read
assumes the write works)
// add root (/)
@@ -672,7 +658,7 @@
}
}
- public void _testGetChildProperties() throws Exception
+ public void testGetChildProperties() throws Exception
{
// TODO prepare using JCR WDC API (not a right way, JBC API better... but read
assumes the write works)
// add root (/)
@@ -703,6 +689,7 @@
// check
treePrint(nodes);
+ treePrint(props);
List<PropertyData> childs =
conn.getChildPropertiesData(new TransientNodeData(Constants.ROOT_PATH,
Constants.ROOT_UUID, 1,