Moved extract* methods to TyperUtils 86/15686/2
authorEd Warnicke <eaw@cisco.com>
Tue, 24 Feb 2015 23:42:55 +0000 (16:42 -0700)
committerEd Warnicke <eaw@cisco.com>
Wed, 25 Feb 2015 13:26:24 +0000 (06:26 -0700)
This was discussed with shague on #opendaylight-ovsdb

Change-Id: I5b5eff8eae5644695fe7a6a2eb9e2030621bff35
Signed-off-by: Ed Warnicke <eaw@cisco.com>
library/src/main/java/org/opendaylight/ovsdb/lib/schema/typed/TyperUtils.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeRemovedCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionUtils.java [deleted file]

index 40dc93f699488fed22143514f8c343199c464c54..f4c98f19208eec8cf283fc07e8f50de228913afc 100644 (file)
@@ -12,20 +12,26 @@ package org.opendaylight.ovsdb.lib.schema.typed;
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.opendaylight.ovsdb.lib.error.ColumnSchemaNotFoundException;
 import org.opendaylight.ovsdb.lib.error.SchemaVersionMismatchException;
 import org.opendaylight.ovsdb.lib.error.TableSchemaNotFoundException;
 import org.opendaylight.ovsdb.lib.error.TyperException;
 import org.opendaylight.ovsdb.lib.error.UnsupportedMethodException;
+import org.opendaylight.ovsdb.lib.message.TableUpdate;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
 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.notation.Version;
 import org.opendaylight.ovsdb.lib.schema.ColumnSchema;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
 import org.opendaylight.ovsdb.lib.schema.TableSchema;
 
+import com.google.common.base.Preconditions;
 import com.google.common.reflect.Reflection;
 
 public class TyperUtils {
@@ -371,4 +377,95 @@ public class TyperUtils {
         }
         );
     }
+
+    /**
+     * This method extracts all row updates of Class<T> klazz from a TableUpdates
+     * that correspond to insertion or updates of rows of type klazz.
+     * Example:
+     * <code>
+     * Map<UUID,Bridge> updatedBridges = extractRowsUpdated(Bridge.class,updates,dbSchema)
+     * </code>
+     *
+     * @param klazz Class for row type to be extracted
+     * @param updates TableUpdates from which to extract rowUpdates
+     * @param dbSchema Dbschema for the TableUpdates
+     * @return Map<UUID,T> for the type of things being sought
+     */
+    public static <T> Map<UUID,T> extractRowsUpdated(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+        Preconditions.checkNotNull(klazz);
+        Preconditions.checkNotNull(updates);
+        Preconditions.checkNotNull(dbSchema);
+        Map<UUID,T> result = new HashMap<UUID,T>();
+
+        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
+        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+            if(rowUpdate != null) {
+                if(rowUpdate.getNew() != null) {
+                    Row<GenericTableSchema> row = rowUpdate.getNew();
+                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * This method extracts all row updates of Class<T> klazz from a TableUpdates
+     * that correspond to removal of rows of type klazz.
+     * Example:
+     * <code>
+     * Map<UUID,Bridge> updatedBridges = extractRowsRemoved(Bridge.class,updates,dbSchema)
+     * </code>
+     *
+     * @param klazz Class for row type to be extracted
+     * @param updates TableUpdates from which to extract rowUpdates
+     * @param dbSchema Dbschema for the TableUpdates
+     * @return Map<UUID,T> for the type of things being sought
+     */
+    public static <T> Map<UUID,T> extractRowsRemoved(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+        Preconditions.checkNotNull(klazz);
+        Preconditions.checkNotNull(updates);
+        Preconditions.checkNotNull(dbSchema);
+        Map<UUID,T> result = new HashMap<UUID,T>();
+
+        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
+        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+            if(rowUpdate != null) {
+                if(rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
+                    Row<GenericTableSchema> row = rowUpdate.getOld();
+                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
+                }
+            }
+        }
+        return result;
+    }
+
+    /**
+     * This method extracts all RowUpdates of Class<T> klazz from a TableUpdates
+     * that correspond to rows of type klazz.
+     * Example:
+     * <code>
+     * Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> updatedBridges = extractRowsUpdates(Bridge.class,updates,dbSchema)
+     * </code>
+     *
+     * @param klazz Class for row type to be extracted
+     * @param updates TableUpdates from which to extract rowUpdates
+     * @param dbSchema Dbschema for the TableUpdates
+     * @return Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> for the type of things being sought
+     */
+    public static Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+        Preconditions.checkNotNull(klazz);
+        Preconditions.checkNotNull(updates);
+        Preconditions.checkNotNull(dbSchema);
+        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result = new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
+        TableUpdate<GenericTableSchema> update = updates.getUpdate(TyperUtils.getTableSchema(dbSchema, klazz));
+        if(update != null) {
+            Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
+            if(rows != null) {
+                result = rows;
+            }
+        }
+        return result;
+    }
+
 }
index e189b3a99cfde096678e383fd2d4c25d87965975..a5f50c49d398235447d3f3e3913b7f501f24705b 100644 (file)
@@ -6,6 +6,7 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
@@ -28,7 +29,7 @@ public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        Collection<Bridge> removedRows = TransactionUtils.extractRowsRemoved(Bridge.class, getUpdates(), getDbSchema()).values();
+        Collection<Bridge> removedRows = TyperUtils.extractRowsRemoved(Bridge.class, getUpdates(), getDbSchema()).values();
         for(Bridge bridge : removedRows) {
             InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(getKey(), bridge.getUuid());
             InstanceIdentifier<ManagedNodeEntry> mnIid = SouthboundMapper.createInstanceIndentifier(getKey())
index 8e2e6e44fe5f3d59d1c9199e2224de2f21ee530b..5edfe072262355f8885e42212efecd8177225fa0 100644 (file)
@@ -9,6 +9,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.ovsdb.lib.message.TableUpdates;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
 import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
@@ -40,7 +41,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        Collection<Bridge> updatedRows = TransactionUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema()).values();
+        Collection<Bridge> updatedRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema()).values();
         for(Bridge bridge : updatedRows) {
             final InstanceIdentifier<Node> nodePath = getKey().toInstanceIndentifier();
             Optional<Node> node = Optional.absent();
diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionUtils.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/TransactionUtils.java
deleted file mode 100644 (file)
index c283e12..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-package org.opendaylight.ovsdb.southbound.transactions.md;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.opendaylight.ovsdb.lib.message.TableUpdate;
-import org.opendaylight.ovsdb.lib.message.TableUpdates;
-import org.opendaylight.ovsdb.lib.notation.Row;
-import org.opendaylight.ovsdb.lib.notation.UUID;
-import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
-import org.opendaylight.ovsdb.lib.schema.GenericTableSchema;
-import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
-
-import com.google.common.base.Preconditions;
-
-public class TransactionUtils {
-
-    public static <T> Map<UUID,T> extractRowsUpdated(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
-        Preconditions.checkNotNull(klazz);
-        Preconditions.checkNotNull(updates);
-        Preconditions.checkNotNull(dbSchema);
-        Map<UUID,T> result = new HashMap<UUID,T>();
-
-        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
-            if(rowUpdate != null) {
-                if(rowUpdate.getNew() != null) {
-                    Row<GenericTableSchema> row = rowUpdate.getNew();
-                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
-                }
-            }
-        }
-        return result;
-    }
-
-    public static <T> Map<UUID,T> extractRowsRemoved(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
-        Preconditions.checkNotNull(klazz);
-        Preconditions.checkNotNull(updates);
-        Preconditions.checkNotNull(dbSchema);
-        Map<UUID,T> result = new HashMap<UUID,T>();
-
-        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
-            if(rowUpdate != null) {
-                if(rowUpdate.getNew() == null && rowUpdate.getOld() != null) {
-                    Row<GenericTableSchema> row = rowUpdate.getOld();
-                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
-                }
-            }
-        }
-        return result;
-    }
-
-    public static Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
-        Preconditions.checkNotNull(klazz);
-        Preconditions.checkNotNull(updates);
-        Preconditions.checkNotNull(dbSchema);
-        Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result = new HashMap<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
-        TableUpdate<GenericTableSchema> update = updates.getUpdate(TyperUtils.getTableSchema(dbSchema, klazz));
-        if(update != null) {
-            Map<UUID, TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rows = update.getRows();
-            if(rows != null) {
-                result = rows;
-            }
-        }
-        return result;
-    }
-
-}
-