简体   繁体   English

如何在Gemfire地区创建复合主键方案?

[英]How to create composite primary key scenario in Gemfire region?

I am working on migration of mainframe to java. 我正在将大型机迁移到Java。 I have one table in DB2. 我在DB2中有一张表。 I am replicating this table as a region in Gemfire. 我将此表复制为Gemfire中的一个区域。 While doing this, I have composite primary key for that table. 在执行此操作时,我具有该表的复合主键。 To replicate table to gemfire region. 将表复制到gemfire区域。 I want to make composite primary key for region. 我要为区域设置复合主键。 I just want to know that, is there any possibility to create composite primary key in region? 我只想知道,是否有可能在区域中创建复合主键?

Ideally, you are creating keys that do not change in value after the Key/Value pair is "put" into a Region. 理想情况下,您要创建在“键/值”对“放入”区域后值不会改变的键。 A GemFire/Geode Region is a just a glorified version of a java.util.Map (and a HashMap to be precise). GemFire / Geode Region只是java.util.Map (准确地说是HashMap )的美化版本。

This means that the "composite" key should not be based on any property values in the Region value itself. 这意味着“复合”键不应基于Region值本身中的任何属性值。 By way of example, imagine I have a value Customer defined like so... 举例来说,假设我有一个这样定义的值Customer

class Customer {

  Long accountNumber;

  Gender gender;

  LocalDate birthDate;

  String firstName;
  String lastName;

  ...
}

It would be inadvisable to then create a key like so... 然后像这样创建密钥是不明智的...

class CustomerKey {

  LocalDate birthDate;

  String firstName;
  String lastName;

}

While a person's birth date, first and last name are generally enough to uniquely identify someone, if any of these individual property/field values change then you lose your pairing given the intrinsic behavior of the Java Map (so be careful). 虽然一个人的出生日期,名字和姓氏通常足以唯一地标识一个人,但是如果这些单独的属性/字段值中的任何一个发生了变化,那么鉴于Java Map的固有行为,您将失去配对(因此请小心)。

You should also take care to carefully craft the equals/hashCode methods of any "custom/composite" key class you create. 您还应该小心谨慎地创建任何“自定义/复合”键类的equals/hashCode方法。

I would generally recommend that you use internal (only known to the application), scalar types for your keys, eg Long or String . 我通常建议您为键使用内部(仅对于应用程序而言是已知的)标量类型,例如LongString

This would be as simple as adding a property/field to the Customer class like so... 就像将属性/字段添加到Customer类一样简单...

class Customer {

  Long id;

  ...

}

Most of the time, your (OQL) query predicates are based on the values of the individual domain object properties/fields, not the keys. 在大多数情况下,您的(OQL)查询谓词是基于各个域对象属性/字段的值,而不是键。 For example... 例如...

SELECT c FROM /Customers c WHERE c.lastName = 'Doe'

Additionally, if your key were a String , you could use the UUID class to generate unique values. 此外,如果键是String ,则可以使用UUID类生成唯一值。 Otherwise, you will need to craft your own unique, key generation strategy. 否则,您将需要制定自己独特的密钥生成策略。

In summary, while what you are asking is possible given carefully crafted class types in Java, it is not generally recommended; 总而言之,尽管您可以使用Java中精心设计的类类型来询问您所要提出的问题,但通常不建议这样做。 prefer simple, scalar types. 更喜欢简单的标量类型。

Here is a link to some things in general to keep in mind. 这里是一个链接到一些普遍的事情要记住。

Hope this helps. 希望这可以帮助。

-John -约翰

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建复合主键hibernate JPA? - how to create a composite primary key hibernate JPA? 如何为复合主键创建JPA类 - How to create JPA class for composite primary key 如何在JPA中创建和处理复合主键 - How to create and handle composite primary key in JPA 如何使用包含生成值的复合主键创建实体 - How to create an entity with a composite primary key containing a generated value 如何创建一个外键和一个主键的复合键 Spring 数据 JPA - How to create a composite key of one foreign key and one primary key Spring Data JPA JPA如何制作复合主键的复合外键部分 - JPA how to make composite Foreign Key part of composite Primary Key hibernate composite主键包含一个复合外键,如何映射这个 - hibernate composite Primary key contains a composite foreign key, how to map this 如何创建一个同时包含基元和复合主键作为表复合键 (Spring JPA) 的 JoinTable? - How do I create a JoinTable which includes both a primitive and a composite primary key as the tables composite key (Spring JPA)? 如何在 Hibernate 的复合主键中自动增加一个 Id? - How to autoincrement an Id in a composite primary key in Hibernate? 如何在mybatis映射中定义复合主键 - how to define composite primary key in mybatis mapping
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM