IdGeneratorStrategy对于每种类型都是唯一的 [英] IdGeneratorStrategy unique for each kind

查看:86
本文介绍了IdGeneratorStrategy对于每种类型都是唯一的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以创建一个只在一种特定类型内唯一的主键(假设我在这里问正确的问题! - 道歉,如果没有)我注意到有一个IdentityType.APPLICATION选项,但应用程序似乎是最小的可用选项!!



我有以下几种:

  @PersistenceCapable(identityType = IdentityType.APPLICATION)
public class AuditTrail
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private长ID;
@Persistent
私人日期createDate;
@Persistent
私人Long AdminID;
public AuditTrail()
{
this.createDate = new Date();
}
public AuditTrail(Long AdminID)
{
this();
this.setAdminID(AdminID);
}
}

但是当我创建一个新条目时,ID是我的应用程序中的所有项目都是唯一的,所以联系人,管理员,约会,服务等都是独立的表格(或种类),因此它们都是唯一的,但审核跟踪,可以有自己的计数空间,这样它就不会干扰我的实际数据的计数。

我以正确的方式问这个问题,我真的试图找出这个实体/种类/属性/关键的东西,但我不确定我是否完全理解这一切实际上是如何工作的!

解决方案

AppEngine专为高可扩展性而设计,每个Kind缺少唯一标识符是其中一个后果。人们经常询问类似的相关能力,但提供效率不高。 Datastore是基于BigTable构建的NoSQL设计,它被描述为一个巨大的键值存储。它可以快速检索密钥的值,但考虑到你的许多记录不一定在同一台服务器上,它会花费太多的开销以维持一组密钥的准确计数(Kind)。

如果您尝试在自己的代码中强健地添加功能,则无法避免耗时的操作。因此,您的代码会导致很高的工作负载和延迟或延迟,因为有些人称之为延迟。可能AppEngine开发者看到了相同的问题,并选择了速度而不是开发者友好。



没有什么能够阻止您在应用程序代码中维护自己的数量,甚至节省他们在数据存储区中。在某些情况下,这是值得推迟的。记住布鲁尔的CAP定理(解释)。

Is there any way to create a primary key that is only unique inside one specific kind (assuming I am asking the right question here! - apologies if not) I notice there is an "IdentityType.APPLICATION" option but "Application" seems to be the "smallest" available option!!

I have the following:

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class AuditTrail
{
  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Long ID;
  @Persistent
  private Date createDate;
  @Persistent
  private Long AdminID;
  public AuditTrail()
  {
     this.createDate = new Date();
  }
  public AuditTrail(Long AdminID)
  {
     this();
     this.setAdminID(AdminID);
  }
}

But when I create a new entry, the ID is unique across all the items in my application, so that a Contact, an Admin, an Appointment, a Service etc are all separate "tables" (or kinds?) so its OK that the are all unique against each other, but the Audit Trail, could just have its own counting space, so that it doesn't interfere with the count of my "actual data"

Am I asking this in the right way, I have really tried to figure out this Entity/Kind/Property/Key thing, but I'm not sure I am fully understanding how it all actually works under the hood!

解决方案

AppEngine is designed for high scalability and the lack of unique identifiers per Kind is one of the consequences. People often ask about similar related capability but it just is not efficient to provide. The Datastore is a NoSQL design built on BigTable which is described as a huge key-value store. It can retrieve the value for a key rapidly but considering that your many records are not necessarily on the same server it too much overhead to maintain an accurate count of a set of them (the Kind).

If you try to add the functionality robustly in your own code, you cannot avoid time consuming operations. Therefore your code will cause a high workload and delay or "latency" as some like to call it. Probably the AppEngine developers saw the same problems and opted for speed rather than developer friendliness.

There is nothing stopping you from maintaining your own counts in your application code, and even saving them in the Datastore. In some cases it is worth the delay. Always bear Brewer's CAP theorem (explanation) in mind.

这篇关于IdGeneratorStrategy对于每种类型都是唯一的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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