2010-07-09 49 views

回答

2

我發現了一個工作解決方案here。 (它不會在本地部署服務器工作在2010年7月9日)

DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); 
PreparedQuery global = datastore.prepare(new Query("__Stat_Kind__")); 

for(Entity globalStat : global.asIterable()) 
{ 
    Long totalBytes = (Long) globalStat.getProperty("bytes"); 
    Long totalEntities = (Long) globalStat.getProperty("count"); 
    String kindName = (String) globalStat.getProperty("kind_name"); 
    resp.getWriter().println("[" + kindName + "] has " + totalEntities + " entities and takes up " + totalBytes + "bytes<br/>"); 
} 
2

可以使用Metadata API。例如:

Query query = new Query(Entities.KIND_METADATA_KIND); 
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService(); 

Iterable<Entity> entityIterable = datastoreService.prepare(query).asIterable(); 

for(Entity entity : entityIterable) { 
    System.out.println("Entity kind: " + entity.getKey().getName()); 
} 
相關問題