使用App Engine数据存储区查找重叠范围 [英] Using the App Engine datastore to find overlapping ranges

查看:95
本文介绍了使用App Engine数据存储区查找重叠范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用适用于CrimeWatch组织的应用程序的数据存储的JDO界面使用Google App Engine for Java。我试图实现的功能之一是一个离开日志,人们报告他们将要离开很长一段时间(所以巡逻人员知道要留意房屋)。在应用程序中,我有一个开始和结束日期的AwayLogEntry对象,并且需要其他字段。



我需要向巡逻人员提供报告在特定时间段内(通常是即将到来的一周),谁在附近。我试图构建一个报告,给出两个日期查找所有与此范围重叠的AwayLogEntries。



我真正想要使用的查询是



select * from AwayLogEntry where not(end<:reportStartDate || start>:reportEndDate)



但不允许使用NOT子句(无法找到关于此的文档,但它引发了这种情况的异常),也没有在不等式过滤器,因此我无法直接查询不同的重叠情况。



现在我的解决方法并不是很好 - 我打算做一个日常cron作业,删除(或者标记它们,如果我需要将它们留在审核中)日期大于条目结束日期。然后我可以查询开始日期小于报告结束日期的所有条目(如果我不删除它们,则不标记)。这将允许合理地报告接下来X天的条目(这是他们通常需要的),但不会允许任意的日期范围查询(我猜他们会要求),除非我只是拉入所有条目并在代码中进行过滤。

任何人都可以想出任何技巧来解决GAE JDO实现的这种局限性吗?

$ b $除了 AwayLogEntry 的开始和结束之外,您还可以拥有一个list属性,其中包含您的查询过滤器可以检查日期> :reportStartDate和日期< :reportEndDate ,它在支持的日期属性的单个列表上组合了两个不等式过滤器。


I'm using Google App Engine for Java with the JDO interface for the datastorage for an application for a CrimeWatch organization. One of the features I'm trying to implement is an away log where people report when they're going to be away for an extended period of time (so the patrols know to keep an eye on the houses). In the app, I have an AwayLogEntry object with a start and end date, and the other fields needed.

I need to make a report available to the people who patrol the neighborhood of who is away in a given time period (usually the upcoming week). I'm trying to build a report that given two dates finds all the AwayLogEntries that overlap with this range.

The query I really want to use is

select * from AwayLogEntry where not(end < :reportStartDate || start > :reportEndDate)

however the NOT clause is not allowed (couldn't find documentation about this, but it threw an exception to this effect), nor is using two fields with inequality filters so I can't just query for different overlap cases directly.

My workaround for now isn't great - I'm going to make a daily cron job that deletes (or flags them if I need to keep them around for auditing) away log entries when the current date is greater than entries end date. Then I can query for all entries whose start date is less than the report end date (and isn't flagged if I don't delete them). This will allow for reporting the entries for the next X days reasonably, (which is what they usually need), but won't allow for arbitrary date range queries (which I'm guessing they're going to ask for) unless I just pull all the entries in and filter them in code.

Can anyone think of any tricks to get around this limitation of the GAE JDO implementation?

解决方案

In addition to the start and end of the AwayLogEntry, you could also have a list property containing a list of all the days that the person is away.

Your query filter could then check for dates > :reportStartDate and dates < :reportEndDate, which combines two inequality filters on a single list of date property, which is supported.

这篇关于使用App Engine数据存储区查找重叠范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆