Using App Engine Datastores to Find Overlapping Ranges

I am using the Google App Engine for Java with the JDO interface for the data warehouse for the CrimeWatch organization application. One of the opportunities I'm trying to realize is a magazine in which people let you know when they leave for a long period of time (so the patrols know to keep an eye on the houses). In the application, I have an AwayLogEntry object with a start and end date and other fields.

I need to make the report available to people who patrol the neighborhood of someone who has left over a certain period of time (usually for the coming week). I am trying to create a report that within two dates finds all AwayLogEntries that overlap with this range.

I really want to use a query

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

however, the NOT clause is not allowed (I could not find documentation about this, but he made an exception for this effect) and does not use two fields with inequality filters , so I can’t just request different cases of overlap.

My workaround is not very large yet. I am going to do a daily cron job that removes (or flags them if I need to keep them around for audit) from log entries when the current date is greater than the end of the Date entry. Then I can request for all records whose start date is less than the end date of the report (and not checked if I do not delete them). This will allow the records to be reported over the next X days reasonably (this is what they usually require), but will not allow arbitrary date range queries (which I assume they will ask for), unless I pull all the records and filter them in code.

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

+3
1

AwayLogEntry , , .

dates > :reportStartDate and dates < :reportEndDate, , .

+3

Source: https://habr.com/ru/post/1767995/


All Articles