[英]Google App Engine HR Datastore - Java - Delete Entities programatically
I am running Google App Engine in my Eclipse (Helios) IDE. 我正在Eclipse(Helios)IDE中运行Google App Engine。 I use Java for Implementation. 我使用Java来实现。 Testing is done locally on localhost:8888. 测试是在本地主机上完成的:8888。
Unfortunately I cant solve the following problem. 不幸的是,我无法解决以下问题。 I store Entities in Google app Engine High Replication Datastore. 我将实体存储在Google App Engine高复制数据存储区中。 Key is the location, all events are stored as kinds of location (as i understand) with no special unique primary key right now. 关键是位置,所有事件都存储为各种类型的位置(据我了解),现在没有特殊的唯一主键。 I use: 我用:
DatastoreService dss;
Key key;
Entity event;
dss = DatastoreServiceFactory.getDatastoreService();
key = KeyFactory.createKey("location", location); //location is String
event = new Entity("event", key);
event.setProperty("date", date);
event.setProperty("info", infostrg);
dss.put(event);
This works fine. 这很好。
When I try to get all events taking place in a specific location I use the follewing code: 当我尝试在特定位置发生所有事件时,我使用下面的代码:
dss = DatastoreServiceFactory.getDatastoreService();
key = KeyFactory.createKey("location", location);
aktQuery = new Query ("event", key);
aktQuery.addSort("date", Query.SortDirection.DESCENDING);
//List<Entity>
events = dss.prepare(aktQuery).asList(FetchOptions.Builder.withLimit(20));
for (Entity event : events) {
//HTTPServeletResponse only prints out for test
currentAktionen.getWriter().println(event.getProperty("date") + "," +
event.getProperty("info"));
}
It delivers all events and prints the data in my webbrowser site. 它传递所有事件并在我的Web浏览器站点中打印数据。 --> works ->作品
But I am not able to delete such an event entity. 但是我无法删除这样的事件实体。 I tried: dss.delete(key), i tried to delete during the for each loop,... 我尝试过:dss.delete(key),我尝试在for每个循环中删除...
Does anybody know how to delete one or all events programatically mayby via a query? 有人知道如何通过查询以编程方式删除一个或所有事件吗? (Deleting in the Dashbord does not help me!) (在Dashbord中删除对我没有帮助!)
Many thanks for any help! 非常感谢您的帮助!
I made it now, but I dont know why. 我现在做到了,但我不知道为什么。 The following code works now: 以下代码现在可以工作:
for (Entity event : events) {
currentAktionen.getWriter().println(event.getProperty("date") + "," +
event.getProperty("info"));
Key key = aktion.getKey();
dss.delete(key);
}
Dont ask me why, .... I tried this 15 times before with the last two lines of code at the beginning in the for-each and it did not work. 不要问我为什么,....我在for-each的开头尝试了最后两行代码,然后尝试了15次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.