请帮助我了解GAE数据存储中的实体层次结构 [英] Please help me understand entity hierarchies in GAE's Datastore

查看:124
本文介绍了请帮助我了解GAE数据存储中的实体层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google App Engine Datastore允许每个实体拥有一个父实体,实质上是形成实体层次结构的一种方式。例如,一个员工可以作为:

 公司#521 / Department#5 / Employee#3 

实体id在具有相同父级的实体中唯一唯一,所以完整的实体路径需要唯一地解决它。



到目前为止,这么好。



我应该如何模拟父子关系,而不是像传统数据库中那样依赖实体内的基本引用属性?



我能想到的唯一原因是解决数据存储查询中缺少连接的问题。我只能使用我检索的实体的属性以及实体层次结构中任何级别的父实体的任何实体来过滤查询。



任何使用此功能的其他原因是什么?



Datastore文档说属于同一层次结构的实体被视为实体组,并且同一实体组中的实体具有序列化的写访问权限。这到底是什么意思呢?是否意味着如果我的应用程序的一个线程更新 Department#5 ,另一个写入<$​​ c $ c> Employee#3 必须等待此更新才能完成?



谢谢!

解决方案

只有在需要定义事务域的情况下,您才应该使用实体组。在App Engine上,交易只能修改单个实体组中的实体 - 即具有相同父级的实体。如果您不需要两个实体之间的事务完整性,则它们不应位于同一个实体组中。

如果您绝对需要全局事务,您可以自己实现它们 - 请参阅关于这个问题的博客文章为例。实际上,相对较小比例的应用实际上需要全球交易。

The Google App Engine Datastore allows each entity to have a parent entity, essentially a way to form an entity hierarchy. For example, an Employee can be addressed as:

Company#521/Department#5/Employee#3

The entity id is only unique among entities with the same parent, so the full entity path is required to uniquely address it.

So far, so good.

But when should I model a parent-child relationship this way, rather than relying on a basic reference property within an entity, as I would in a traditional database?

The only reason I can think of is to get around the lack of joins in a Datastore query. I can only filter a query using properties from the entity whose kind I am retrieving -- and by any entity that is a parent at any level in the entity's hierarchy.

Any other reason to use this feature?

The Datastore documentation says that entities that belong to the same hierarchy are treated as an entity group, and that entities in the same entity group have serialized write access. What exactly does that mean? Does it mean that if one thread of my app is updating Department#5, another thread that is writing to Employee#3 will have to wait for this update to finish?

Thanks!

解决方案

You should use entity groups only where required to define transactional domains. On App Engine, transactions can only modify entities within a single entity group - that is, entities with the same parent. If you don't need transactional integrity between two entities, they should not be in the same entity group.

If you absolutely need global transactions, you can implement them yourself - see my blog post on the subject for an example. In reality, a relatively small proportion of apps actually need global transactions.

这篇关于请帮助我了解GAE数据存储中的实体层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆