Objectify上的增量ID [英] Incremental IDs on Objectify

查看:96
本文介绍了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开发者提交请求。 http://code.google.com/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. http://code.google.com/p/objectify-appengine/issues/list

这篇关于Objectify上的增量ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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