Since the Google App Engine Datastore application viewer does not support displaying sets of reference objects, I changed the version of Paul to display all descendant entities:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String entityParam = req.getParameter("e"); resp.setContentType("text/plain"); final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); // Original query final Query queryOrig = new Query(entityParam); queryOrig.addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.ASCENDING); for (final Entity entityOrig : datastore.prepare(queryOrig).asIterable()) { // Query for this entity and all its descendant entities and collections final Query query = new Query(); query.setAncestor(entityOrig.getKey()); query.addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.ASCENDING); for (final Entity entity : datastore.prepare(query).asIterable()) { resp.getWriter().println(entity.getKey().toString()); // Print properties final Map<String, Object> properties = entity.getProperties(); final String[] propertyNames = properties.keySet().toArray(new String[properties.size()]); for(final String propertyName : propertyNames) { resp.getWriter().println("-> " + propertyName + ": " + entity.getProperty(propertyName)); } } } }
It should be noted that nothing is displayed for empty collections / reference objects.
gw0 Aug 20 '12 at 19:08 2012-08-20 19:08
source share