Hi,

I thought of only keys queries but since I've got to use encoded keys I don't know if they work.

However, I'll try it!

thanks

Yasuo Higa wrote:
Hi Patrizio,
  
what's the best way to know the number of entities of a specific kind
saved into the DS?
Of course I'd like to know the optimized way, without retrieving all the
objects.

    
If you have less than or equal to 1000 entities for a specific kind,
the following codes are efficient.

Low level API:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
int count = ds.prepare(new Queue("your kind").setKeysOnly()).countEntities();

JDO:
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Xxx.class);
query.setResult("count(this)");
int count = (Integer) query.exeucte();

If you have more than 1000 entities for a specific kind,
the following codes are efficient.

Low level API:
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
int count = ds.prepare(new Query("your kind").setKeysOnly())
    .asList(FetchOptions.Builder.withOffset(0)).size();

JDO:
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(Xxx.class);
query.setResult("key");// "key" is a name of primary key field
int count = ((List) query.exeucte()).size();

Hope this helps,

Yasuo higa



  

--

Patrizio Munzi
Product Specialist
Viale Bruno Buozzi, 19 - 00197 Roma (Italy)
tel: +39 06 4543 3540
fax: +39 06 4543 3587
mobile: +39 393 7195 164
mail: [email protected]
web: http://www.eris4.com
skype: eris4_munzi


--~--~---------~--~----~------------~-------~--~----~
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