通过键删除实体而不先在应用程序引擎中获取它(使用 JDO)
有没有一种方法可以删除实体而不必先从数据存储中获取实体?我假设我已经拥有该实体的密钥或 ID。 我正在考虑类似 deleteObjectById
的东西,它类似于 PersistenceManager
上的 getObjectById
。
我能想到的最接近的是使用 Query.deletePercientAll()
(如 此处)并指定一个仅依赖于该键的查询,但我无法判断在删除实体之前是否会获取该实体。
谢谢
编辑:我知道如何使用低级 API 以及 python API 来执行此操作。我想知道是否有办法在 JDO 层中做到这一点。
Is there a way to delete an entity without having to fetch it from the datastore first? I am assuming I already have the key or id for the entity.
I'm thinking of something like deleteObjectById
that would be an analogue to getObjectById
on PersistenceManager
.
The closest I can think of is using Query.deletePersistentAll()
(as seen here) and specifying a query that only relies on the key, but I can't tell if that is going to fetch the entity before deleting it.
thanks
EDIT: I know how to do this using the low level API, as well as in the python API. I was wondering if there was a way to do it within the JDO layer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
datanucleus 在 Google 网上论坛回答了我的问题:
datanucleus answered my question on the google group:
我不确定 JDO,但对于 Python,这可以通过一个小技巧实现。您需要使用相同的密钥“创建”一个新实例,然后将其删除。它只会访问数据库一次。
I'm not sure about JDO, but for Python this is possible with a small hack. You need to "create" a new instance with the same key and then delete it. It will hit the database only once.
如何使用 低级API?
我认为 DataService.delete(Key) 会完全满足您的需要。
如果您使用 Long 作为密钥,则需要先使用 KeyMaker 创建密钥。
How about using the Low-level API?
I think
DataService.delete(Key)
will do exactly what you need.If you use a Long as key, you will ned to use the KeyMaker to create a key first.