Aug 11, 2012

GAE - Querying on the Datastore Entity with limit

Just share this simple statement in querying the Entity With limit. Assume the we want only specific number of report to be retrieve from our entity.
Query query = new Query(dataStoreKind);
PreparedQuery pq = datastore.prepare(query);
Iterable<Entity> users  = pq.asIterable(FetchOptions.Builder.withLimit(30));
for (Entity user : users) { // Scroll the data
  // user.getKey().getName(); // this how to get the Entity key
   // (Long)user.getProperty("EntityName"); // Get Entity value 

}

No comments: