Add TableSchema.getColumnList() 39/86139/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 3 Dec 2019 11:01:38 +0000 (12:01 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 3 Dec 2019 11:43:40 +0000 (12:43 +0100)
There are a number of callers which need to populate the columns
as a List. This adds a simple cached wrapper to allow in-place
reuse of the backing collection.

Change-Id: I3add766905b0a5d520b5cdc8f551fca411e7b137
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java
hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTableReader.java
library/impl/src/main/java/org/opendaylight/ovsdb/lib/schema/TableSchema.java
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionManager.java

index 56a5c29cce448b1e47659bf2640944ae53a5836b..af799f7a9d067e1f3cc7ce220508ea92086e722e 100644 (file)
@@ -412,7 +412,7 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo
 
         GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(Global.class);
         Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
-        selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
+        selectOperation.setColumns(hwvtepSchema.getColumnList());
 
         ArrayList<Operation> operations = new ArrayList<>(2);
         operations.add(selectOperation);
index 541c88df1d4e04cb0ad382ffa7aaada06a46dc7d..34ab973eadc641daf95988662bcd19de0e6b0e9f 100644 (file)
@@ -241,7 +241,7 @@ public class HwvtepTableReader {
         final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass);
 
         final Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
-        selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
+        selectOperation.setColumns(hwvtepSchema.getColumnList());
 
         if (existingUUID == null) {
             final WhereClauseGetter<?> whereClausule = whereClauseGetters.get(cls);
@@ -305,7 +305,7 @@ public class HwvtepTableReader {
         final Class<? extends TypedBaseTable<?>> tableClass = TABLE_MAP.get(cls);
         final GenericTableSchema hwvtepSchema = dbSchema.getTableSchema(tableClass);
         final Select<GenericTableSchema> selectOperation = op.select(hwvtepSchema);
-        selectOperation.setColumns(new ArrayList<>(hwvtepSchema.getColumns()));
+        selectOperation.setColumns(hwvtepSchema.getColumnList());
 
         final List<OperationResult> results;
         try {
@@ -360,7 +360,7 @@ public class HwvtepTableReader {
 
     private static Select<GenericTableSchema> buildSelectOperationFor(final GenericTableSchema tableSchema) {
         Select<GenericTableSchema> selectOpearation = op.select(tableSchema);
-        selectOpearation.setColumns(new ArrayList<>(tableSchema.getColumns()));
+        selectOpearation.setColumns(tableSchema.getColumnList());
         return selectOpearation;
     }
 
index e63ecef6b5c815b3a12c7e9e9ec1fb3162e2b796..325815b045851b7dc8ea74e1b3cc295922896aea 100644 (file)
@@ -25,6 +25,7 @@ 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.operations.Insert;
+import org.opendaylight.yangtools.util.CollectionWrappers;
 
 public abstract class TableSchema<E extends TableSchema<E>> {
     private static final AtomicColumnType UUID_COLUMN_TYPE = new AtomicColumnType(UuidBaseType.SINGLETON);
@@ -34,6 +35,8 @@ public abstract class TableSchema<E extends TableSchema<E>> {
     private final String name;
     private final ImmutableMap<String, ColumnSchema> columns;
 
+    private volatile List<String> columnList;
+
     protected TableSchema(final String name) {
         this(name, ImmutableMap.of());
     }
@@ -47,6 +50,19 @@ public abstract class TableSchema<E extends TableSchema<E>> {
         return columns.keySet();
     }
 
+    public List<String> getColumnList() {
+        final List<String> local = columnList;
+        return local != null ? local : populateColumnList();
+    }
+
+    private synchronized List<String> populateColumnList() {
+        List<String> local = columnList;
+        if (local == null) {
+            columnList = local = CollectionWrappers.wrapAsList(columns.keySet());
+        }
+        return local;
+    }
+
     public Map<String, ColumnSchema> getColumnSchemas() {
         return columns;
     }
index db89248c34e103095b00833f2d9ade9f719065f5..19c970fed443e7a2662c5ee3073ce821fe8c2587 100644 (file)
@@ -514,7 +514,7 @@ public class OvsdbConnectionManager implements OvsdbConnectionListener, AutoClos
 
         final GenericTableSchema openVSwitchSchema = dbSchema.getTableSchema(OpenVSwitch.class);
         final Select<GenericTableSchema> selectOperation = op.select(openVSwitchSchema);
-        selectOperation.setColumns(new ArrayList<>(openVSwitchSchema.getColumns()));
+        selectOperation.setColumns(openVSwitchSchema.getColumnList());
 
         List<Operation> operations = new ArrayList<>();
         operations.add(selectOperation);