[英]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
. 我通常建议您为键使用内部(仅对于应用程序而言是已知的)标量类型,例如
Long
或String
。
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.