}
protected void doUpdate(NodeData mergeNode, NodeData corrNode) throws RepositoryException
{
DataManager mergeDataManager = mergeSession.getTransientNodesManager().getTransactManager();
QPath mergePath = mergeNode.getQPath();
TransientNodeData mergedNode =
new TransientNodeData(mergePath, mergeNode.getIdentifier(), mergeNode.getPersistedVersion(),
corrNode.getPrimaryTypeName(), corrNode.getMixinTypeNames(), mergeNode.getOrderNumber(),
mergeNode.getParentIdentifier(), mergeNode.getACL());
if (!mergeNode.getIdentifier().equals(corrNode.getIdentifier()))
{
NodeData existedSameIdentifier = (NodeData)mergeDataManager.getItemData(corrNode.getIdentifier());
if (existedSameIdentifier != null)
{
// if an incoming node has the same
// UUID as a node already existing in this workspace,
// the already existing node is removed
RemoveVisitor remover = new RemoveVisitor();
existedSameIdentifier.accept(remover);
changes.addAll(remover.getRemovedStates());
}
}
changes.add(new ItemState(mergedNode, ItemState.UPDATED, true, mergeNode.getQPath(), true));
// replace set of properties of n with those of n'.
DataManager corrDataManager = corrSession.getTransientNodesManager().getTransactManager();
List<PropertyData> corrChildProps = corrDataManager.getChildPropertiesData(corrNode);
List<PropertyData> mergeChildProps = mergeDataManager.getChildPropertiesData(mergeNode);
Map<InternalQName, PropertyData> existedProps = new HashMap<InternalQName, PropertyData>();
for (PropertyData cp : mergeChildProps)
{
TransientPropertyData existed =
new TransientPropertyData(cp.getQPath(), cp.getIdentifier(), cp.getPersistedVersion(), cp.getType(),
cp.getParentIdentifier(), cp.isMultiValued(), copyValues(cp));
changes.add(new ItemState(existed, ItemState.DELETED, true, mergedNode.getQPath(), true));
existedProps.put(existed.getQPath().getName(), existed);
}
for (PropertyData cp : corrChildProps)
{
PropertyData existed = existedProps.get(cp.getQPath().getName());
TransientPropertyData mcp =
new TransientPropertyData(QPath.makeChildPath(mergePath, cp.getQPath().getName()), existed != null
? existed.getIdentifier() : cp.getIdentifier(), existed != null ? existed.getPersistedVersion()
: cp.getPersistedVersion(), cp.getType(), mergedNode.getIdentifier(), cp.isMultiValued(), copyValues(cp));
changes.add(new ItemState(mcp, ItemState.ADDED, true, mergedNode.getQPath(), true));
}
List<NodeData> childNodes = corrDataManager.getChildNodesData(corrNode);
parents.push(new ContextParent(mergedNode, childNodes, UPDATE));
// let S be the set of child nodes of n.
// let S' be the set of child nodes of n'.
// judging by the name of the child node: