Reputation: 291
I'm using GAE in Java, I have a data table "Person" and I need doing something like:
SELECT * FROM PERSON WHERE NAME="MIKE" OR AGE=50
My code builds "AND", I don't know how to build the sentence with OR
Query query = new Query(getEntityKind(), getRootEntityKey());
query.addFilter("name", FilterOperator.EQUAL, "Mike");
query.addFilter("age", FilterOperator.EQUAL, 50);
Any ideas?
Thanks!
Upvotes: 1
Views: 240
Reputation: 80340
There is no OR
operator in GAE queries. The only way is to run two queries and then merge results.
Update: since 1.7.0, GAE supports OR
queries via CompositeFilterOperator
. What it does is basically run parallel queries and then AND/OR them on server. The cost is the same as running separate queries and merging them on client, but one saves on roundtrip times.
Upvotes: 4
Reputation: 936
You can do OR in JDO or JPA - but it's a bit of a trick because it actually translates your query into an IN query. That might give you some ideas on how to rewrite your query though.
Check out the end of this blog post for more: http://gae-java-persistence.blogspot.co.uk/2009/12/queries-with-and-in-filters.html
Upvotes: 0