Add helper methods to meta/*Schema classes 36/5836/2
authorDave Tucker <dave.j.tucker@hp.com>
Tue, 1 Apr 2014 14:39:09 +0000 (15:39 +0100)
committerDave Tucker <dave@dtucker.co.uk>
Tue, 1 Apr 2014 19:40:07 +0000 (20:40 +0100)
Add the following helper methods to make error and type checking easier.

DatabaseSchema.getTables() - gets a List<String> of tables
DatabaseSchema.hasTable(String table) - returns true if the table exists
DatabaseSchema.getTable(String table) - returns the TableSchema object
TableSchema.getColumns() - gets a List<String> of columns
TableSchema.hasColumn(String column) - returns true if the column exists
TableSchema.getColumn(String column) - returns the ColumnSchema object
TableSchema.getColumnType(String column) - returns the ColumnType object
for the specified column

These calls are intended to be used for error/type checks. For example:

if (!device.hasTable("Open_vSwitch") {
    throw RuntimeException("This is not the vswitchd schema")
}

Change-Id: If9dd286c05a38d7f60a0ce63cd3148157e3b345e
Signed-off-by: Dave Tucker <dave.j.tucker@hp.com>
ovsdb/src/main/java/org/opendaylight/ovsdb/OpenVswitch.java
ovsdb/src/main/java/org/opendaylight/ovsdb/lib/meta/ColumnSchema.java
ovsdb/src/main/java/org/opendaylight/ovsdb/lib/meta/DatabaseSchema.java
ovsdb/src/main/java/org/opendaylight/ovsdb/lib/meta/TableSchema.java

index b38efc4cf62c048032dae2ce54c56876be985447..74c3368769fae33b1190ad43fafe7867b8576ac6 100644 (file)
@@ -266,5 +266,4 @@ public class OpenVswitch {
         this.exceptions = exceptions;
     }
 
-
 }
index 683dbea933810c9f3b6c7b5e2dc34d3a97d41406..cdabc6480c1db897770908cbc86a76a4104e8c44 100644 (file)
@@ -32,6 +32,8 @@ public class ColumnSchema<E extends TableSchema<E>, D> {
         return name;
     }
 
+    public ColumnType getType() { return type; }
+
     public Condition opEqual(D data) {
         return new Condition(this.getName(), Function.EQUALS, data);
     }
index e082b0907cc5a74fabc023683d0b255c8c6fe4b5..2492acfee1191a40e6bd53bc90174acf784d3150 100644 (file)
@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author araveendrann
@@ -23,6 +24,11 @@ public class DatabaseSchema {
         this.tables = tables;
     }
 
+    public Set<String> getTables() { return this.tables.keySet(); }
+
+    public boolean hasTable(String table) { return this.getTables().contains(table); }
+
+    public TableSchema getTable(String table) { return this.tables.get(table); }
 
     public static DatabaseSchema fromJson(JsonNode json) {
         if (!json.isObject() || !json.has("tables")) {
index 2547ac0b765c70a0390f0add42486ba16a056552..4ff640ba1bc89a5cd715ddd2be0667f51466940b 100644 (file)
@@ -9,6 +9,7 @@ import java.lang.reflect.Constructor;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * @author araveendrann
@@ -26,6 +27,14 @@ public class TableSchema<E extends TableSchema<E>> {
         this.columns = columns;
     }
 
+    public Set<String> getColumns() { return this.columns.keySet(); }
+
+    public boolean hasColumn(String column) { return this.getColumns().contains(column); }
+
+    public ColumnSchema getColumn(String column) { return this.columns.get(column); }
+
+    public ColumnType getColumnType(String column) { return this.columns.get(column).getType(); }
+
     public static TableSchema fromJson(String tableName, JsonNode json) {
 
         if (!json.isObject() || !json.has("columns")) {