Also, introduced strong typing for the TypedBaseTable.
Change-Id: I42818bf944862135959edd226e0a761bb1248aa2
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
*/
package org.opendaylight.ovsdb.lib.operations;
+import java.util.Collection;
import java.util.Map;
import org.opendaylight.ovsdb.lib.notation.Column;
+import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Maps;
private Map<String, Object> row = Maps.newHashMap();
- public Insert<E> on(TableSchema schema){
+ public Insert<E> on(TableSchema<E> schema){
this.setTableSchema(schema);
return this;
}
super(schema, INSERT);
}
+ public Insert(TableSchema<E> schema, Row<E> row) {
+ super(schema, INSERT);
+ Collection<Column<E,?>> columns = row.getColumns();
+ for (Column<E,?> column : columns) {
+ this.value(column);
+ }
+ }
+
+ public Insert(TypedBaseTable<E> typedTable) {
+ this(typedTable.getSchema(), typedTable.getRow());
+ }
+
public <D, C extends TableSchema<C>> Insert<E> value(ColumnSchema<C, D> columnSchema, D value) {
Object untypedValue = columnSchema.getNormalizeData(value);
row.put(columnSchema.getName(), untypedValue);
package org.opendaylight.ovsdb.lib.operations;
+import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.schema.TableSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable;
public class Operations {
public static Operations op = new Operations();
return new Insert<>(schema);
}
+ public <E extends TableSchema<E>> Insert<E> insert(TypedBaseTable<E> typedTable) {
+ return new Insert<>(typedTable);
+ }
+
+ public <E extends TableSchema<E>> Insert<E> insert(TableSchema<E> schema, Row<E> row) {
+ return new Insert<>(schema, row);
+ }
+
public <E extends TableSchema<E>> Update<E> update(TableSchema<E> schema) {
return new Update<>(schema);
}
package org.opendaylight.ovsdb.lib.schema.typed;
public enum MethodType {
- GETCOLUMN, GETDATA, SETDATA, GETTABLESCHEMA
+ GETCOLUMN, GETDATA, SETDATA, GETTABLESCHEMA, GETROW
}
package org.opendaylight.ovsdb.lib.schema.typed;
import org.opendaylight.ovsdb.lib.notation.Column;
+import org.opendaylight.ovsdb.lib.notation.Row;
import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
+import org.opendaylight.ovsdb.lib.schema.TableSchema;
-public interface TypedBaseTable {
+public interface TypedBaseTable <E extends TableSchema<E>> {
@TypedColumn(name="", method=MethodType.GETTABLESCHEMA)
- GenericTableSchema getSchema();
+ E getSchema();
+
+ @TypedColumn(name="", method=MethodType.GETROW)
+ Row<E> getRow();
@TypedColumn(name="_uuid", method=MethodType.GETDATA)
public UUID getUuid();
@TypedColumn(name="_uuid", method=MethodType.GETCOLUMN)
- public Column<GenericTableSchema, UUID> getUuidColumn();
+ public Column<E, UUID> getUuidColumn();
@TypedColumn(name="_version", method=MethodType.GETDATA)
public UUID getVersion();
@TypedColumn(name="_version", method=MethodType.GETCOLUMN)
- public Column<GenericTableSchema, UUID> getVersionColumn();
+ public Column<E, UUID> getVersionColumn();
}
private static final String GET_STARTS_WITH="get";
private static final String SET_STARTS_WITH="set";
private static final String GETCOLUMN_ENDS_WITH="Column";
+ private static final String GETROW_ENDS_WITH="Row";
private static <T> String getTableName (Class<T> klazz) {
TypedTable typedTable = klazz.getAnnotation(TypedTable.class);
return false;
}
+ private static boolean isGetRow (Method method) {
+ TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
+ if (typedColumn != null) {
+ return typedColumn.method().equals(MethodType.GETROW) ? true : false;
+ }
+
+ if (method.getName().startsWith(GET_STARTS_WITH) && method.getName().endsWith(GETROW_ENDS_WITH)) {
+ return true;
+ }
+ return false;
+ }
+
private static boolean isGetColumn (Method method) {
TypedColumn typedColumn = method.getAnnotation(TypedColumn.class);
if (typedColumn != null) {
return row.getColumn(columnSchema).getData();
}
+ private Object processGetRow() throws Throwable {
+ return row;
+ }
+
private Object processGetColumn(Method method) throws Throwable {
String columnName = getColumnName(method);
checkSchemaVersion(dbSchema, method);
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (isGetTableSchema(method)) {
return processGetTableSchema();
+ } else if (isGetRow(method)) {
+ return processGetRow();
} else if (isSetData(method)) {
return processSetData(proxy, method, args);
} else if(isGetData(method)) {
Logger logger = LoggerFactory.getLogger(OvsdbClientTestITTyped.class);
OvsdbClient ovs;
DatabaseSchema dbSchema = null;
- static String testBridgeName = "br-test";
+ static String testBridgeName = "br_test";
static UUID testBridgeUuid = null;
@Test
int insertOperationIndex = 0;
TransactionBuilder transactionBuilder = ovs.transactBuilder()
- .add(op.insert(rBridge.getSchema())
- .withId(namedUuid)
- .value(rBridge.getNameColumn()))
- .add(op.update(rBridge.getSchema())
- .set(rBridge.getStatusColumn())
- .set(rBridge.getFloodVlansColumn())
- .where(rBridge.getNameColumn().getSchema().opEqual(rBridge.getName()))
- .and(rBridge.getNameColumn().getSchema().opEqual(rBridge.getName())).build())
+ .add(op.insert(rBridge)
+ .withId(namedUuid))
.add(op.mutate(ovsTable)
.addMutation(bridges, Mutator.INSERT, Sets.newHashSet(new UUID(namedUuid))));
* This class is a typed interface to the Bridge Table
*/
@TypedTable(name="Bridge", database="Open_vSwitch")
-public interface Bridge extends TypedBaseTable {
+public interface Bridge extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
* TODO : Fill up the missing Columns and include Supported DB Version
*/
@TypedTable(name="Capability", database="Open_vSwitch")
-public interface Capability extends TypedBaseTable {
+public interface Capability extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="details", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, Map<String, String>> getDetailsColumn();
*/
@TypedTable(name="Controller", database="Open_vSwitch")
-public interface Controller extends TypedBaseTable {
+public interface Controller extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="target", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, String> getTargetColumn();
* TODO : Fill up the missing Columns and include Supported DB Version
*/
@TypedTable(name="Flow_Sample_Collector_Set", database="Open_vSwitch")
-public interface FlowSampleCollectorSet extends TypedBaseTable {
+public interface FlowSampleCollectorSet extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="id", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, Integer> getIdColumn();
@TypedColumn(name="id", method=MethodType.SETDATA)
* This class is a typed interface to the Flow_Table Table
*/
@TypedTable(name="Flow_Table", database="Open_vSwitch", fromVersion="6.5.0")
-public interface FlowTable extends TypedBaseTable {
+public interface FlowTable extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="flow_limit", method=MethodType.GETCOLUMN, fromVersion="6.5.0")
public Column<GenericTableSchema, Integer> getFlowLimitColumn() ;
* This class is a typed interface to the IPFIX Table
*/
@TypedTable(name="IPFIX", database="Open_vSwitch", fromVersion="7.1.0")
-public interface IPFIX extends TypedBaseTable {
+public interface IPFIX extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="targets", method=MethodType.GETCOLUMN, fromVersion="7.1.0")
public Column<GenericTableSchema, Set<String>> getTargetsColumn();
* This class is a typed interface to the Bridge Table
*/
@TypedTable(name="Interface", database="Open_vSwitch")
-public interface Interface extends TypedBaseTable {
+public interface Interface extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
* TODO : Fill up the missing Columns and include Supported DB Version
*/
@TypedTable(name="Manager", database="Open_vSwitch")
-public interface Manager extends TypedBaseTable {
+public interface Manager extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="target", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, String> getTargetColumn() ;
@TypedColumn(name="target", method=MethodType.SETDATA)
* TODO : Fill up the missing Columns and include Supported DB Version
*/
@TypedTable(name="Mirror", database="Open_vSwitch")
-public interface Mirror extends TypedBaseTable {
+public interface Mirror extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, String> getNameColumn();
* This class is a typed interface to the NetFlow Table
*/
@TypedTable(name="NetFlow", database="Open_vSwitch", fromVersion="1.0.0")
-public interface NetFlow extends TypedBaseTable {
+public interface NetFlow extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="targets", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Set<String>> getTargetsColumn();
* This class is a typed interface to the Open_vSwitch table
*/
@TypedTable(name="Open_vSwitch", database="Open_vSwitch")
-public interface OpenVSwitch extends TypedBaseTable {
+public interface OpenVSwitch extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="bridges", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Set<UUID>> getBridgesColumn();
* This class is a typed interface to the Port Table
*/
@TypedTable(name="Port", database="Open_vSwitch")
-public interface Port extends TypedBaseTable {
+public interface Port extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
*/
@TypedTable(name="Qos", database="Open_vSwitch")
-public interface Qos extends TypedBaseTable {
+public interface Qos extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="queues", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, Map<Integer, UUID>> getQueuesColumn() ;
@TypedColumn(name="queues", method=MethodType.SETDATA)
*/
@TypedTable(name="Queue", database="Open_vSwitch")
-public interface Queue extends TypedBaseTable {
+public interface Queue extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="dscp", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, Set<Integer>> getDscpColumn() ;
@TypedColumn(name="dscp", method=MethodType.SETDATA)
* This class is a typed interface to the SFlow Table
*/
@TypedTable(name="sFlow", database="Open_vSwitch", fromVersion="1.0.0")
-public interface SFlow extends TypedBaseTable {
+public interface SFlow extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="targets", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Set<String>> getTargetsColumn() ;
@TypedColumn(name="targets", method=MethodType.SETDATA, fromVersion="1.0.0")
* TODO : Fill up the missing Columns and include Supported DB Version
*/
@TypedTable(name="SSL", database="Open_vSwitch")
-public interface SSL extends TypedBaseTable {
+public interface SSL extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="ca_cert", method=MethodType.GETCOLUMN)
public Column<GenericTableSchema, String> getCaCertColumn() ;
@TypedColumn(name="ca_cert", method=MethodType.SETDATA)
int insertOperationIndex = 0;
TransactionBuilder transactionBuilder = ovs.transactBuilder()
- .add(op.insert(bridge.getSchema())
- .withId(testBridgeName)
- .value(bridge.getNameColumn()))
+ .add(op.insert(bridge)
+ .withId(testBridgeName))
.add(op.update(bridge.getSchema())
.set(bridge.getStatusColumn())
.set(bridge.getFloodVlansColumn())
*/
public <T extends TypedBaseTable> MonitorRequest<GenericTableSchema> getAllColumnsMonitorRequest (Class <T> klazz) {
TypedBaseTable table = ovs.createTypedRowWrapper(klazz);
- GenericTableSchema bridgeSchema = table.getSchema();
+ GenericTableSchema bridgeSchema = (GenericTableSchema) table.getSchema();
Set<String> columns = bridgeSchema.getColumns();
MonitorRequestBuilder<GenericTableSchema> bridgeBuilder = MonitorRequestBuilder.builder(table.getSchema());
for (String column : columns) {
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Arp_Sources_Local", database="hardware_vtep", fromVersion="1.2.0")
-public interface ArpSourcesLocal extends TypedBaseTable {
+public interface ArpSourcesLocal extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="src_mac", method=MethodType.GETCOLUMN, fromVersion="1.2.0")
public Column<GenericTableSchema, String> getSrcMacColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Arp_Sources_Remote", database="hardware_vtep", fromVersion="1.2.0")
-public interface ArpSourcesRemote extends TypedBaseTable {
+public interface ArpSourcesRemote extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="src_mac", method=MethodType.GETCOLUMN, fromVersion="1.2.0")
public Column<GenericTableSchema, String> getSrcMacColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Global", database="hardware_vtep", fromVersion="1.0.0")
-public interface Global extends TypedBaseTable {
+public interface Global extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="managers", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Set<UUID>> getManagersColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Logical_Binding_Stats", database="hardware_vtep", fromVersion="1.0.0")
-public interface LogicalBindingStats extends TypedBaseTable {
+public interface LogicalBindingStats extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="bytes_from_local", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Integer> getBytesFromLocalColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Logical_Router", database="hardware_vtep", fromVersion="1.0.0")
-public interface LogicalRouter extends TypedBaseTable {
+public interface LogicalRouter extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Logical_Switch", database="hardware_vtep", fromVersion="1.0.0")
-public interface LogicalSwitch extends TypedBaseTable {
+public interface LogicalSwitch extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Manager", database="hardware_vtep", fromVersion="1.0.0")
-public interface Manager extends TypedBaseTable {
+public interface Manager extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="target", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getTargetColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Mcast_Macs_Local", database="hardware_vtep", fromVersion="1.0.0")
-public interface McastMacsLocal extends TypedBaseTable {
+public interface McastMacsLocal extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="MAC", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getMacColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Mcast_Macs_Remote", database="hardware_vtep", fromVersion="1.0.0")
-public interface McastMacsRemote extends TypedBaseTable {
+public interface McastMacsRemote extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="MAC", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getMacColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Physical_Locator", database="hardware_vtep", fromVersion="1.0.0")
-public interface PhysicalLocator extends TypedBaseTable {
+public interface PhysicalLocator extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="encapsulation_type", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getEncapsulationTypeColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Physical_Locator_Set", database="hardware_vtep", fromVersion="1.0.0")
-public interface PhysicalLocatorSet extends TypedBaseTable {
+public interface PhysicalLocatorSet extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="locators", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, Set<UUID>> getLocatorsColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Physical_Port", database="hardware_vtep", fromVersion="1.0.0")
-public interface PhysicalPort extends TypedBaseTable {
+public interface PhysicalPort extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Physical_Switch", database="hardware_vtep", fromVersion="1.0.0")
-public interface PhysicalSwitch extends TypedBaseTable {
+public interface PhysicalSwitch extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="name", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getNameColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Tunnel", database="hardware_vtep", fromVersion="1.3.0")
-public interface Tunnel extends TypedBaseTable {
+public interface Tunnel extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="local", method=MethodType.GETCOLUMN, fromVersion="1.3.0")
public Column<GenericTableSchema, UUID> getLocalColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Ucast_Macs_Local", database="hardware_vtep", fromVersion="1.0.0")
-public interface UcastMacsLocal extends TypedBaseTable {
+public interface UcastMacsLocal extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="MAC", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getMacColumn();
import org.opendaylight.ovsdb.lib.schema.typed.TypedTable;
@TypedTable(name="Ucast_Macs_Remote", database="hardware_vtep", fromVersion="1.0.0")
-public interface UcastMacsRemote extends TypedBaseTable {
+public interface UcastMacsRemote extends TypedBaseTable<GenericTableSchema> {
@TypedColumn(name="MAC", method=MethodType.GETCOLUMN, fromVersion="1.0.0")
public Column<GenericTableSchema, String> getMacColumn();