How to browse local Java App Engine datastore?

后端 未结 7 1845
离开以前
离开以前 2020-12-07 08:37

It seems there is no equivalent of Python App Engine\'s _ah/admin for the Java implementation of Google App Engine.

Is there a manual way I can browse the datastore?

相关标签:
7条回答
  • 2020-12-07 09:09

    For me the fix was to do the login using below gcloud command

    gcloud auth application-default login
    
    0 讨论(0)
  • 2020-12-07 09:11

    Because Google App Engines Datastore viewer does not support displaying collections of referenced entities, I modified Paul's version 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/referenced entities.

    0 讨论(0)
  • 2020-12-07 09:15

    I have local datastore on my Windows+Eclipse environment on \war\WEB-INF\appengine-generated\local_db.bin

    As far as I understood it uses internal format named "protocol buffers". I don't have external tools to present the file in human-readable format.

    I'm using simple "viewer" code like this:

    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
        throws IOException 
    {
    
        resp.setContentType("text/plain");
    
        final DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        final Query query = new Query("Table/Entity Name");
        //query.addSort(Entity.KEY_RESERVED_PROPERTY, Query.SortDirection.DESCENDING);
    
        for (final Entity entity : datastore.prepare(query).asIterable()) {
            resp.getWriter().println(entity.getKey().toString());
    
            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));
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-07 09:15

    Open the \war\WEB-INF\appengine-generated\local_db.bin file with a text editor, like Notepad++.

    The data is scrambled but at least you can read it and you can copy to extract it.

    0 讨论(0)
  • 2020-12-07 09:18

    In the newest versions of the SDK (1.7.6+) the admin part of the dev server comes with it changed its location

    Analyzing the server output logs we can see that it is accessible at:

    http://localhost:8000

    And the Datastore viewer:

    http://localhost:8000/datastore

    Looks pretty neat - according to google's new design guidlines.

    0 讨论(0)
  • 2020-12-07 09:23

    There's currently no datastore viewer for the Java SDK - one should be coming in the next SDK release. In the meantime, your best bet is to write your own admin interface with datastore viewing code - or wait for the next SDK release.

    Java App Engine now has a local datastore viewer, accessible at http://localhost:8080/_ah/admin.

    0 讨论(0)
提交回复
热议问题