【问题标题】:Using 'IN' query in objectify在objectify中使用'IN'查询
【发布时间】:2012-08-09 02:35:25
【问题描述】:

如何在 objectify 中使用“IN”查询?我有一个“Paper”实体和一个不同的实体“Schedule”。在“时间表”中,我有纸键。现在我使用一些标准得到了一些“纸”键。现在我想用'scheduledDate'过滤那些。我想用这样的方式查询“计划”:get 'schedule' from 'Schedule' where 'paper key' in (List of paper keys) and 'scheduledDate' = 'some date'。我如何在客观化中做到这一点?谢谢

【问题讨论】:

    标签: java google-app-engine objectify


    【解决方案1】:

    Objectify 是低级 Datastore API 的精简包装器,因此 IN 运算符的行为与低级 API 相同:

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

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

    注意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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      相关资源
      最近更新 更多