如何使用 Java 从 Google 数据存储中删除行?

发布于 2024-10-17 19:18:58 字数 1069 浏览 3 评论 0原文

我想从谷歌数据存储中删除行条目。

我已经编码:

            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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-10-24 19:18:58

尝试以下操作,

String[] elements = deletedRow.split(",");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

for (String element : elements) {
    Key key = KeyFactory.createKey("Row", element);
    datastore.delete(key);
}

我假设 Row 是实体类型,元素(即用户名?)是键名称。

Try the following

String[] elements = deletedRow.split(",");
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();

for (String element : elements) {
    Key key = KeyFactory.createKey("Row", element);
    datastore.delete(key);
}

I assume Row is the kind of entity and element (i.e., user name?) is the key name.

苏别ゝ 2024-10-24 19:18:58

根据 getKey() 文档:

如果实体尚未保存(例如通过DatastoreService.put),则此Key将不会被完全指定,并且不能用于某些操作(如DatastoreService.get)。保存实体后,其密钥将更新为完全指定。

因此,您不应尝试将密钥用于从未保存到数据存储的实体,除非您在实体的构造函数中指定了完整密钥。

Per the getKey() documentation:

If the entity has not yet been saved (e.g. via DatastoreService.put), this Key will not be fully specified and cannot be used for certain operations (like DatastoreService.get). Once the Entity has been saved, its Key will be updated to be fully specified.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文