GWT RequestFactory:如何处理具有复合主键的实体
RequestFactory能否处理复合主键GWT RequestFactory:如何处理具有复合主键的实体,gwt,requestfactory,Gwt,Requestfactory,RequestFactory能否处理复合主键 其中提到实体必须实现getId();在实体没有单个“id”字段,而是有多个外键字段共同构成复合主键的情况下,应该如何实现这一点?在GWT 2.1.1中,id和版本属性可以是RequestFactory知道如何传输的任何类型。基本上,任何基元类型(int)、装箱类型(Integer)或具有关联代理类型的任何对象。您不必自己将复合id缩减为字符串;RF管道可以通过使用实体类型键的持久id或值类型键的序列化状态自动处理复合键 使用之前发布的示例: inte
其中提到实体必须实现
getId()
;在实体没有单个“id”字段,而是有多个外键字段共同构成复合主键的情况下,应该如何实现这一点?在GWT 2.1.1中,id和版本属性可以是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()
属性,则可以使用提供外部定义的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(); }
}
@ProxyFor(value=Employee.class,locator=EmployeeLocator.class)
接口EmployeeProxy{….}
类EmployeeLocator扩展定位器{
//还有其他几种方法可以实现
字符串getId(Employee domainObject){返回domainObject.getDepartment()+“”+domainObject.getDesk();}
}
问题中链接的DevGuide在以下方面有点过时
应该提到的是,复合ID必须映射为ValueProxy(上面代码中的LocationProxy),并且该代理必须在代理中的某个位置公开(即,从GWT.create()d RequestFactory开始遍历接口和方法时可以访问;在上面的示例代码中,可以从EmployeeProxy上的getId访问该代理)哦,顺便说一句,这个版本不必在代理上公开。