Author: skabashnyuk
Date: 2009-12-11 11:33:12 -0500 (Fri, 11 Dec 2009)
New Revision: 1010
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
Log:
EXOJCR-199: Nicolas suggestion applied
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-12-11
16:01:37 UTC (rev 1009)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-12-11
16:33:12 UTC (rev 1010)
@@ -174,7 +174,7 @@
if (data.getParentIdentifier() != null)
{
// check if parent is cached
- Node<Serializable, Object> parent =
nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
+ 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 "
@@ -491,7 +491,56 @@
*/
public ItemData getItemData(NodeData parentData, QPathEntry name) throws
RepositoryException, IllegalStateException
{
+ ItemData itemData = null;
+ //try as Node
+ String nodeId =
+ (String)cache.get(Fqn.fromRelativeFqn(Fqn.fromElements(JBossCacheStorage.NODES),
makeChildNodeFqn(parentData
+ .getIdentifier(), name)), ITEM_ID);
+ if (nodeId != null)
+ {
+ itemData =
+
(ItemData)cache.get(Fqn.fromRelativeFqn(Fqn.fromElements(JBossCacheStorage.NODES),
makeNodeFqn(nodeId)),
+ ITEM_DATA);
+ // nodeId found but item not exist's
+ if (itemData == null)
+ {
+ throw new RepositoryException("FATAL NodeData empty " +
parentData.getQPath() + name.getAsString(true));
+ }
+ }
+ else
+ {
+ // try as Property
+ String propId =
+
(String)cache.get(Fqn.fromRelativeFqn(Fqn.fromElements(JBossCacheStorage.NODES),
makeNodeFqn(parentData
+ .getIdentifier())), name.getAsString(false));
+ if (propId != null)
+ {
+ itemData =
+
(ItemData)cache.get(Fqn.fromRelativeFqn(Fqn.fromElements(JBossCacheStorage.PROPS),
makePropFqn(propId)),
+ ITEM_DATA);
+ // propId found but item not exist's
+ if (itemData == null)
+ {
+ throw new RepositoryException("FATAL PropertyData empty " +
parentData.getQPath()
+ + name.getAsString(true));
+ }
+
+ }
+ }
+ return itemData;
+ }
+
+ /**
+ * @deprecated version of getItemData(NodeData parentData, QPathEntry name) .
+ * Should be removed
+ * {@inheritDoc}
+ *
+ */
+ @Deprecated
+ public ItemData getItemData_old(NodeData parentData, QPathEntry name) throws
RepositoryException,
+ IllegalStateException
+ {
// try as Node
// TODO validate ParentNotFound for both Node and Property
Node<Serializable, Object> childNode =
nodesRoot.getChild(makeChildNodeFqn(parentData.getIdentifier(), name));
@@ -569,7 +618,6 @@
// + name.getAsString(true));
}
}
-
return null;
}
@@ -592,24 +640,24 @@
throw new RepositoryException("FATAL NodeData empty " +
identifier);
}
}
-
+
// TODO only Nodes by Id
-// else
-// {
-// Node<Serializable, Object> prop =
propsRoot.getChild(makePropFqn(identifier));
-// if (prop != null)
-// {
-// Object itemData = prop.get(ITEM_DATA);
-// if (itemData != null)
-// {
-// return (PropertyData)itemData;
-// }
-// else
-// {
-// throw new RepositoryException("FATAL PropertyData empty " +
identifier);
-// }
-// }
-// }
+ // else
+ // {
+ // Node<Serializable, Object> prop =
propsRoot.getChild(makePropFqn(identifier));
+ // if (prop != null)
+ // {
+ // Object itemData = prop.get(ITEM_DATA);
+ // if (itemData != null)
+ // {
+ // return (PropertyData)itemData;
+ // }
+ // else
+ // {
+ // throw new RepositoryException("FATAL PropertyData empty
" + identifier);
+ // }
+ // }
+ // }
return null;
}
@@ -622,7 +670,8 @@
{
ArrayList<PropertyData> references = new ArrayList<PropertyData>();
- Node<Serializable, Object> node =
this.refsRoot.getChild(Fqn.fromElements(IdTreeHelper.buildPath(nodeIdentifier)));
+ Node<Serializable, Object> node =
+
this.refsRoot.getChild(Fqn.fromElements(IdTreeHelper.buildPath(nodeIdentifier)));
if (node != null)
{
Set<Object> props = node.getChildrenNames();
@@ -1246,7 +1295,7 @@
for (String id : addSet)
{
Fqn nodeFqn = makeNodeFqn(id);
- Node<Serializable, Object> node = refsRoot.getChild(nodeFqn);
+ Node<Serializable, Object> node = refsRoot.getChild(nodeFqn);
if (node == null)
{
@@ -1313,7 +1362,7 @@
public List<LockData> getLocksData() throws RepositoryException
{
Set<Node<Serializable, Object>> lockSet = locksRoot.getChildren();
-
+
List<LockData> locksData = new ArrayList<LockData>();
for (Node<Serializable, Object> node : lockSet)
{
@@ -1328,38 +1377,40 @@
}
return locksData;
}
-
-
+
/**
* Traverse tree and getting all nodes without children.
*
* @param node
* @return
*/
- private Set<Node<Serializable, Object>> getNodes(Node<Serializable,
Object> node) {
- Set<Node<Serializable, Object>> lockSet = new
HashSet<Node<Serializable,Object>>();
-
+ private Set<Node<Serializable, Object>> getNodes(Node<Serializable,
Object> node)
+ {
+ Set<Node<Serializable, Object>> lockSet = new
HashSet<Node<Serializable, Object>>();
+
traverseTree(lockSet, node);
-
+
return lockSet;
}
-
- private void traverseTree(Set<Node<Serializable, Object>> resultSet,
Node<Serializable, Object> node) {
+
+ private void traverseTree(Set<Node<Serializable, Object>> resultSet,
Node<Serializable, Object> node)
+ {
Set<Node<Serializable, Object>> childNodes = node.getChildren();
-
- for (Node<Serializable, Object> childNode : childNodes)
+
+ for (Node<Serializable, Object> childNode : childNodes)
{
if (childNode.isLeaf())
{
resultSet.add(childNode);
- } else
+ }
+ else
{
- traverseTree(resultSet, childNode);
+ traverseTree(resultSet, childNode);
}
-
+
}
}
-
+
/**
* @see
org.exoplatform.services.jcr.storage.WorkspaceStorageConnection#addLockData(org.exoplatform.services.jcr.impl.core.lock.LockData)
*/
@@ -1372,7 +1423,7 @@
}
// addChild will add if absent or return old if present
Node<Serializable, Object> node =
locksRoot.addChild(Fqn.fromString(lockData.getNodeIdentifier()));
-
+
// this will prevent from deleting by eviction.
node.setResident(true);
@@ -1395,8 +1446,8 @@
// token is the same, then Lock is just refreshed. Putting new LockData.
if (!node.replace(JBossCacheStorage.LOCK_DATA, oldLockData, lockData))
{
- throw new LockException("Unable to re-write LockData. Possibly
LockData for the Node[" + lockData.getNodeIdentifier()
- + "] has just been changed!");
+ throw new LockException("Unable to re-write LockData. Possibly
LockData for the Node["
+ + lockData.getNodeIdentifier() + "] has just been
changed!");
}
}
}
@@ -1414,7 +1465,7 @@
}
locksRoot.removeChild(Fqn.fromString(identifier));
}
-
+
/**
* Will be removed empty tree.
*