如何使用 Java 从 Google 数据存储中删除行?
我想从谷歌数据存储中删除行条目。
我已经编码:
String[] elements = deletedRow.split(",");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity row = new Entity("Row");
Key rowKey;
for (String element : elements) {
row.setProperty("userName", "kapil.kaisare");
out.print("UserName : " + element);
row.setProperty("description", element);
rowKey = row.getKey();
out.print("\nKey : " + rowKey);
datastore.delete(rowKey);
}
deletedRow 是来自 AJAX javaScript 调用的查询参数 &那肯定不是空的。
用户名打印成功。而关键打印:
键:键0
这让我很惊讶!即使我设置了行属性,为什么还有键 0!
请提出一些解决方案。
I want to remove a row entry from google datastore.
I have coded :
String[] elements = deletedRow.split(",");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity row = new Entity("Row");
Key rowKey;
for (String element : elements) {
row.setProperty("userName", "kapil.kaisare");
out.print("UserName : " + element);
row.setProperty("description", element);
rowKey = row.getKey();
out.print("\nKey : " + rowKey);
datastore.delete(rowKey);
}
deletedRow is a query parameter coming from AJAX javaScript call & that's not empty for sure.
Username printed successfully. While Key prints :
Key : Key 0
This is surprising me ! Why is there key 0 even if I am setting row properties !
Please suggest some solution.
For reference : Queries and Indexes, Entities, Properties, and Keys
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作,
我假设 Row 是实体类型,元素(即用户名?)是键名称。
Try the following
I assume Row is the kind of entity and element (i.e., user name?) is the key name.
根据
getKey()
文档:因此,您不应尝试将密钥用于从未保存到数据存储的实体,除非您在实体的构造函数中指定了完整密钥。
Per the
getKey()
documentation:As such, you should not attempt to use the key for entities that have never been saved to the datastore, unless you specified a full key in the entity's constructor.