简体   繁体   English

如何在App Engine数据存储区(Java)中查询根实体

[英]How can I query for root entities in the App Engine DataStore (Java)

I'm trying to write a query which will identify and return all root entities (ie entities which have no ancestor). 我正在尝试编写一个查询,该查询将识别并返回所有根实体(即没有祖先的实体)。 I initially tried calling Query.setAncestor(null) but later found out from the datastore Query docs that this doesn't work: 我最初尝试调用Query.setAncestor(null)但后来从数据存储区Query文档中发现这无效:

Passing null as a parameter to Query.setAncestor(String ancestor) does not query for entities without ancestors (this type of query is not currently supported). 将NULL作为参数传递给Query.setAncestor(String ancestor)不会查询没有祖先的实体(当前不支持此类型的查询)。

So now I'm a bit stuck, given what the Query API contains I can't figure out how one would construct a query which identified all the root entities. 因此,由于查询API所包含的内容,我现在有些困惑,我无法弄清楚如何构造一个可以识别所有根实体的查询。

This needs to be app functionality so I'm looking for a solution which works programatically as opposed to some manual intervention wnich requires me to log in to the admin console and click a button :-) 这需要是应用程序的功能,因此我正在寻找一种能够以编程方式工作的解决方案,而不是一些手动干预。wnich要求我登录到管理控制台并单击一个按钮:-)

Anyone know how to do this? 有人知道怎么做吗?

Cheers, 干杯,

Edd 埃德

You will need to add a property to your models that you can query on. 您将需要在模型中添加一个属性,以供查询。 Perhaps a boolean named is_root or something similar. 可能是一个名为is_root的布尔值或类似名称。

As the documentation indicates, there's no way to do this - other than working around it as @Robert suggests. 如文档所示,除了按照@Robert的建议进行处理之外,没有其他方法可以这样做。 If you tell us what you're trying to achieve - as opposed to how you're trying to achieve it - perhaps we can provide a suggestion on how best to go about it. 如果您告诉我们您正在努力实现的目标-与您正在努力实现的目标相对-也许我们可以就如何最好地实现它提供建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将本地Google App Engine Python数据存储区复制到本地Google App Engine Java数据存储区? - How do I copy local Google App Engine Python datastore to local Google App Engine Java datastore? 如何设置数据存储区,以便我可以通过非App Engine Java App访问本地计算机 - How to setup the datastore so I can access my local machine through a non App Engine Java App 更新Google App Engine的DataStore中的查询-Java - Update query in DataStore of google app engine - java 使用Java随机查询Google App Engine数据存储区实体 - Random querying for Google App Engine Datastore entities using Java Google App Engine HR数据存储-Java-以编程方式删除实体 - Google App Engine HR Datastore - Java - Delete Entities programatically 在Google应用引擎java本地数据存储区中添加/编辑实体 - Add/Edit Entities in google app engine java local datastore 覆盖Google App Engine- Java中的数据存储区实体 - Overwrite Datastore entities in Google App Engine- Java Google App Engine DataStore - 如何以有效的方式从 Java 中子表的键中获取 select 父实体? - Google App Engine DataStore - How to select parent entities from keys of a child table in Java in an efficient way? 如何减少Google App Engine数据存储延迟? - How can I reduce Google App Engine datastore latency? 如何让一个 App Engine 项目查询不同的 App Engine 数据存储区? - How do I get one App Engine Project to query a different App Engine's Datastore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM