views:

65

answers:

1

I am using the low level datastore interface in java. I have an entity that stores a collection of Keys. I would like to query the datastore to get all of the entities in the collection. However, I'd also like to sort them on a created date property. So, I'd like to do something like this:

Query query = new Query(EndeavorUpdate.ENDEAVOR_UPDATE_ENTITY_TYPE);
//getEndeavorUpdateIds() returns a List < Key >
query.addFilter("__key__", Query.FilterOperator.EQUAL, getEndeavorUpdateIds());
query.addSort(EndeavorUpdate.CREATED_DATE_PROPERTY);
PreparedQuery pq = ds.prepare(query);

However, I get an exception saying that "a collection of values is not allowed". It does work if I use IN instead of EQUAL but that seems tremendously inefficient.

Is there a way to do this query efficiently or should I get all the entities from the datastore and do the sorting myself?

+3  A: 

Since you have the keys, it would be most efficient to just get all of the entities directly by key and then sort them by date yourself.

Doing the sorting yourself may also save you from needing an index on the EndeavorUpdate model's date created field (depending on whether you also need such an index somewhere else in your code or not).

David Underhill