Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
列出Google数据存储中的所有类型,保留的除外(java)_Java_Google App Engine_Google Cloud Datastore - Fatal编程技术网

列出Google数据存储中的所有类型,保留的除外(java)

列出Google数据存储中的所有类型,保留的除外(java),java,google-app-engine,google-cloud-datastore,Java,Google App Engine,Google Cloud Datastore,在Appengine(java)中,我能够使用此代码列出数据存储的所有实体,以便在以后删除它们。问题是,我在日志中得到了大量的种类“\uuuuxxx\ukind\uuuuuuu”是保留的。,因此我想要一种方法来检索未保留的种类下的所有实体 这可能吗 do { FetchOptions options = FetchOptions.Builder.withLimit(100); if(cursor != null) { options.startCursor(cur

在Appengine(java)中,我能够使用此代码列出数据存储的所有实体,以便在以后删除它们。问题是,我在日志中得到了大量的
种类“\uuuuxxx\ukind\uuuuuuu”是保留的。
,因此我想要一种方法来检索未保留的种类下的所有实体

这可能吗

do {
    FetchOptions options = FetchOptions.Builder.withLimit(100);
    if(cursor != null) {
        options.startCursor(cursor);
    }
    QueryResultList<Entity> results = pq.asQueryResultList(options);
    if(results.size() > 0) {
        for (Entity result : results) {
            try {
                datastore.delete(result.getKey());   
            } catch (Exception e) {
                log.warning(e.getMessage());
            }
        }
        cursor = results.getCursor();
    } else {
        cursor = null;
    }
} while(cursor != null);
do{
FetchOptions=FetchOptions.Builder.withLimit(100);
如果(光标!=null){
选项。startCursor(光标);
}
QueryResultList结果=pq.asQueryResultList(选项);
如果(results.size()>0){
对于(实体结果:结果){
试一试{
datastore.delete(result.getKey());
}捕获(例外e){
log.warning(如getMessage());
}
}
cursor=results.getCursor();
}否则{
游标=空;
}
}while(游标!=null);

您应该能够从元数据中获取所有类型的内容。使用GQL,您可以运行以下查询以列出所有类型:

SELECT __key__ FROM __kind__ ORDER BY __key__
这将返回所有类型,包括任何系统类型;种类以双下划线开头(例如
\uuu Stat\uu Kind\uuu

在迭代上述查询的结果时,只需排除系统类型,然后对每种类型运行delete即可进行清理

根据您使用的API,如果它不支持GQL,请使用等效的查询生成器并运行它


看看这个

你是否只在本地devserver上看到这些类型,或者在GAE上部署时也看到了这些类型?只有在实际部署时,这也是我最终得到的结果,但我认为会有一些“更干净”的方法来做到这一点。无论如何,我会将您的答案标记为解决方案,因为这是我得到的唯一答案:)