On Tue, Jan 26, 2010 at 5:41 PM, asianCoolz <[email protected]> wrote:

> DatastoreService dataSvc =...;
>
> Query query = new Query("MessageRecipients")
>   .addFilter("recipients"), FilterOperator.EQUAL,userid)
>   .addSort("date", SortDirection.DESCENDING)
>   .setKeysOnly();  // <-- Only fetch keys!
>
> //*** from the presentation , mentioned the above can only be done
> using low level api, arent jdo/jpa can get the key only value as well
> //***http://gae-java-persistence.blogspot.com/2009/10/keys-only-
> queries.html
>
>
Can you post the link to the video as well as a summary of the technique
they are discussing? I've been meaning to watch the video, but it'd be
beneficial to other developers on this list who don't have the time to watch
the whole thing.


> List<Entity> msgRecpts = dataSvc.prepare(query).asList();
> List<Key> parents = new ArrayList<Key>();
> for(Entity recep : msgREcpts) {
>  parents.add(recep.getParent());
> }
>
> //Bulk fetch parents using key list
> Map<Key, Entity> msg = dataSvc.get(parents);
>
> //***for second part above, what is the different from doing directly
> "select in" statement in jpa/jdo ?
> //***http://gae-java-persistence.blogspot.com/2009/12/queries-with-and-
> in-filters.html


One of the benefits of passing a List is type safety. The example in the
link above uses a List of Strings, but you could just as easily define Java
enums with valid values. A more subtle advantage is that were you to use a
StringBuilder with an "IN" clause, you would be programmatically building a
String, not a List of query parameters. There's no difference at the lower
levels - both techniques get translated to multiple queries, as Max
describes.

-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to