Accessibility

Table of Contents

Architecting RIAs with Flex Data Management Services

What about complex object models?

After you have decided on your client-side application model, you need to figure out how to manage properties that are not primitive values. I'll call these complex properties for the purposes of this discussion. They will typically point to other classes you also mark as [Managed] if you want to manage their state in Flex Data Management Services. There are two ways to represent a complex property in Flex Data Management Services: using hierarchical values or managed associations.

With hierarchical values, the subobjects do not need to have ID properties; they are managed by the same destination as the top-level objects. In this case, think of the subobject as being part of the parent object's value. The subobject must be deleted when the parent object is deleted and should not be referenced by any other top-level objects—although it can be referenced by other objects underneath the same top-level object. With hierarchical values, when a property of a subobject is modified, the adapter is given only the list of top-level property names that have changed. You are given the complete state of the original and new instances so if you want to do a more detailed incremental update of the value, you will need to do your own comparison of the subobject's properties.

With managed associations, on the other hand, the object referenced by your complex property has a life of its own. You can use getItem, createItem, and fill calls to return individual instances of this type and also retrieve instances as values of properties from the referencing type. To use managed associations, Data Management Services requires that the referenced objects have their own identity properties which uniquely identify them within their destination.

If you choose to make a property a managed association, you add a line to the metadata XML file for the referencing object's destination that contains the name of the property and the referenced object's destination name. This tag specifies the nature of the relationship: one-to-one, one-to-many, many-to-many, or many-to-one. For most purposes, it is easier to just think of two types of properties: single valued (one-to-one and many-to-one) and multivalued (one-to-many and many-to-many). A many-valued property is supported as a List property in Java and an ArrayCollection on the client.

Relationships can be bidirectional or create cycles in your object model. When you have a property that is the inverse of another property, your code will have to ensure that the reverse direction is updated because Data Management Services does not automatically update the inverse reference when the forward reference is modified.