15 package com.cloudera.impala.catalog;
17 import java.util.Iterator;
18 import java.util.List;
20 import java.util.concurrent.ConcurrentHashMap;
22 import org.apache.log4j.Logger;
24 import com.google.common.base.Preconditions;
25 import com.google.common.collect.Lists;
32 private static final Logger LOG = Logger.getLogger(CatalogObjectCache.class);
48 caseInsensitiveKeys_ = caseInsensitiveKeys;
56 private final ConcurrentHashMap<String, T> metadataCache_ =
57 new ConcurrentHashMap<String, T>();
67 public synchronized boolean add(T catalogObject) {
68 Preconditions.checkNotNull(catalogObject);
69 String key = catalogObject.getName();
70 if (caseInsensitiveKeys_) key = key.toLowerCase();
71 T existingItem = metadataCache_.putIfAbsent(key, catalogObject);
72 if (existingItem == null)
return true;
74 if (existingItem.getCatalogVersion() < catalogObject.getCatalogVersion()) {
78 metadataCache_.put(key, catalogObject);
88 public synchronized T
remove(String
name) {
89 if (caseInsensitiveKeys_)
name = name.toLowerCase();
90 return metadataCache_.remove(
name);
96 public synchronized void clear() {
97 metadataCache_.clear();
107 return metadataCache_.keySet();
114 return Lists.newArrayList(metadataCache_.values());
121 if (caseInsensitiveKeys_) name = name.toLowerCase();
122 return metadataCache_.containsKey(
name);
131 if (caseInsensitiveKeys_)
name = name.toLowerCase();
132 return metadataCache_.get(
name);
143 return metadataCache_.values().iterator();
boolean contains(String name)
synchronized void clear()
synchronized boolean add(T catalogObject)
CatalogObjectCache(boolean caseInsensitiveKeys)
final boolean caseInsensitiveKeys_