在客体化中使用“IN”查询

时间:2012-08-12 18:14:26

标签: java google-app-engine objectify

如何在物化中使用'IN'查询?我有一个'纸'实体和一个不同的实体'时间表'。在'附表'中我有纸的关键。现在我使用一些标准获得了“纸”的几个键。现在我想用'scheduledDate'来过滤那些。我想用这样的问题查询'Schedule':get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'。如何在物化中做到这一点?感谢

1 个答案:

答案 0 :(得分:6)

Objectify是低级数据存储API的瘦包装器,因此IN运算符的行为与低级API相同:

ofy.query(Schedule.class).filter("paper IN", listOfPaperKeys).filter("scheduledDate = ", someDate)

这假设您的Schedule类有一个字段List<Key> paper,其中包含指向Paper个实体的键列表(如果您使用objectify的类型,您也可以拥有List<Key<Paper>> paper - 安全Key s)。

请注意IN如何在幕后执行一系列查询并合并结果。所以从某种意义上说,它表现为一系列“=”运算符,其结果被合并:

The IN operator also performs multiple queries, one for each item in the 
specified list, with all other filters the same and the IN filter replaced with
an EQUAL filter. The results are merged, in the order of the items in the list. 
If a query has more than one IN filter, it is performed as multiple queries, 
one for each possible combination of values in the IN lists.