Thanks Yasuo. It's definitely very helpful. I am just reading
http://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 on
http://code.google.com/appengine/docs/java/datastore/overview.html#Quotas_and_Limits

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 <higaya...@gmail.com> 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 google-appengine-java@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to