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>
this.exceptions = exceptions;
}
-
}
return name;
}
+ public ColumnType getType() { return type; }
+
public Condition opEqual(D data) {
return new Condition(this.getName(), Function.EQUALS, data);
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
/**
* @author araveendrann
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")) {
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
/**
* @author araveendrann
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")) {