views:

42

answers:

1

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?

+3  A: 

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.

Saxon Druce
I would recommend this, only with one entry per week, since that's the granularity of your report.
Nick Johnson
Perfect - new to GAE so hadn't played with the list properties before. Thanks!
Andrew