This is a fixup of the previous patch. The problem was expanding a merge
into a new node, which used a direct value propagation with a merge.
That is not correct, as the merge should be pushed via
ModificationApplyOperation, which in case of unkeyed lists will turn it
into a write.
Change-Id: I93c8be80e4467b5d3a1e20f26f5576bd701b1375
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit
dfe3c8193b6fd06090de7221e51e5857b75517b6)
final Collection<NormalizedNode<?, ?>> children = ((NormalizedNodeContainer) value).getValue();
for (NormalizedNode<?, ?> c : children) {
final PathArgument id = c.getIdentifier();
- modification.modifyChild(id, resolveChildOperation(id).getChildPolicy(), version);
+ modification.modifyChild(id, resolveChildOperation(id), version);
}
return applyTouch(modification, currentMeta, version);
}
final Collection<NormalizedNode<?, ?>> children, final Version version) {
for (NormalizedNode<?, ?> c : children) {
final ModificationApplyOperation childOp = resolveChildOperation(c.getIdentifier());
- final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp.getChildPolicy(), version);
+ final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp, version);
childOp.mergeIntoModifiedNode(childNode, c, version);
}
}
throw new IllegalArgumentException("Unsupported operation " + modification.getOperation());
}
- @SuppressWarnings({"rawtypes", "unchecked"})
- private NormalizedNode<?, ?> createEmptyValue(NormalizedNode<?, ?> value,
- Collection<NormalizedNode<?, ?>> children) {
- NormalizedNodeContainerBuilder builder = createBuilder(value);
- for (NormalizedNode<?, ?> child : children) {
- builder.removeChild(child.getIdentifier());
- }
- return builder.build();
- }
-
@Override
protected TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
/*
operation = potential.get();
++i;
- modification = modification.modifyChild(pathArg, operation.getChildPolicy(), version);
+ modification = modification.modifyChild(pathArg, operation, version);
}
return OperationWithModification.from(operation, modification);
final Optional<ModificationApplyOperation> potential = op.getApplyOperation().getChild(child);
if (potential.isPresent()) {
final ModificationApplyOperation operation = potential.get();
- final ModifiedNode modification = op.getModification().modifyChild(child, operation.getChildPolicy(),
+ final ModifiedNode modification = op.getModification().modifyChild(child, operation,
getParent().getVersion());
return OperationWithModification.from(operation, modification);
* changes modification type to {@link ModificationType#SUBTREE_MODIFIED}
*
* @param child child identifier, may not be null
- * @param childPolicy child tracking policy for the node we are looking for
+ * @param childOper Child operation
* @param modVersion Version allocated by the calling {@link InMemoryDataTreeModification}
* @return {@link ModifiedNode} for specified child, with {@link #getOriginal()}
* containing child metadata if child was present in original data.
*/
- ModifiedNode modifyChild(@Nonnull final PathArgument child, @Nonnull final ChildTrackingPolicy childPolicy,
+ ModifiedNode modifyChild(@Nonnull final PathArgument child, @Nonnull final ModificationApplyOperation childOper,
@Nonnull final Version modVersion) {
clearSnapshot();
if (operation == LogicalOperation.NONE) {
final Optional<TreeNode> currentMetadata = findOriginalMetadata(child, modVersion);
- final ModifiedNode newlyCreated = new ModifiedNode(child, currentMetadata, childPolicy);
+ final ModifiedNode newlyCreated = new ModifiedNode(child, currentMetadata, childOper.getChildPolicy());
if (operation == LogicalOperation.MERGE && value != null) {
/*
* We are attempting to modify a previously-unmodified part of a MERGE node. If the
@SuppressWarnings({ "rawtypes", "unchecked" })
final Optional<NormalizedNode<?, ?>> childData = ((NormalizedNodeContainer)value).getChild(child);
if (childData.isPresent()) {
- newlyCreated.updateValue(LogicalOperation.MERGE, childData.get());
+ childOper.mergeIntoModifiedNode(newlyCreated, childData.get(), modVersion);
}
}
@Override
protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
- // A merge operation is promoted into a write
- return applyWrite(modification, Optional.of(currentMeta), version);
+ throw new IllegalStateException(String.format("Merge of modification %s on unkeyed list should never be called",
+ modification));
}
@Override