Objectify上的增量ID

编程入门 行业动态 更新时间:2024-10-24 18:18:57
本文介绍了Objectify上的增量ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

自从升级到GAE 1.8后,在Objectify中使用@Id进行注释时,我得到零散的ID:

@Id 私人长ID;

尽管我理解在避免云平台上的热点方面需要分散的ID,但是Objectify是一种让旧的增量式ID恢复的方法吗?不得不在UI中显示一个十六进制值(比如1DZENH6BSOW),以避免大量生成的64位id不会削减它。

我很高兴有一个辅助注释@IdLegacy与@Id一起使用,然后@Id仍然会生成长ID,我可以使用旧ID来显示。

解决方案:

在我的网站里面,我有一段简单的代码,如果代码不存在,它会分配一个ID:

if(getId()== null){ ObjectifyFactory f = new ObjectifyFactory(); 钥匙< MyEntity> key = f.allocateId(MyEntity.class); setId(key.getId()); }

解决方案

据我所知, Objectify传递App引擎数据存储的零散id行为。

Objectify问题跟踪器的快速检查并未显示任何人尚未提出增量ID请求。向Objectify开发者提交请求。 code.google/p/objectify-appengine/issues/list

Since upgrading to GAE 1.8, I'm getting scattered ids when annotating with @Id in Objectify:

@Id private Long id;

Even though I understand the need for scattered ids in terms of avoiding hotspots on the cloud platform, is there a way in Objectify to get the old incremental ids back? Having to display a hexatridecimal value (like 1DZENH6BSOW) in the UI to avoid that massive generated 64bit id just doesn't cut it.

I'm happy to have a secondary annotation @IdLegacy working in conjunction with the @Id, then @Id will still generate the long id and I can use the legacy id for display purposes.

SOLUTION:

Inside my construtor, I have a simple piece of code that allocates an id if ones doesn't exist:

if (getId() == null){ ObjectifyFactory f = new ObjectifyFactory(); Key<MyEntity> key = f.allocateId(MyEntity.class); setId(key.getId()); }

解决方案

As far as I know, Objectify passes along the App Engine Datastore's scattered id behavior.

A quick check of the Objectify issue tracker doesn't show that anyone has yet made a request for incremental ids. Submit a request to the Objectify devs. code.google/p/objectify-appengine/issues/list

更多推荐

Objectify上的增量ID

本文发布于:2023-10-15 02:37:43,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:增量   Objectify   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!