Generating Change Logs

Use the Change Log API to generate change logs that are sent to the client after the synchronization.

In MBS, the application can use the information in the change logs to update its UI tables with new records and deletions. To do in the same in RBS, enable change logs in your application before synchronizing.

[SUP101SUP101DB enableChangeLog];

This method notifies you of all changes including the initial synchronization records. You may want to set a flag to indicate when the initial synchronization is done so you do not update the UI for all these initial records.

To set a flag, use code similar to this in your callback onSynchronize (isCompleteSynchronize is an application variable, set to true after the first synchronization is complete):
- (SUPSynchronizationActionType)onSynchronize:(SUPObjectList*)syncGroupList withContext:(SUPSynchronizationContext*)context
{
  if (context.status == SUPSynchronizationStatus_ERROR)
  {
      MBOLogError(@"onSynchronize failed for context %@ with exception %@", context.userContext, [context.exception reason]);
  } else if (context.status == SUPSynchronizationStatus_FINISHING)
  {
        
      if (self.isCompleteSynchronize)
      {
          // Handle change log
          SUPObjectList *changeLogs = (SUPObjectList *)[SUP101SUP101DB getChangeLogs:[SUPQuery getInstance]];
          if([changeLogs size] > 0)
          {
              [changeLogs retain];
                
              // delete these so we don't do updates later on these.
              [SUP101SUP101DB deleteChangeLogs];
              for (id<SUPChangeLog> cl in changeLogs)
              {
                  MBOLogDebug(@"Changelog: %@['%c', %ld]\n",
                              [SUP101SUP101DB getEntityName:[cl entityType]],
                              [cl operationType], [cl surrogateKey]);
                    
                  // If your UI needs to find the actual object you can
                  // convert the entity name to a class.
                  Class entityClass = NSClassFromString([SUP101SUP101DB  getEntityName:[cl entityType]]);
                  if (entityClass)
                  {
                      // You can either use the surrogate key or change to the "keyToString" equivalent.
                      NSString *primaryKey = [SUPStringUtil
                                              toString_long:[cl surrogateKey]];
                      NSString *type = ([cl operationType] == 'D'
                                        ) ? @"delete" : @"update";
                        
                      // Notify your UI with NSNotification...
                  } //entityClass
                }
              [changeLogs release];
          }
      }
  }
    
  return SUPSynchronizationAction_CONTINUE;
}