RequestFactory可以处理复合主键吗?
documentation提到实体必须实现getId();如果实体没有单个"id“字段,而有多个共同构成复合主键的外键字段,应该如何实现呢?
发布于 2011-02-10 10:41:56
在GWT2.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();
}如果您不能在域类型上将标识简化为单个版本属性,则可以使用Locator来提供外部定义的id和getId()属性。例如:
@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(); }
}关于RequestFactory changes in 2.1.1,问题中链接的DevGuide有点过时
https://stackoverflow.com/questions/4951735
复制相似问题