Change signature of TransactionUtils to returns Maps keyed by UUID. 84/15684/2
authorEd Warnicke <eaw@cisco.com>
Tue, 24 Feb 2015 23:01:54 +0000 (16:01 -0700)
committerEd Warnicke <eaw@cisco.com>
Wed, 25 Feb 2015 13:14:41 +0000 (06:14 -0700)
Change-Id: I1e1f47914b91bcb524b76f405d5c7ca76b918659
Signed-off-by: Ed Warnicke <eaw@cisco.com>
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

index fe2574aba66e808ecff27b7b1830498cecf273ab..e189b3a99cfde096678e383fd2d4c25d87965975 100644 (file)
@@ -1,6 +1,6 @@
 package org.opendaylight.ovsdb.southbound.transactions.md;
 
-import java.util.List;
+import java.util.Collection;
 
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -28,7 +28,7 @@ public class OvsdbBridgeRemovedCommand extends AbstractTransactionCommand {
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        List<Bridge> removedRows = TransactionUtils.extractRowsRemoved(Bridge.class, getUpdates(), getDbSchema());
+        Collection<Bridge> removedRows = TransactionUtils.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 ff42ac641f95320ba1d455fc2b0d0a769a47c3a4..8e2e6e44fe5f3d59d1c9199e2224de2f21ee530b 100644 (file)
@@ -1,6 +1,7 @@
 package org.opendaylight.ovsdb.southbound.transactions.md;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -39,7 +40,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
 
     @Override
     public void execute(ReadWriteTransaction transaction) {
-        List<Bridge> updatedRows = TransactionUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
+        Collection<Bridge> updatedRows = TransactionUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema()).values();
         for(Bridge bridge : updatedRows) {
             final InstanceIdentifier<Node> nodePath = getKey().toInstanceIndentifier();
             Optional<Node> node = Optional.absent();
index 17d4db6b88d4a13aa9130bbf1e8c02d034ca597f..c283e126df880e3913cda157e61f7d22373e1c25 100644 (file)
@@ -1,7 +1,6 @@
 package org.opendaylight.ovsdb.southbound.transactions.md;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
 import java.util.Map;
 
 import org.opendaylight.ovsdb.lib.message.TableUpdate;
@@ -10,63 +9,58 @@ 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.TypedBaseTable;
 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
 
 import com.google.common.base.Preconditions;
 
 public class TransactionUtils {
 
-    public static <T> List<T> extractRowsUpdated(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+    public static <T> Map<UUID,T> extractRowsUpdated(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        List<T> result = new ArrayList<T>();
+        Map<UUID,T> result = new HashMap<UUID,T>();
 
-        List<TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates) {
+        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.add(TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
+                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
                 }
             }
         }
         return result;
     }
 
-    public static <T> List<T> extractRowsRemoved(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+    public static <T> Map<UUID,T> extractRowsRemoved(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        List<T> result = new ArrayList<T>();
+        Map<UUID,T> result = new HashMap<UUID,T>();
 
-        List<TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates = extractRowUpdates(klazz,updates,dbSchema);
-        for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates) {
+        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.add(TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
+                    result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
                 }
             }
         }
         return result;
     }
 
-    public static List<TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+    public static Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> extractRowUpdates(Class<?> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
         Preconditions.checkNotNull(klazz);
         Preconditions.checkNotNull(updates);
         Preconditions.checkNotNull(dbSchema);
-        List<TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> result = new ArrayList<TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>>();
+        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) {
-                for(TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rows.values()) {
-                    if(rowUpdate != null) {
-                        result.add(rowUpdate);
-                    }
-                }
+                result = rows;
             }
         }
         return result;