BUG-509: node version is always required 92/7292/2
authorRobert Varga <rovarga@cisco.com>
Tue, 20 May 2014 13:42:32 +0000 (15:42 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 21 May 2014 15:20:29 +0000 (15:20 +0000)
This just clarifies the requirement to know the node version you are
attempting to build before instantiating a builder. Also remove some
unused methods.

Change-Id: I09406bbedee963624b43a280529d4b8cbc9931c6
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/SchemaAwareApplyOperation.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreMetadataNode.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/StoreNodeCompositeBuilder.java

index ca53712..c3c0273 100644 (file)
@@ -272,8 +272,7 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
         @Override
         protected StoreMetadataNode applyWrite(final NodeModification modification,
                 final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
-            UnsignedLong nodeVersion = subtreeVersion;
-            return StoreMetadataNode.builder().setNodeVersion(nodeVersion).setSubtreeVersion(subtreeVersion)
+            return StoreMetadataNode.builder(subtreeVersion).setSubtreeVersion(subtreeVersion)
                     .setData(modification.getWrittenValue()).build();
         }
 
@@ -366,8 +365,7 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
 
             @SuppressWarnings("rawtypes")
             NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue);
-            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder) //
-                    .setNodeVersion(nodeVersion) //
+            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.create(nodeVersion, dataBuilder) //
                     .setSubtreeVersion(subtreeVersion);
 
             return mutateChildren(modification.getModifications(), newValueMeta, builder, nodeVersion);
@@ -388,8 +386,8 @@ abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
 
             @SuppressWarnings("rawtypes")
             NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData());
-            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder, currentMeta)
-                    .setIdentifier(modification.getIdentifier()).setNodeVersion(currentMeta.getNodeVersion())
+            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.create(dataBuilder, currentMeta)
+                    .setIdentifier(modification.getIdentifier())
                     .setSubtreeVersion(updatedSubtreeVersion);
 
             return mutateChildren(modification.getModifications(), currentMeta, builder, updatedSubtreeVersion);
index 77186a6..3faeabb 100644 (file)
@@ -49,11 +49,11 @@ class StoreMetadataNode implements Immutable, Identifiable<PathArgument> {
                 Collections.<PathArgument, StoreMetadataNode>emptyMap());
     }
 
-    public static Builder builder() {
-        return new Builder();
+    public static Builder builder(final UnsignedLong version) {
+        return new Builder(version);
     }
 
-    public static Builder builder(StoreMetadataNode node) {
+    public static Builder builder(final StoreMetadataNode node) {
         return new Builder(node);
     }
 
@@ -100,8 +100,7 @@ class StoreMetadataNode implements Immutable, Identifiable<PathArgument> {
 
     public static final StoreMetadataNode createRecursively(final NormalizedNode<?, ?> node,
             final UnsignedLong nodeVersion, final UnsignedLong subtreeVersion) {
-        Builder builder = builder() //
-                .setNodeVersion(nodeVersion) //
+        Builder builder = builder(nodeVersion) //
                 .setSubtreeVersion(subtreeVersion) //
                 .setData(node);
         if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
@@ -117,30 +116,22 @@ class StoreMetadataNode implements Immutable, Identifiable<PathArgument> {
 
     public static class Builder {
 
-        private UnsignedLong nodeVersion;
+        private final UnsignedLong nodeVersion;
         private UnsignedLong subtreeVersion;
         private NormalizedNode<?, ?> data;
         private Map<PathArgument, StoreMetadataNode> children;
         private boolean dirty = false;
 
-        private Builder() {
+        private Builder(final UnsignedLong version) {
+            this.nodeVersion = Preconditions.checkNotNull(version);
             children = new HashMap<>();
         }
 
-        private Builder(StoreMetadataNode node) {
+        private Builder(final StoreMetadataNode node) {
+            this.nodeVersion = node.getNodeVersion();
             children = new HashMap<>(node.children);
         }
 
-        public UnsignedLong getVersion() {
-            return nodeVersion;
-
-        }
-
-        public Builder setNodeVersion(final UnsignedLong version) {
-            this.nodeVersion = version;
-            return this;
-        }
-
         public Builder setSubtreeVersion(final UnsignedLong version) {
             this.subtreeVersion = version;
             return this;
index 6bce4ff..19debbb 100644 (file)
@@ -26,12 +26,12 @@ class StoreNodeCompositeBuilder {
 
     private final NormalizedNodeContainerBuilder data;
 
-    private StoreNodeCompositeBuilder(final NormalizedNodeContainerBuilder nodeBuilder) {
-        this.metadata = StoreMetadataNode.builder();
+    private StoreNodeCompositeBuilder(final UnsignedLong version, final NormalizedNodeContainerBuilder nodeBuilder) {
+        this.metadata = StoreMetadataNode.builder(version);
         this.data = Preconditions.checkNotNull(nodeBuilder);
     }
 
-    public StoreNodeCompositeBuilder(NormalizedNodeContainerBuilder nodeBuilder, StoreMetadataNode currentMeta) {
+    private StoreNodeCompositeBuilder(final NormalizedNodeContainerBuilder nodeBuilder, final StoreMetadataNode currentMeta) {
         this.metadata = StoreMetadataNode.builder(currentMeta);
         this.data = Preconditions.checkNotNull(nodeBuilder);
     }
@@ -44,7 +44,7 @@ class StoreNodeCompositeBuilder {
     }
 
     @SuppressWarnings("unchecked")
-    public StoreNodeCompositeBuilder remove(PathArgument id) {
+    public StoreNodeCompositeBuilder remove(final PathArgument id) {
         metadata.remove(id);
         data.removeChild(id);
         return this;
@@ -54,11 +54,11 @@ class StoreNodeCompositeBuilder {
         return metadata.setData(data.build()).build();
     }
 
-    public static StoreNodeCompositeBuilder from(final NormalizedNodeContainerBuilder nodeBuilder) {
-        return new StoreNodeCompositeBuilder(nodeBuilder);
+    public static StoreNodeCompositeBuilder create(final UnsignedLong version, final NormalizedNodeContainerBuilder nodeBuilder) {
+        return new StoreNodeCompositeBuilder(version, nodeBuilder);
     }
 
-    public static StoreNodeCompositeBuilder from(final NormalizedNodeContainerBuilder nodeBuilder, StoreMetadataNode currentMeta) {
+    public static StoreNodeCompositeBuilder create(final NormalizedNodeContainerBuilder nodeBuilder, final StoreMetadataNode currentMeta) {
         return new StoreNodeCompositeBuilder(nodeBuilder, currentMeta);
     }
 
@@ -68,11 +68,6 @@ class StoreNodeCompositeBuilder {
         return this;
     }
 
-    public StoreNodeCompositeBuilder setNodeVersion(final UnsignedLong nodeVersion) {
-        metadata.setNodeVersion(nodeVersion);
-        return this;
-    }
-
     public StoreNodeCompositeBuilder setSubtreeVersion(final UnsignedLong updatedSubtreeVersion) {
         metadata.setSubtreeVersion(updatedSubtreeVersion);
         return this;