Author: dkuleshov
Date: 2012-01-20 10:48:48 -0500 (Fri, 20 Jan 2012)
New Revision: 5491
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestMoveNode.java
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingTest.java
Log:
EXOJCR-1454: fixed sub-nodes' reloading to item reference pool
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2012-01-20
15:27:50 UTC (rev 5490)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SessionDataManager.java 2012-01-20
15:48:48 UTC (rev 5491)
@@ -43,6 +43,7 @@
import org.exoplatform.services.jcr.impl.core.version.VersionImpl;
import org.exoplatform.services.jcr.impl.dataflow.ItemDataMoveVisitor;
import org.exoplatform.services.jcr.impl.dataflow.TransientNodeData;
+import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
import
org.exoplatform.services.jcr.impl.dataflow.persistent.LocalWorkspaceDataManagerStub;
import org.exoplatform.services.jcr.impl.dataflow.session.SessionChangesLog;
import org.exoplatform.services.jcr.impl.dataflow.session.TransactionableDataManager;
@@ -1149,34 +1150,6 @@
}
}
- void reloadPool(ItemData fromItem) throws RepositoryException
- {
- Collection<ItemImpl> pooledItems = itemsPool.getAll();
- for (ItemImpl item : pooledItems)
- {
- if (item != null)
- {
- if (item.getInternalPath().isDescendantOf(fromItem.getQPath())
- || item.getInternalPath().equals(fromItem.getQPath()))
- {
- ItemData ri = getItemData(item.getInternalIdentifier());
- if (ri != null)
- {
- itemsPool.reload(ri);
- }
- else
- {
- // the item is invalid, case of version restore - the item from non
- // current version
- item.invalidate();
- }
-
- invalidated.add(item);
- }
- }
- }
- }
-
/**
* Reloads item in pool.
*
@@ -1208,6 +1181,10 @@
invalidated.add(item);
}
}
+ else if (state.isPathChanged())
+ {
+ reloadDescendants(state.getOldPath(), state.getData().getQPath());
+ }
}
}
@@ -1433,6 +1410,10 @@
while (nextSibling != null &&
!nextSibling.getIdentifier().equals(cause.getIdentifier())
&& !nextSibling.getIdentifier().equals(reindexedId))
{
+ QPath siblingOldPath =
+ QPath.makeChildPath(nextSibling.getQPath().makeParentPath(),
nextSibling.getQPath().getName(), nextSibling
+ .getQPath().getIndex());
+
// update with new index
QPath siblingPath =
QPath.makeChildPath(nextSibling.getQPath().makeParentPath(),
nextSibling.getQPath().getName(), nextSibling
@@ -1450,6 +1431,8 @@
itemsPool.reload(reindexed);
+ reloadDescendants(siblingOldPath, siblingPath);
+
// next...
nextSibling =
(NodeData)dataManager.getItemData(parentNodeData, new
QPathEntry(nextSibling.getQPath().getName(),
@@ -1797,13 +1780,10 @@
*/
void rollback(ItemData item) throws InvalidItemStateException, RepositoryException
{
-
// remove from changes log (Session pending changes)
PlainChangesLog slog = changesLog.pushLog(item.getQPath());
SessionChangesLog changes = new SessionChangesLog(slog.getAllStates(), session);
- StringBuilder exceptions = new StringBuilder();
-
for (Iterator<ItemImpl> removedIter = invalidated.iterator();
removedIter.hasNext();)
{
ItemImpl removed = removedIter.next();
@@ -1811,46 +1791,46 @@
QPath removedPath = removed.getLocation().getInternalPath();
ItemState rstate = changes.getItemState(removedPath);
- if (rstate == null)
+ if (rstate != null)
{
- exceptions.append("Can't find removed item
").append(removed.getLocation().getAsString(false))
- .append(" in changes for rollback.\n");
- continue;
- }
+ if (rstate.isRenamed() || rstate.isPathChanged())
+ {
+ // find DELETED
+ rstate = changes.findItemState(rstate.getData().getIdentifier(), false,
new int[]{ItemState.DELETED});
+ if (rstate == null)
+ {
+ continue;
+ }
+ }
- if (rstate.isRenamed())
- {
- // find DELETED
- rstate = changes.findItemState(rstate.getData().getIdentifier(), false, new
int[]{ItemState.DELETED});
- if (rstate == null)
+ NodeData parent =
(NodeData)transactionableManager.getItemData(rstate.getData().getParentIdentifier());
+ if (parent != null)
{
- exceptions.append("Can't find removed item (of move operation)
")
- .append(removed.getLocation().getAsString(false)).append(" in
changes for rollback.\n");
- continue;
- }
+ ItemData persisted =
+ transactionableManager.getItemData(parent,
rstate.getData().getQPath().getEntries()[rstate.getData()
+ .getQPath().getEntries().length - 1],
ItemType.getItemType(rstate.getData()));
+
+ if (persisted != null)
+ {
+ // reload item data
+ removed.loadData(persisted);
+ }
+ } // else it's transient item
}
-
- NodeData parent =
(NodeData)transactionableManager.getItemData(rstate.getData().getParentIdentifier());
- if (parent != null)
+ else
{
- ItemData persisted =
- transactionableManager.getItemData(parent,
rstate.getData().getQPath().getEntries()[rstate.getData()
- .getQPath().getEntries().length - 1],
ItemType.getItemType(rstate.getData()));
+ // No states for items left usecase
+ ItemData persisted =
transactionableManager.getItemData(removed.getData().getIdentifier());
if (persisted != null)
{
// reload item data
removed.loadData(persisted);
}
- } // else it's transient item
+ }
removedIter.remove();
}
-
- if (exceptions.length() > 0 && log.isDebugEnabled())
- {
- log.warn(exceptions);
- }
}
/**
@@ -2312,6 +2292,50 @@
}
/**
+ * Reload item's descendants in item reference pool
+ *
+ * @param parentOld old item's QPath to get descendants out of item reference
pool
+ * @param parent new item's QPath to set for reloaded descendants
+ * @throws RepositoryException
+ */
+ private void reloadDescendants(QPath parentOld, QPath parent) throws
RepositoryException
+ {
+ List<ItemImpl> items = itemsPool.getDescendats(parentOld);
+
+ for (ItemImpl item : items)
+ {
+ ItemData oldItemData = item.getData();
+
+ int relativeDegree = oldItemData.getQPath().getDepth() - parentOld.getDepth();
+ QPath newQPath = QPath.makeChildPath(parent,
oldItemData.getQPath().getRelPath(relativeDegree));
+
+ ItemData newItemData;
+ if (oldItemData.isNode())
+ {
+ NodeData oldNodeData = (NodeData)oldItemData;
+ newItemData =
+ new TransientNodeData(newQPath, oldNodeData.getIdentifier(),
oldNodeData.getPersistedVersion(),
+ oldNodeData.getPrimaryTypeName(), oldNodeData.getMixinTypeNames(),
oldNodeData.getOrderNumber(),
+ oldNodeData.getParentIdentifier(), oldNodeData.getACL());
+ }
+ else
+ {
+ PropertyData oldPropertyData = (PropertyData)oldItemData;
+ newItemData =
+ new TransientPropertyData(newQPath, oldPropertyData.getIdentifier(),
+ oldPropertyData.getPersistedVersion(), oldPropertyData.getType(),
+ oldPropertyData.getParentIdentifier(), oldPropertyData.isMultiValued(),
oldPropertyData.getValues());
+ }
+
+ ItemImpl reloadedItem = reloadItem(newItemData);
+ if (reloadedItem != null)
+ {
+ invalidated.add(reloadedItem);
+ }
+ }
+ }
+
+ /**
* Pool for touched items.
*/
protected final class ItemReferencePool
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestMoveNode.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestMoveNode.java 2012-01-20
15:27:50 UTC (rev 5490)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestMoveNode.java 2012-01-20
15:48:48 UTC (rev 5491)
@@ -19,8 +19,13 @@
package org.exoplatform.services.jcr.impl.core;
import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.config.SimpleParameterEntry;
+import org.exoplatform.services.jcr.config.WorkspaceEntry;
+import org.exoplatform.services.jcr.core.ManageableRepository;
import org.exoplatform.services.jcr.datamodel.InternalQName;
import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
+import org.exoplatform.services.jcr.util.TesterConfigurationHelper;
import java.io.FileInputStream;
import java.io.InputStream;
@@ -272,4 +277,37 @@
compareStream(new FileInputStream(filesList.get(i)),
contentNode.getProperty("jcr:data").getStream());
}
}
+
+ /**
+ * We have A/B moved to C/B without generation events for B.
+ * Will checked if B reloaded its data.
+ */
+ public void testMoveWithoutGenerationChangesForAllSubTree() throws Exception
+ {
+ TesterConfigurationHelper helper = TesterConfigurationHelper.getInstance();
+ WorkspaceEntry wsEntry = helper.createWorkspaceEntry(true, null);
+ wsEntry.getContainer().getParameters()
+ .add(new
SimpleParameterEntry(WorkspaceDataContainer.TRIGGER_EVENTS_FOR_DESCENDENTS_ON_RENAME,
"false"));
+
+ ManageableRepository repository = helper.createRepository(container, true, null);
+ helper.addWorkspace(repository, wsEntry);
+
+ SessionImpl session = (SessionImpl)repository.login(credentials,
wsEntry.getName());
+
+ Node nodeA = session.getRootNode().addNode("A");
+ Node nodeB = nodeA.addNode("B");
+ session.save();
+
+ assertEquals("/A/B", nodeB.getPath());
+
+ session.move("/A", "/C");
+
+ assertEquals("/C/B", nodeB.getPath());
+ assertEquals("/C", nodeA.getPath());
+
+ session.refresh(false);
+
+ assertEquals("/A/B", nodeB.getPath());
+ assertEquals("/A", nodeA.getPath());
+ }
}
Modified:
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingTest.java
===================================================================
---
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingTest.java 2012-01-20
15:27:50 UTC (rev 5490)
+++
jcr/branches/1.15.x/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/RemoveSameNameSiblingTest.java 2012-01-20
15:48:48 UTC (rev 5491)
@@ -135,8 +135,6 @@
session.save();
assertEquals("Same-name siblings path must be reindexed",
"/u1/child[2]", n3.getPath());
- assertEquals("Same-name siblings path must be reindexed",
"/u1/child[3]/n1/n2", n3_n1n2.getPath());
- session.refresh(true);
assertEquals("Same-name siblings path must be reindexed",
"/u1/child[2]/n1/n2", n3_n1n2.getPath());
n3_n1n2 = n3.getNode("n1").getNode("n2");