Add OVSDB Select Operation 61/6861/8
authorDave Tucker <dave@dtucker.co.uk>
Sat, 10 May 2014 18:08:00 +0000 (19:08 +0100)
committerDave Tucker <djt@redhat.com>
Thu, 22 May 2014 13:00:44 +0000 (14:00 +0100)
Add the OVSDB Select Operation to the new OVSDB Library

Change-Id: Ie59033a7628f02e85bc3babba56c5723406398d0
Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
library/src/main/java/org/opendaylight/ovsdb/lib/operations/Operations.java
library/src/main/java/org/opendaylight/ovsdb/lib/operations/Select.java [new file with mode: 0644]
library/src/test/java/org/opendaylight/ovsdb/lib/OvsDBClientTestIT.java

index 206ddd64e28ca95306bf3b1a8d69cf02fbfd0cee..e4102aaec81ecb512ac8802e6a9d6334d67f51e1 100644 (file)
@@ -21,11 +21,11 @@ public class Operations {
         return new Insert<>(schema);
     }
 
-    public  <E extends TableSchema<E>> Update<E> update(TableSchema<E> schema) {
+    public <E extends TableSchema<E>> Update<E> update(TableSchema<E> schema) {
         return new Update<>(schema);
     }
 
-    public  <E extends TableSchema<E>> Delete<E> delete(TableSchema<E> schema) {
+    public <E extends TableSchema<E>> Delete<E> delete(TableSchema<E> schema) {
         return new Delete<>(schema);
     }
 
@@ -36,4 +36,9 @@ public class Operations {
     public Abort abort() {
         return new Abort();
     }
+
+    public <E extends TableSchema<E>> Select<E> select(TableSchema<E> schema) {
+        return new Select<>(schema);
+    }
+
 }
\ No newline at end of file
diff --git a/library/src/main/java/org/opendaylight/ovsdb/lib/operations/Select.java b/library/src/main/java/org/opendaylight/ovsdb/lib/operations/Select.java
new file mode 100644 (file)
index 0000000..d3d7805
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2014 Red Hat Inc,
+ *
+ * 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 : Dave Tucker
+ *
+ */
+package org.opendaylight.ovsdb.lib.operations;
+
+import com.google.common.collect.Lists;
+import org.opendaylight.ovsdb.lib.notation.Condition;
+import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
+import org.opendaylight.ovsdb.lib.schema.TableSchema;
+
+import java.util.List;
+
+public class Select<E extends TableSchema<E>> extends Operation<E> implements ConditionalOperation {
+
+    public static final String SELECT = "select";
+    List<Condition> where = Lists.newArrayList();
+    private List<String> columns = Lists.newArrayList();
+
+    public Select on(TableSchema schema){
+        this.setTableSchema(schema);
+        return this;
+    }
+
+    public Select(TableSchema<E> schema) {
+        super(schema, SELECT);
+    }
+
+    public <D, C extends TableSchema<C>> Select<E> column(ColumnSchema<C, D> columnSchema) {
+        columns.add(columnSchema.getName());
+        return this;
+    }
+
+    public Where where(Condition condition) {
+        where.add(condition);
+        return new Where(this);
+    }
+
+    public List<String> getColumns() {
+        return columns;
+    }
+
+    public void setColumns(List<String> columns) {
+        this.columns = columns;
+    }
+
+    @Override
+    public void addCondition(Condition condition) {
+        this.where.add(condition);
+    }
+
+    public List<Condition> getWhere() {
+        return where;
+    }
+
+    public void setWhere(List<Condition> where) {
+        this.where = where;
+    }
+}
\ No newline at end of file
index db69e1522c9ac5905871eaa65dc270778403c2da..66e97563a6631bc5bc1e61597aeef6292ac7f72b 100644 (file)
@@ -67,6 +67,10 @@ public class OvsDBClientTestIT extends OvsdbTestBase {
                         .where(name.opEqual("br-int"))
                         //.and(name.opEqual("br-int"))
                         .operation())
+                .add(op.select(bridge)
+                        .column(name)
+                        .where(name.opEqual("br-int"))
+                        .operation())
                 .add(op.commit(true))
                 .execute();