This article uses the Restaurant Finder application for code examples of RPC-style data management. Data management can be grouped into four basic operations: create, retrieve, update, and delete (CRUD). I will look at the code used to implement each of these operations and discuss the limitations of the implementation and how Data Management Services can be used to improve the implementation.
Retrieve is the most fundamental part of any application involving data. Here is how the Restaurant Finder application retrieves reviews for a given restaurant:
public function set restaurantId(restaurantId:Object):Void
{
...
var call: Object = service.getReviews(restaurantId);
call.resultHandler = getReviewsResult;
}
private function getReviewsResult(event:ResultEvent):Void
{
reviews = new ArrayCollection(event.result);
}
The biggest limitation to retrieving data in this manner is that once the data is loaded, should it change on another client, there is no way for that change to propagate to all of the clients viewing that data set. The developer may need to implement some form of data refreshing and caching techniques to ensure that the client keeps in sync with the server.
Another limitation of this implementation is that there is no simple way to handle data preloading. Let's say you want to do background loading of the reviews so that when the user navigates to a different restaurant, the review data is already loaded. The developer is going to need to add complex code to handle the preloading in an efficient manner.
When using Data Management Services, if the data set changes, the server sends the list of changes to all connected clients viewing the changed data set. The data set on each client is then updated. To do background loading of data in Data Management Services, all that the developer needs to do is specify paging parameters on the Data Management Services destination.
Using Data Management Services to get the reviews for a given restaurant may look like the following:
private function init():Void
{
reviewDS = new DataService('review');
}
public function set restaurantId(restaurantId:Object):Void
{
reviewDS.fill(reviews,restaurantId);
}