简体   繁体   English

如何在appengine数据存储区中的两个日期之间获取实体

[英]How to get an entity between two dates in appengine datastore for

I have an appointment table with appointment date as one of the columns. 我有一个约会表,其中约会日期为其中一列。 I want to retrieve all the appointments between two dates in appengine datastore using JPA. 我想使用JPA检索appengine数据存储区中两个日期之间的所有约会。 can please let me know how to achieve this? 可以请让我知道如何实现这一目标? I tried with following query but it did not work. 我尝试了以下查询,但它没有用。

select a from Appointment a where (apptSts='p' or apptSts='a') and (apptDate>=:fromDate or apptDate<=:toDate) 从Appointment a where(apptSts ='p'或apptSts ='a')和(apptDate> =:fromDate或apptDate <=:toDate)中选择一个

Make the property as a list property. 将属性设置为列表属性。 Then you can query between two dates. 然后您可以在两个日期之间查询。 See the following test code done in Objectify. 请参阅Objectify中完成的以下测试代码。 I think you can use the same technique in JPA also. 我想你也可以在JPA中使用相同的技术。 https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java https://github.com/stickfigure/objectify/blob/master/src/test/java/com/googlecode/objectify/test/QueryExoticTypesTests.java

To retrieve appointments between 2 dates, you need to change your query logic to include " and " instead of " or " : 要检索2个日期之间的约会,您需要更改查询逻辑以包含“ ”而不是“ ”:

select a from Appointment
where apptDate>=fromDate and apptDate<=toDate

You CAN have inequality filers on the same property in appengine, but they can't be combined with OR. 您可以在appengine中的同一属性上使用不等式文件管理器,但它们不能与OR结合使用。

See examples in gql reference , which should also apply to JPA. 请参阅gql参考中的示例,该示例也应适用于JPA。

You can apply multiple inequality but they should be on the same field (variable).I guess whats going wrong here is that app engine doesn't allow to use the bracket things ,,,i mean 你可以应用多个不等式,但它们应该在同一个字段(变量)。我想这里出现的问题是app引擎不允许使用括号的东西,,,我的意思是

(conditionA AND conditionB .....) OR (conditionC AND conditionC .....)
//--this is not allowed.

By the way following is allowed(i tried it) 顺便说一句允许(我试过)

(conditionA AND conditionB .....) AND (conditionC AND conditionC)
//--allowed(although its bracket are meaning less here)

您只能执行大于或小于查询的一个,因此一种方法是执行大于查询,并遍历结果并手动过滤掉与小于查询不匹配的结果。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM