*/
package org.opendaylight.controller.md.sal.dom.store.impl;
-import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import java.util.Map.Entry;
final NodeModification rootModification;
final ModificationApplyOperation strategyTree;
- private boolean sealed = false;
+ private boolean sealed = false;
private MutableDataTree(final DataAndMetadataSnapshot snapshot, final ModificationApplyOperation strategyTree) {
this.snapshot = snapshot;
}
public Optional<NormalizedNode<?, ?>> read(final InstanceIdentifier path) {
- Entry<InstanceIdentifier, NodeModification> modification = TreeNodeUtils.findClosest(rootModification, path);
- return getModifiedVersion(path, modification);
- }
+ Entry<InstanceIdentifier, NodeModification> modification = TreeNodeUtils.findClosestsOrFirstMatch(rootModification, path, NodeModification.IS_TERMINAL_PREDICATE);
- private Optional<NormalizedNode<?, ?>> getModifiedVersion(final InstanceIdentifier path, final Entry<InstanceIdentifier, NodeModification> modification) {
Optional<StoreMetadataNode> result = resolveSnapshot(modification);
- if(result.isPresent()) {
+ if (result.isPresent()) {
NormalizedNode<?, ?> data = result.get().getData();
- return NormalizedNodeUtils.findNode(modification.getKey(),data, path);
+ return NormalizedNodeUtils.findNode(modification.getKey(), data, path);
}
return Optional.absent();
}
- private Optional<StoreMetadataNode> resolveSnapshot(final Entry<InstanceIdentifier, NodeModification> keyModification) {
+ private Optional<StoreMetadataNode> resolveSnapshot(
+ final Entry<InstanceIdentifier, NodeModification> keyModification) {
InstanceIdentifier path = keyModification.getKey();
NodeModification modification = keyModification.getValue();
- return resolveSnapshot(path,modification);
+ return resolveSnapshot(path, modification);
}
- private Optional<StoreMetadataNode> resolveSnapshot(final InstanceIdentifier path, final NodeModification modification) {
+ private Optional<StoreMetadataNode> resolveSnapshot(final InstanceIdentifier path,
+ final NodeModification modification) {
try {
- return resolveModificationStrategy(path).apply(modification,modification.getOriginal());
+ Optional<Optional<StoreMetadataNode>> potentialSnapshot = modification.getSnapshotCache();
+ if(potentialSnapshot.isPresent()) {
+ return potentialSnapshot.get();
+ }
+ return resolveModificationStrategy(path).apply(modification, modification.getOriginal(),
+ StoreUtils.increase(snapshot.getMetadataTree().getSubtreeVersion()));
} catch (Exception e) {
- log.error("Could not create snapshot for {},",e);
+ log.error("Could not create snapshot for {}", path,e);
throw e;
}
}
private ModificationApplyOperation resolveModificationStrategy(final InstanceIdentifier path) {
- log.trace("Resolving modification apply strategy for {}",path);
- Optional<ModificationApplyOperation> strategy = TreeNodeUtils.findNode(strategyTree, path);
- checkArgument(strategy.isPresent(),"Provided path %s is not supported by data store. No schema available for it.",path);
- return strategy.get();
+ log.trace("Resolving modification apply strategy for {}", path);
+ return TreeNodeUtils.findNodeChecked(strategyTree, path);
}
- private NodeModification resolveModificationFor(final InstanceIdentifier path) {
+ private OperationWithModification resolveModificationFor(final InstanceIdentifier path) {
NodeModification modification = rootModification;
// We ensure strategy is present.
- resolveModificationStrategy(path);
+ ModificationApplyOperation operation = resolveModificationStrategy(path);
for (PathArgument pathArg : path.getPath()) {
modification = modification.modifyChild(pathArg);
}
- return modification;
+ return OperationWithModification.from(operation, modification);
}
public static MutableDataTree from(final DataAndMetadataSnapshot snapshot, final ModificationApplyOperation resolver) {
}
private void checkSealed() {
- checkState(!sealed , "Data Tree is sealed. No further modifications allowed.");
+ checkState(!sealed, "Data Tree is sealed. No further modifications allowed.");
+ }
+
+ protected NodeModification getRootModification() {
+ return rootModification;
}
+
+ @Override
+ public String toString() {
+ return "MutableDataTree [modification=" + rootModification + "]";
+ }
+
+
}