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