google app engine - Objectify/AppEngine: best way to count # of objects returned by a query? -


what best (i.e. efficient) way of counting number of objects returned query, w/o loading them, using objectify on appengine? i'm guessing best fetch keys , counting result:

public int getentitycount(long v) {     objectify ofy = objectifyservice.begin();     iterable<key<myentity>> list = ofy.query(myentity.class)             .filter("field", v).fetchkeys();     int n = 0;     (key<myentity> e : list)         n++;     return n; } 

doesn't seems have dedicated method doing that. ideas?

found it:

int n = iterable<key<myentity>> list = ofy().query(myentity.class)       .filter("field", v).count(); 

it's simple, though efficient because retrieves keys. it's better design ui handle unknown numbers of results (such google gives clues number of pages not actual number)


Comments

Popular posts from this blog

jQuery clickable div with working mailto link inside -

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -