GWT RequestFactory: how to handle objects with compound primary keys

1 answer

In GWT 2.1.1, the Id and Version properties can be of any type that RequestFactory knows how to transport. In principle, any primitive type ( int ), type in a box ( Integer ), or any object that has an associated proxy type. You do not need to reduce the composite identifier to String yourself; RF plumbing can automatically handle compound keys using a constant key of an object type key or a serialized key of a value type key.

Using a previously published 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 cannot reduce the identifier to a single getId() property in a domain type, you can use Locator to provide an external id and version property. For instance:

 @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 related to the question is a bit outdated regarding the Change in RequestFactory in 2.1.1

+7
source

Source: https://habr.com/ru/post/1339106/


All Articles