[exo-jcr-commits] exo-jcr SVN: r718 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
do-not-reply at jboss.org
do-not-reply at jboss.org
Tue Nov 17 08:13:23 EST 2009
Author: sergiykarpenko
Date: 2009-11-17 08:13:23 -0500 (Tue, 17 Nov 2009)
New Revision: 718
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java
Log:
EXOJCR-245: JBossCacheStorageConnection remove() method implemented
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-17 13:01:05 UTC (rev 717)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/JBossCacheStorageConnection.java 2009-11-17 13:13:23 UTC (rev 718)
@@ -21,8 +21,10 @@
import org.exoplatform.services.jcr.datamodel.ItemData;
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.core.lock.LockData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
@@ -378,20 +380,20 @@
* {@inheritDoc}
*/
public void deleteNode(String identifier) throws RepositoryException, UnsupportedOperationException,
- InvalidItemStateException, IllegalStateException
+ InvalidItemStateException, IllegalStateException
{
// TODO Auto-generated method stub
-
+
}
/**
* {@inheritDoc}
*/
- public void deleteProperty(String identifier) throws RepositoryException,
- UnsupportedOperationException, InvalidItemStateException, IllegalStateException
+ public void deleteProperty(String identifier) throws RepositoryException, UnsupportedOperationException,
+ InvalidItemStateException, IllegalStateException
{
// TODO Auto-generated method stub
-
+
}
/**
@@ -449,9 +451,99 @@
public void rename(NodeData data) throws RepositoryException, UnsupportedOperationException,
InvalidItemStateException, IllegalStateException
{
+ //TODO we expecting that on session.move() there will be only one rename() method call
+
startBatch();
- // TODO move Node to a new position at the tree,
- // but prev location was in prev DELETE.
+
+ String nodeUUID = data.getIdentifier();
+
+ //1. Update renamed node and also get old parent node UUID
+ Node<Serializable, Object> node = nodesRoot.getChild(makeNodeFqn(nodeUUID));
+ if (node == null)
+ {
+ throw new RepositoryException("FATAL renamed node is not exist" + data.getQPath().getAsString());
+ }
+ String oldParentIdentifier = null;
+ Object itemData = node.put(ITEM_DATA, data);
+ if (itemData != null)
+ {
+ oldParentIdentifier = ((NodeData)itemData).getParentIdentifier();
+ }
+ else
+ {
+ throw new RepositoryException("FATAL NodeData is empty " + data.getQPath().getAsString());
+ }
+
+ // 2. remove renamed node from child list of previous parent node
+ // check if parent is cached
+ Node<Serializable, Object> oldparent = nodesRoot.getChild(makeNodeFqn(oldParentIdentifier));
+ if (oldparent == null)
+ {
+ throw new RepositoryException("Nodes old parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // remove child on old Parent
+ boolean removed =
+ oldparent.removeChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+ if (!removed)
+ {
+ throw new RepositoryException("Node was not removed from child list of old parent "
+ + data.getQPath().getAsString());
+ }
+
+ // 3. add node to child list of new parent node
+ if (data.getParentIdentifier() != null)
+ {
+ // check if parent is cached
+ Node<Serializable, Object> newparent = nodesRoot.getChild(makeNodeFqn(data.getParentIdentifier()));
+ if (newparent == null)
+ {
+ throw new RepositoryException("Nodes new parent doesn't exist " + data.getQPath().getAsString());
+ }
+
+ // add child to Parent
+ Node<Serializable, Object> childNode =
+ newparent.addChild(makeChildNodeFqn(data.getQPath().getEntries()[data.getQPath().getEntries().length - 1]));
+
+ // set child id attr
+ childNode.put(ITEM_ID, data.getIdentifier());
+ }
+
+ // 4. update all child nodes
+ Set<Node<Serializable, Object>> childNodes = node.getChildren();
+
+ for (Node<Serializable, Object> child : childNodes)
+ {
+ String childNodeId = (String)child.get(ITEM_ID);
+ if (childNodeId == null)
+ {
+ throw new RepositoryException("FATAL Child Node Id key is null. Parent " + data.getQPath().getAsString());
+ }
+
+ // TODO NodeData or PropertyData? As ItemData check then and cast.
+ Node<Serializable, Object> childnode = nodesRoot.getChild(makeNodeFqn(childNodeId));
+ if (childnode == null)
+ {
+ throw new RepositoryException("FATAL Node record not found(" + childNodeId + "), but listed in childs of "
+ + data.getQPath().getAsString());
+ }
+ NodeData nodeData = (NodeData)childnode.get(ITEM_DATA);
+ if (nodeData == null)
+ {
+ // TODO should not occurs by contract
+ throw new RepositoryException("Child node data is null. Parent " + data.getQPath().getAsString());
+ }
+
+ //repack child NodeData with new QPath
+ //TODO check it
+ QPath newPath = QPath.makeChildPath(data.getQPath(), nodeData.getQPath().getName());
+ TransientNodeData newNodeData =
+ new TransientNodeData(newPath, nodeData.getIdentifier(), nodeData.getPersistedVersion(), nodeData
+ .getPrimaryTypeName(), nodeData.getMixinTypeNames(), nodeData.getOrderNumber(), nodeData
+ .getParentIdentifier(), nodeData.getACL());
+ childnode.put(ITEM_DATA, newNodeData);
+ }
+
}
/**
More information about the exo-jcr-commits
mailing list