如何浏览本地 Java App Engine 数据存储?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1102449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to browse local Java App Engine datastore?
提问by Jim Blackler
It seems there is no equivalent of Python App Engine's _ah/admin for the Java implementation of Google App Engine.
对于 Google App Engine 的 Java 实现,似乎没有等效于 Python App Engine 的 _ah/admin。
Is there a manual way I can browse the datastore? Where are the files to be found on my machine? (I am using the App Engine plugin with Eclipse on OS X).
是否可以手动浏览数据存储?在我的机器上可以找到哪些文件?(我在 OS X 上将 App Engine 插件与 Eclipse 一起使用)。
回答by Paul
I have local datastore on my Windows+Eclipse environment on \war\WEB-INF\appengine-generated\local_db.bin
我的 Windows+Eclipse 环境中的本地数据存储位于 \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));
}
}
}
回答by Nick Johnson
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 SDK 的数据存储查看器——应该会在下一个 SDK 版本中推出。与此同时,最好的办法是编写自己的带有数据存储查看代码的管理界面 - 或者等待下一个 SDK 版本。
Java App Engine now has a local datastore viewer, accessible at http://localhost:8080/_ah/admin
.
Java App Engine 现在有一个本地数据存储查看器,可在http://localhost:8080/_ah/admin
.
回答by dfrankow
http://googleappengine.blogspot.com/2009/07/google-app-engine-for-java-sdk-122.html: "At long last, the dev appserver has a data viewer. Start your app locally and point your browser to http://localhost:8888/_ah/admin
http://localhost:8000/datastore
* to check it out."
http://googleappengine.blogspot.com/2009/07/google-app-engine-for-java-sdk-122.html:“开发应用服务器终于有了数据查看器。在本地启动您的应用程序并指向您的浏览器转到* 以查看。”http://localhost:8888/_ah/admin
http://localhost:8000/datastore
* as of 1.7.7
* 自1.7.7 起
回答by gw0
Because Google App Engines Datastore viewer does not support displaying collections of referenced entities, I modified Paul's version to display all descendant entities:
由于 Google App Engines Datastore 查看器不支持显示引用实体的集合,因此我修改了 Paul 的版本以显示所有后代实体:
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.
应该注意的是,对于空集合/引用实体,没有任何显示。
回答by Matyas
In the newest versions of the SDK (1.7.6+) the admin part of the dev server comes with it changed its location
在最新版本的 SDK ( 1.7.6+) 中,开发服务器的管理部分随它一起改变了它的位置
Analyzing the server output logs we can see that it is accessible at:
分析服务器输出日志,我们可以看到它可以在以下位置访问:
http://localhost:8000
http://localhost:8000
And the Datastoreviewer:
和数据存储查看器:
http://localhost:8000/datastore
http://localhost:8000/datastore
Looks pretty neat - according to google's new design guidlines.
看起来很整洁——根据谷歌的新设计指南。
回答by Daniel De León
Open the \war\WEB-INF\appengine-generated\local_db.bin
file with a text editor, like Notepad++.
\war\WEB-INF\appengine-generated\local_db.bin
使用文本编辑器(如 Notepad++)打开文件。
The data is scrambled but at least you can read it and you can copy to extract it.
数据被打乱,但至少你可以阅读它,你可以复制以提取它。
回答by Aniruddha Das
For me the fix was to do the login using below gcloud
command
对我来说,修复是使用以下gcloud
命令进行登录
gcloud auth application-default login