OfflineDataCollection

The Clear component library includes a descendant of DataCollection (described in Chapter ), the com.farata.collections.OfflineDataCollection class. The class OfflineDataCollection is responsible for performing data synchronization between the local and remote databases.

If the network connection is available, the method fill() gets the data from the server and the application creates the backup copy of the existing local database and creates a fresh one:

public override function fill(... args):AsyncToken {
      var changes:Array=getChangesFromLocalDB();
      syncRequired=changes.length > 0;
      if (!commitRequired && !syncRequired) {
         var act:AsyncToken=invoke(method, args);
         act.method="fill";
         return act;
      }else{
         fillFromLocalDB();
      }
   return null;
}

This function starts with getting the data from the local database. If this is the very first invocation, the array changes will be empty and no other function calls will be made.

If no modifications were made in the data grid with visit information and no unsynchronized changes exist in the local database, this function will just retrieve the data from the remote destination using DataCollection’s invoke() method.

How does OfflineDataCollection know that there are local changes to be synchronized? Each instance of OfflineDataCollection persists its data in a database table. When the application calls the function OfflineDataCollection.backup(), it copies this table to a backup database.

Comparing the content of the corresponding tables ...

Get Agile Enterprise Application Development with Flex now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.