在客体化中使用"IN"查询

Shw*_*nka 4 java google-app-engine objectify

如何在客体化中使用"IN"查询?我有一个'纸'实体和一个不同的实体'附表'.在'附表'中我有纸的关键.现在我使用一些标准获得了"纸"的几个键.现在我想用'scheduledDate'来过滤那些.我要查询"日程"像这样的东西:get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'.如何在物化中做到这一点?谢谢

Pet*_*ego 6

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

ofy.query(Schedule.class).filter("paper IN", listOfPaperKeys).filter("scheduledDate = ", someDate)
Run Code Online (Sandbox Code Playgroud)

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

注意如何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.
Run Code Online (Sandbox Code Playgroud)