private String name;
private Version version;
- private Map<String, TableSchema> tables;
+ private final Map<String, TableSchema> tables;
- public DatabaseSchema(Map<String, TableSchema> tables) {
+ public DatabaseSchema(final Map<String, TableSchema> tables) {
this.tables = tables;
}
- public DatabaseSchema(String name, Version version, Map<String, TableSchema> tables) {
+ public DatabaseSchema(final String name, final Version version, final Map<String, TableSchema> tables) {
this.name = name;
this.version = version;
this.tables = tables;
return this.tables.keySet();
}
- public boolean hasTable(String table) {
+ public boolean hasTable(final String table) {
return this.getTables().contains(table);
}
- public <E extends TableSchema<E>> E table(String tableName, Class<E> clazz) {
+ public <E extends TableSchema<E>> E table(final String tableName, final Class<E> clazz) {
TableSchema<E> table = tables.get(tableName);
if (clazz.isInstance(table)) {
return createTableSchema(clazz, table);
}
- protected <E extends TableSchema<E>> E createTableSchema(Class<E> clazz, TableSchema<E> table) {
+ protected <E extends TableSchema<E>> E createTableSchema(final Class<E> clazz, final TableSchema<E> table) {
Constructor<E> declaredConstructor;
try {
declaredConstructor = clazz.getDeclaredConstructor(TableSchema.class);
}
//todo : this needs to move to a custom factory
- public static DatabaseSchema fromJson(String dbName, JsonNode json) {
+ public static DatabaseSchema fromJson(final String dbName, final JsonNode json) {
if (!json.isObject() || !json.has("tables")) {
throw new ParsingException("bad DatabaseSchema root, expected \"tables\" as child but was not found");
}
LOG.trace("Read schema for table[{}]:{}", table.getKey(), table.getValue());
//todo : this needs to done by a factory
- tables.put(table.getKey(), new GenericTableSchema().fromJson(table.getKey(), table.getValue()));
+ tables.put(table.getKey(), GenericTableSchema.fromJson(table.getKey(), table.getValue()));
}
return new DatabaseSchema(dbName, dbVersion, tables);
return name;
}
- public void setName(String name) {
+ public void setName(final String name) {
this.name = name;
}
return version;
}
- public void setVersion(Version version) {
+ public void setVersion(final Version version) {
this.version = version;
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.ovsdb.lib.schema;
import com.fasterxml.jackson.databind.JsonNode;
import org.slf4j.LoggerFactory;
public class GenericTableSchema extends TableSchema<GenericTableSchema> {
-
private static final Logger LOG = LoggerFactory.getLogger(GenericTableSchema.class);
- public GenericTableSchema() {
+ public GenericTableSchema(final String name) {
+ super(name);
}
- public GenericTableSchema(String tableName) {
- super(tableName);
+ public GenericTableSchema(final String name, final Map<String, ColumnSchema> columns) {
+ super(name, columns);
}
- public GenericTableSchema(TableSchema tableSchema) {
+ public GenericTableSchema(final TableSchema tableSchema) {
super(tableSchema.getName(), tableSchema.getColumnSchemas());
}
- public GenericTableSchema fromJson(String tableName, JsonNode json) {
-
+ public static GenericTableSchema fromJson(final String tableName, final JsonNode json) {
if (!json.isObject() || !json.has("columns")) {
throw new BadSchemaException("bad tableschema root, expected \"columns\" as child");
}
columns.put(column.getKey(), ColumnSchema.fromJson(column.getKey(), column.getValue()));
}
- this.setName(tableName);
- this.setColumns(columns);
- return this;
+ return new GenericTableSchema(tableName, columns);
}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.ovsdb.lib.schema;
import com.fasterxml.jackson.databind.JsonNode;
import org.opendaylight.ovsdb.lib.schema.BaseType.UuidBaseType;
import org.opendaylight.ovsdb.lib.schema.ColumnType.AtomicColumnType;
-
public abstract class TableSchema<E extends TableSchema<E>> {
private String name;
private Map<String, ColumnSchema> columns;
- public TableSchema() {
- }
-
- protected TableSchema(String name) {
+ protected TableSchema(final String name) {
this.name = name;
}
- public TableSchema(String name, Map<String, ColumnSchema> columns) {
+ protected TableSchema(final String name, final Map<String, ColumnSchema> columns) {
this.name = name;
this.columns = columns;
}
return columns;
}
- public boolean hasColumn(String column) {
+ public boolean hasColumn(final String column) {
return this.getColumns().contains(column);
}
-
- public ColumnType getColumnType(String column) {
+ public ColumnType getColumnType(final String column) {
return this.columns.get(column).getType();
}
- public <E extends TableSchema<E>> E as(Class<E> clazz) {
+ public <E extends TableSchema<E>> E as(final Class<E> clazz) {
try {
Constructor<E> instance = clazz.getConstructor(TableSchema.class);
return instance.newInstance(this);
return new Insert<>(this);
}
- public <D> ColumnSchema<E, Set<D>> multiValuedColumn(String column, Class<D> type) {
+ public <D> ColumnSchema<E, Set<D>> multiValuedColumn(final String column, final Class<D> type) {
//todo exception handling
ColumnSchema<E, Set<D>> columnSchema = columns.get(column);
return columnSchema;
}
- public <K,V> ColumnSchema<E, Map<K,V>> multiValuedColumn(String column, Class<K> keyType, Class<V> valueType) {
+ public <K,V> ColumnSchema<E, Map<K,V>> multiValuedColumn(final String column, final Class<K> keyType,
+ final Class<V> valueType) {
//todo exception handling
ColumnSchema<E, Map<K, V>> columnSchema = columns.get(column);
return columnSchema;
}
- public <D> ColumnSchema<E, D> column(String column, Class<D> type) {
+ public <D> ColumnSchema<E, D> column(final String column, final Class<D> type) {
//todo exception handling
ColumnSchema<E, D> columnSchema = columns.get(column);
return columnSchema;
}
- public ColumnSchema column(String column) {
+ public ColumnSchema column(final String column) {
return this.columns.get(column);
}
-
public String getName() {
return name;
}
- protected void setName(String name) {
+ protected void setName(final String name) {
this.name = name;
}
- protected void setColumns(Map<String, ColumnSchema> columns) {
+ protected void setColumns(final Map<String, ColumnSchema> columns) {
this.columns = columns;
}
- public TableUpdate<E> updatesFromJson(JsonNode value) {
+ public TableUpdate<E> updatesFromJson(final JsonNode value) {
TableUpdate<E> tableUpdate = new TableUpdate<>();
Iterator<Entry<String, JsonNode>> fields = value.fields();
while (fields.hasNext()) {
return tableUpdate;
}
- public Row<E> createRow(ObjectNode rowNode) {
+ public Row<E> createRow(final ObjectNode rowNode) {
List<Column<E, ?>> newColumns = new ArrayList<>();
for (Iterator<Map.Entry<String, JsonNode>> iter = rowNode.fields(); iter.hasNext();) {
Map.Entry<String, JsonNode> next = iter.next();
return new Row<>(this, newColumns);
}
- public List<Row<E>> createRows(JsonNode rowsNode) {
+ public List<Row<E>> createRows(final JsonNode rowsNode) {
List<Row<E>> rows = new ArrayList<>();
for (JsonNode rowNode : rowsNode.get("rows")) {
rows.add(createRow((ObjectNode)rowNode));