I have to load entity values by using 2 conditions using OR condition For example, SELECT * FROM db WHERE (email = xyz@gmail.com OR UUID = 1234)
.
Have tried using Filter:
Filter emailFilter =
new FilterPredicate("email", FilterOperator.EQUAL, email);
Filter firstFilter =
new FilterPredicate("firstname", FilterOperator.EQUAL, firstName);
Filter filter =
CompositeFilterOperator.or(emailFilter, firstFilter);
But I don't understand how to use this filter while loading...
How can I do this using filter in datastore?
If I understand you correctly, you just need to apply the filter to a query and retrieve the results:
// Your filter declarations
Filter emailFilter =
new FilterPredicate("email", FilterOperator.EQUAL, email);
Filter firstFilter =
new FilterPredicate("firstname", FilterOperator.EQUAL, firstName);
Filter filter =
CompositeFilterOperator.or(emailFilter, firstFilter);
// Use class Query to assemble a query
Query q = new Query("Person").setFilter(filter)
// Use PreparedQuery interface to retrieve results
PreparedQuery pq = datastore.prepare(q);
for (Entity result : pq.asIterable()) {
// result.getProperty("lastname")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.