With an RIA, your client code is in a separate process from your application model, but frequently requires even finer-grained access to features on the server to support the improved interactivity. Each user click will more than likely require a remote procedure call to the server to refresh the view, which frequently translates to more remote calls to get a more dynamic user interface. It is common to have many remote stubs for each model operation; and, as you make changes to these model objects, these changes ripple throughout your RPC stubs. So code is not only more complex and involved to write, but it becomes more difficult to maintain in the long term. The glue and wrapper code becomes the tail at the end of the dog, requiring several changes for each model change.
Additionally, these wrappers make copies of data that exist on the server. It is therefore the responsibility of the developer to synchronize properly these copies with the server data to maintain data integrity. As changes are made on the client, your code must track what has changed. To update data, your RPC wrapper needs to include some information about the original version of the data so that it can determine if this update is being performed with stale data. These problems can be difficult to solve and often are not fully addressed until they present production problems.
Flex Data Management Services helps solve these problems by making it easy to synchronize data between client and server tiers without compromising the end-user experience, the integrity of the data, or the scalability and performance of the application. By eliminating the RPC wrappers, Data Management Services enables you to replicate server objects to the client, detects changes you make to these objects, and propagates these changes to the server where a server-side data adapter handles them. One type of adapter is the Java Adapter, which communicates these changes to your Java back end or updates your database. Data Management Services also supports an in-memory ActionScript adapter and an adapter that directly supports a hibernate data model.
But that is not all. In addition to making it easy to write and maintain your application, Data Management Services makes it easy to support advanced data manipulation features. For example, the data services server side can propagate one client's changes to other clients to give the client the most up-to-date view of the data possible. This improves the end user experience for many applications and makes it easy to add collaborative and applications that monitor data in real time.
Data Management Services supports a rich set of object models—the types found in most real-world applications—and is carefully designed to allow applications to maintain referential integrity using database integrity constraints. Flex Data Services supports object models that contain cyclic graphs of references between objects. You can use one-to-one, one-to-many, many-to-one, and many-to-many associations between objects in your data model and include backpointers when necessary.
When it comes time to optimizing the performance of your application, Data Management Services supports two ways of loading data on demand. You can enable paging for a given list of objects. When the initial set loads, only the first page of data is sent to the client. Any attempt to access an item in a page that has not been loaded causes that page to be loaded automatically. You can also provide prefetch hints, specifying which elements are desired in the future, so that you get a quick startup time while the rest of the data is loaded in the background.
Loading data on demand is an optional feature of associations. Individual associations can be marked as "lazy" and the value of the referenced object is loaded by the client only when it is accessed.
You can attach role-based authorization constraints to each type of data used by your application to prevent unauthorized access or modification of data. This facility is integrated into J2EE's authentication and authorization systems, so if you are already using this system, you can use Flex Data Services security constraints with very little additional work.
Data Management Services is designed to work for the large enterprise, so it will work for your application. It operates in a clustered environment to provide scalable and reliable data-intensive applications and is integrated to work seamlessly as a component of the Flex 2 application development framework.
Below is a simple functional Flex application that uses the declarative style enabled by MXML, data binding, and Data Management Services. You can find this example, which is part of the Flex 2 installation, in the file samples/dataservice/contact/mini.mxml:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="dataService.fill(contacts)">
<mx:ArrayCollection id="contacts"/>
<mx:DataService destination="contact" id="dataService""/>
<mx:Panel title="Contact List" width="100%" height="100%">
<mx:DataGrid id="dg" dataProvider="{contacts}" width="100%" height="100%" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="contactId" headerText="Id" editable="false"/>
<mx:DataGridColumn dataField="firstName" headerText="First Name"/>
<mx:DataGridColumn dataField="lastName" headerText="Last Name"/>
<mx:DataGridColumn dataField="phone" headerText="Phone"/>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:Application>
Because the data grid displaying your data is marked as editable, as you change data in the grid, those changes automatically propagate to the server and to other clients, which display the results of the same fill method you called.
Open a couple of browsers on this application and check it out!