Now I have 3 versions of this method.
protected int count(String kind) {
// Version 1 - It works on Development Server.
// But it does not work (deployed) App Engine because 1000 entities
limitation
http://code.google.com/appengine/docs/java/datastore/overview.html#Quotas_and_Limits
// Query query = new Query(kind);
// PreparedQuery preparedQuery = datastore.prepare(query);
// int result = preparedQuery.countEntities();
// Version 2 - This one only works on (deployed) App Engine.
// But it does not work on Development Server
// Query query = new Query("__Stat_Kind__");
// query.addFilter("kind_name", FilterOperator.EQUAL, kind);
// PreparedQuery preparedQuery = datastore.prepare(query);
// Entity statKind = preparedQuery.asSingleEntity();
// It returns
null on Development server
// Long totalEntities = (Long) statKind.getProperty("count");
// int result = totalEntities.intValue();
// Version 3 - This code works on both (deployed) App Engine and
Development server
// But The Admin Console -> Datastore -> Statistic shows that it has
about 5,000 entities
// This code returns about 6,0000 entities
Query query = new Query(kind);
query.setKeysOnly();
FetchOptions fetchOptions = FetchOptions.Builder.withOffset(0);
PreparedQuery preparedQuery = datastore.prepare(query);
int result = preparedQuery.asList(fetchOptions).size();
logger.info(Integer.toString(result));
return result;
}
Please correct me what I did wrong.
Thanks.
On Oct 30, 4:43 pm, Pion <[email protected]> wrote:
> Thanks Yasuo. It's definitely very helpful. I am just
> readinghttp://code.google.com/appengine/docs/java/datastore/stats.html.
> Your example clarifies a few things which is unclear on the doc.
>
> It works now!
>
> With my original code ... On the Development server, it returns
> whatever the number of the entities. On the (deployed) App Engine
> always returns 1000 due to the limitation as shown
> onhttp://code.google.com/appengine/docs/java/datastore/overview.html#Qu...
>
> I have changed my code as the following (using your example)
>
> protected int count(String kind) {
> Query query = new Query("__Stat_Kind__");
> query.addFilter("kind_name", FilterOperator.EQUAL,
> kind);
> PreparedQuery preparedQuery = datastore.prepare
> (query);
> Entity statKind = preparedQuery.asSingleEntity(); //
> It works on (deployed App Engine). It returns null on Development
> server.
> Long totalEntities = (Long) statKind.getProperty
> ("count");
> int result = totalEntities.intValue();
>
> return result;
> }
>
> BUT this new code only works on the (deployed) App Engine.
>
> On the Development server, the statKind is null. How do I make it work
> on the Development Server?
>
> My environments: GAE 1.2.6, GWT 1.7.1, Eclipse(Galileo), Windows Vista
> (32-bit).
>
> Again, thanks.
>
> On Oct 30, 4:13 pm, Yasuo Higa <[email protected]> wrote:
>
> > Hi Pion,
>
> > > On my Development Server, it returns the total number of the entities
> > > which is over 40,000 entities.
>
> > > But when deploying it on GAE, it always returns 1,000 entities. Is
> > > this because of this limitation
> > >http://code.google.com/appengine/docs/java/datastore/overview.html#Qu...
> > > If so, what is the best way to find total number of entities I have?
>
> > If your query has no filter condition, I recommend the following query:
>
> > DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> > Query query = new Query("__Stat_Kind__");
> > query.addFilter("kind_name", FilterOperator.EQUAL, kind);
> > Entity stat = ds.prepare(query).asSingleEntity();
> > Long count = (Long) stat.getProperty("count");
>
> > If your query has some filter conditions, I recommend the following query:
>
> > DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
> > Query query = new Query(kind);
> > query.setKeysOnly();
> > query.addFilter(...);
> > int count =
> > ds.prepare(query).asList(FetchOptions.Builder.withOffset(0)).size();
>
> > The first query is faster than the second one.
>
> > Hope this helps,
>
> > Yasuo Higa
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---