GWT RequestFactory:如何处理具有复合主键的实体

发布于 2024-10-16 14:14:10 字数 227 浏览 3 评论 0原文

RequestFactory 可以处理复合主键吗?

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

Can RequestFactory handle composite primary keys?

The documentation mentions that entities must implement getId(); how should this be implemented in the case where entities do not have a single "id" field, but rather have multiple foreign key fields that together constitute a composite primary key?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱格式化 2024-10-23 14:14:10

在 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 就有点过时了
2.1.1 中的 RequestFactory 更改

In GWT 2.1.1, the Id and Version properties may be of any type that RequestFactory knows how to transport. Basically, any primitive type (int), boxed type (Integer), or any object that has an associated Proxy type. You don't have to reduce a composite id to a String yourself; the RF plumbing can take care of composite keys automatically by using the persistent id of an entity-type key or the serialized state of a value-type key.

Using the previously-posted example:

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();
}

If you can't reduce the identity to a single getId() property on the domain type, you can use a Locator to provide an externally-defined id and version property. For example:

@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(); }
}

The DevGuide linked from the question is a bit out of date with respect to
RequestFactory changes in 2.1.1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文