【发布时间】:2011-06-24 12:24:16
【问题描述】:
RequestFactory 可以处理复合主键吗?
documentation 提到实体必须实现getId();如果实体没有单个“id”字段,而是有多个外键字段共同构成复合主键,该如何实现?
【问题讨论】:
标签: gwt requestfactory
RequestFactory 可以处理复合主键吗?
documentation 提到实体必须实现getId();如果实体没有单个“id”字段,而是有多个外键字段共同构成复合主键,该如何实现?
【问题讨论】:
标签: gwt requestfactory
在 GWT 2.1.1 中,Id 和 Version 属性可以是 RequestFactory 知道如何传输的任何类型。基本上,任何原始类型 (int)、盒装类型 (Integer) 或任何具有关联代理类型的对象。您不必自己将复合 id 简化为 String; 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 和版本属性。例如:
@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
【讨论】: