RequestFactory は複合主キーを処理できますか?
ドキュメントには、エンティティが実装する必要があることが記載されていますgetId()。エンティティに単一の「id」フィールドがなく、複合主キーを構成する複数の外部キー フィールドがある場合、これをどのように実装する必要がありますか?
RequestFactory は複合主キーを処理できますか?
ドキュメントには、エンティティが実装する必要があることが記載されていますgetId()。エンティティに単一の「id」フィールドがなく、複合主キーを構成する複数の外部キー フィールドがある場合、これをどのように実装する必要がありますか?
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()ID をドメイン タイプの 1 つのプロパティに減らすことができない場合は、 を使用し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 は 、2.1.1 の RequestFactory の変更に関して少し古くなっています。