4.2.2.4. One-to-One Composition
The one-to-one composition will be illustrated by the Customer and CustomerDetails entities:
-
Customer.java - the
Customerentity contains an optional link toCustomerDetailsannotated with@Composition. -
CustomerDetails.java - the
CustomerDetailsentity. -
customer-edit.xml - the customer edit screen descriptor. It contains a nested datasource for the
CustomerDetailsinstance. In order to load the nested instance, the root datasource uses a view of theCustomerentity that includes thedetailsattribute. The field group in the customer edit screen just declares a field for thedetailsattribute.
As a result, customer editing works as follows:
-
The customer edit screen contains the PickerField component with two actions: OpenAction and ClearAction:
-
When the open action is invoked, a new instance of
CustomerDetailsis created and its edit screen is shown. When OK is clicked in the details editor, the details instance is not saved to the database, but to thedetailsDsdatasource of the customer edit screen. -
The picker field displays the instance name of the details entity:
-
When a user clicks OK in the customer edit screen, the updated
Customerinstance together with theCustomerDetailsinstance is submitted to theDataManager.commit()method on the Middleware and saved to the database within a single transaction. -
If the user invokes the clear action of the picker field, the
CustomerDetailsinstance is deleted and the reference to it is cleared in the same transaction after the user commits the customer editor.