gpt4 book ai didi

GWT 请求工厂 : how to handle entities with composite primary keys

转载 作者:行者123 更新时间:2023-12-05 00:05:01 26 4
gpt4 key购买 nike

RequestFactory 可以处理复合主键吗?

documentation提到实体必须实现 getId() ;如果实体没有单个“id”字段,而是有多个外键字段共同构成一个复合主键,这应该如何实现?

最佳答案

在 GWT 2.1.1 中,Id 和 Version 属性可以是 RequestFactory 知道如何传输的任何类型。基本上,任何原始类型( int )、装箱类型( Integer )或任何具有关联代理类型的对象。您不必自己将复合 id 减少为字符串; RF 管道可以通过使用实体类型键的持久 id 或值类型键的序列化状态自动处理复合键。

使用之前发布的示例:

interface Location {
public String getDepartment();
public String getDesk();
}

interface Employee {
public Location getId();
public int getVersion();
}

@ProxyFor(Location.class)
interface LocationProxy extends ValueProxy {
// ValueProxy means no requirement for getId() / getVersion()
String getDepartment();
String getDesk();
}
@ProxyFor(Employee.class)
interface EmployeeProxy extends EntityProxy {
// Use a composite type as an id key
LocationProxy getId();
// Version could also be a complex type
int getVersion();
}

如果不能将身份减少到单个 getId()域类型的属性,您可以使用 Locator 提供外部定义的 id 和 version 属性。例如:
@ProxyFor(value = Employee.class, locator = EmployeeLocator.class)
interface EmployeeProxy {.....}

class EmployeeLocator extends Locator<Employee, String> {
// There are several other methods to implement, too
String getId(Employee domainObject) { return domainObject.getDepartment() + " " + domainObject.getDesk(); }
}

问题中链接的 DevGuide 相对于
RequestFactory changes in 2.1.1

关于GWT 请求工厂 : how to handle entities with composite primary keys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4951735/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com