2 * Copyright (C) 2013 Red Hat, Inc.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.plugin;
13 import java.util.concurrent.ConcurrentMap;
15 import com.google.common.collect.Maps;
17 import org.apache.commons.collections.MapUtils;
18 import org.opendaylight.ovsdb.lib.database.DatabaseSchema;
19 import org.opendaylight.ovsdb.lib.table.Table;
22 private DatabaseSchema schema;
23 ConcurrentMap<String, ConcurrentMap<String, Table<?>>> cache = Maps.newConcurrentMap();
25 public DatabaseSchema getSchema() {
29 public void setSchema(DatabaseSchema schema) {
33 public ConcurrentMap<String, ConcurrentMap<String, Table<?>>> getTableCache() {
37 public ConcurrentMap<String, Table<?>> getTableCache(String tableName) {
38 return cache.get(tableName);
41 private void setTableCache(String tableName, ConcurrentMap<String, Table<?>> tableCache) {
42 cache.put(tableName, tableCache);
45 public Table<?> getRow (String tableName, String uuid) {
46 Map<String, Table<?>> tableCache = getTableCache(tableName);
47 if (tableCache != null) {
48 return tableCache.get(uuid);
53 public void updateRow(String tableName, String uuid, Table<?> row) {
54 ConcurrentMap<String, Table<?>> tableCache = getTableCache(tableName);
55 if (tableCache == null) {
56 tableCache = Maps.newConcurrentMap();
57 setTableCache(tableName, tableCache);
59 tableCache.put(uuid, row);
62 public void removeRow(String tableName, String uuid) {
63 Map<String, Table<?>> tableCache = getTableCache(tableName);
64 if (tableCache != null) {
65 tableCache.remove(uuid);
69 public void printTableCache() {
70 MapUtils.debugPrint(System.out, null, schema.getTables());
71 MapUtils.debugPrint(System.out, null, cache);