Merge "Added Mutate operation" into topic/schema
authorMadhu Venugopal <mavenugo@gmail.com>
Tue, 27 May 2014 21:00:01 +0000 (21:00 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 27 May 2014 21:00:01 +0000 (21:00 +0000)
library/src/main/java/org/opendaylight/ovsdb/lib/operations/Mutate.java [new file with mode: 0644]
library/src/main/java/org/opendaylight/ovsdb/lib/operations/Operations.java
library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java

diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/operations/Mutate.java b/library/src/main/java/org/opendaylight/ovsdb/lib/operations/Mutate.java
new file mode 100644 (file)
index 0000000..18805aa
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2014 Matt Oswalt
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Authors : Matt Oswalt
+ *
+ */
+package org.opendaylight.ovsdb.lib.operations;
+
+import com.google.common.collect.Lists;
+import org.opendaylight.ovsdb.lib.notation.Condition;
+import org.opendaylight.ovsdb.lib.notation.Mutation;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
+import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
+import org.opendaylight.ovsdb.lib.schema.TableSchema;
+
+import java.util.List;
+
+public class Mutate<E extends TableSchema<E>> extends Operation<E> implements ConditionalOperation {
+
+    public static final String MUTATE = "mutate";
+    List<Condition> where = Lists.newArrayList();
+    private List<Mutation> mutations = Lists.newArrayList();
+
+    public Mutate on(TableSchema schema){
+        this.setTableSchema(schema);
+        return this;
+    }
+
+    public Mutate(TableSchema<E> schema) {
+        super(schema, MUTATE);
+    }
+
+    public <T extends TableSchema<T>, D> Mutate<E> addMutation(ColumnSchema<T, D> columnSchema, Mutator mutator, D value) {
+        columnSchema.validate(value);
+        mutations.add(new Mutation(columnSchema.getName(), mutator, value));
+        return this;
+    }
+
+    public List<Mutation> getMutations() {
+        return mutations;
+    }
+
+    public void setMutations(List<Mutation> mutations) {
+        this.mutations = mutations;
+    }
+
+    @Override
+    public void addCondition(Condition condition) {
+        this.where.add(condition);
+    }
+
+    public Where where(Condition condition) {
+        this.where.add(condition);
+        return new Where(this);
+    }
+
+    public List<Condition> getWhere() {
+        return where;
+    }
+
+    public void setWhere(List<Condition> where) {
+        this.where = where;
+    }
+}
\ No newline at end of file
index 912ff67caa5d3c961cadc8bbfab0c0d08533ecdd..c88b0adecbdc5649d28bbe234e1ab4381aa5f50c 100644 (file)
@@ -29,6 +29,10 @@ public class Operations {
         return new Delete<>(schema);
     }
 
+    public <E extends TableSchema<E>> Mutate<E> mutate(TableSchema<E> schema) {
+        return new Mutate<>(schema);
+    }
+
     public Commit commit(Boolean durable) {
         return new Commit(durable);
     }
@@ -52,4 +56,4 @@ public class Operations {
     public Assert assertion(String lock) {
         return new Assert(lock);
     }
-}
\ No newline at end of file
+}
index c09afc1293219323526a7f1142ee278aae44e10d..2a25b22a64f68462590fa7afbbc1ba44380f3283 100644 (file)
@@ -30,6 +30,7 @@ import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
 import org.opendaylight.ovsdb.lib.message.TableUpdate;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.message.UpdateNotification;
+import org.opendaylight.ovsdb.lib.notation.Mutator;
 import org.opendaylight.ovsdb.lib.operations.OperationResult;
 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
@@ -77,6 +78,10 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
                         .column(name)
                         .where(name.opEqual("br-int"))
                         .operation())
+                .add(op.mutate(bridge)
+                        .addMutation(flood_vlans, Mutator.INSERT, Sets.newHashSet(100, 101, 4001))
+                        .where(name.opEqual("br-int"))
+                        .operation())
                 .add(op.commit(true))
                 .add(op.comment("Commiting the operation"))
                 .execute();