this.memcache = memcache;
}
@Override
public List<MetaNamespace> loadMetaData() {
AsyncDatastoreService datastore = DatastoreServiceFactory.getAsyncDatastoreService();
// step 1 : load all namespaces
Query nsQ = new Query(Query.NAMESPACE_METADATA_KIND).setKeysOnly();
Iterable<Entity> namespaces = datastore.prepare(nsQ).asIterable();
// step 2 : load all kinds and properties per each namespaces
String defaultNs = NamespaceManager.get();
Map<String, Iterable<Entity>> kindsMap = new HashMap<String, Iterable<Entity>>();
Map<String, Iterable<Entity>> propertiesMap = new HashMap<String, Iterable<Entity>>();
for (Entity e : namespaces) {
String namespace = e.getKey().getName();
if (isNullOrEmpty(namespace)) {
NamespaceManager.set(defaultNs);
} else {
NamespaceManager.set(namespace);
}
Query kindQ = new Query(Query.KIND_METADATA_KIND).setKeysOnly();
kindsMap.put(namespace, datastore.prepare(kindQ).asIterable());
// ancestor query is not used here, properties will be grouped in memory
// not keyOnly query because we will need to load property_representation
Query propertyQ = new Query(Query.PROPERTY_METADATA_KIND);
propertiesMap.put(namespace, datastore.prepare(propertyQ).asIterable());
}
// set namespace back
NamespaceManager.set(defaultNs);