通过键删除实体而不先在应用程序引擎中获取它(使用 JDO)

发布于 2024-08-10 23:21:11 字数 487 浏览 9 评论 0原文

有没有一种方法可以删除实体而不必先从数据存储中获取实体?我假设我已经拥有该实体的密钥或 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 技术交流群。

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

发布评论

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

评论(3

念三年u 2024-08-17 23:21:11

datanucleus 在 Google 网上论坛回答了我的问题

不是真的。问题是一个对象可以有关系,所以,
由于这些可能会导致级联操作,因此通常必须
首先加载到内存中。唯一不需要的情况
被加载到内存中的是如果要删除的对象的类有
没有关系。

进入低级 API 并清除对象可能会也可能不会
对相关对象产生影响......也许有人负责
它可以对此发表评论。

datanucleus answered my question on the google group:

Not really. The issue is that an object can have relations and so,
since these can cause cascade of operations, it typically has to be
loaded into memory first. The only situation where it wouldn't need to
be loaded into memory was if the class of the object to be deleted had
no relations.

Going into the low level API and blasting away objects may or may not
have an impact on related objects ... perhaps someone responsible for
it could comment on that.

谁许谁一生繁华 2024-08-17 23:21:11

我不确定 JDO,但对于 Python,这可以通过一个小技巧实现。您需要使用相同的密钥“创建”一个新实例,然后将其删除。它只会访问数据库一次。

instance = Model(key=key_to_delete, required_property='dummy')
instance.delete()

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.

instance = Model(key=key_to_delete, required_property='dummy')
instance.delete()
晨光如昨 2024-08-17 23:21:11

如何使用 低级API

我认为 DataService.delete(Key) 会完全满足您的需要。

如果您使用 Long 作为密钥,则需要先使用 KeyMaker 创建密钥。

Key k = KeyFactory.createKey(Employee.class.getSimpleName(), "[email protected]");

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.

Key k = KeyFactory.createKey(Employee.class.getSimpleName(), "[email protected]");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文