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
Customer
entity contains an optional link toCustomerDetails
annotated with@Composition
. -
CustomerDetails.java - the
CustomerDetails
entity. -
customer-edit.xml - the customer edit screen descriptor. It contains a nested datasource for the
CustomerDetails
instance. In order to load the nested instance, the root datasource uses a view of theCustomer
entity that includes thedetails
attribute. The field group in the customer edit screen just declares a field for thedetails
attribute.
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
CustomerDetails
is 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 thedetailsDs
datasource 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
Customer
instance together with theCustomerDetails
instance 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
CustomerDetails
instance is deleted and the reference to it is cleared in the same transaction after the user commits the customer editor.