Nonblocking Synchronization

An example that illustrates the basic code requirements for connecting to Unwired Server, updating mobile business object (MBO) data, and synchronizing the device application from a device application based on the Client Object API.

Subscribe to the package using synchronization APIs in the generated database class, specify the groups to be synchronized, and invoke the asynchronous synchronization method (beginSynchronize).

  1. If you have not yet synchronized with Unwired Server, perform a synchronization.
    SUP101DB.synchronize("system")
  2. Set the synchronization parameters if there are any.
    CustomerSynchronizationParameters syncParameter = Customer.getSynchronizationParameters();
    syncParameter.setYourParameters(...);
    syncParameter.save(); 
  3. Make a blocking synchronize call to Unwired Server to pull in all MBO data:
    SUP101DB.synchronize();
  4. List all customer MBO instances from the local database using an object query, such as FindAll, which is a predefined object query.
    GenericList<Customer> customers = Customer.findAll();
    int n = customers.size();
    for (int i = 0; i < n; i )
    {
      Customer customer = customers.get(i);
      //Work on customer information
    }
    
  5. Find and update a particular MBO instance, and save it to the local database.
    Customer cust = Customer.findByPrimaryKey(100);
    cust.setAddress("1 Sybase Dr.");
    cust.setPhone("9252360000");
    cust.save();//or cust.update();
    
  6. Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the Unwired Server.
    cust.submitPending();
    
  7. Use non-blocking synchronize call to upload the pending changes to the Unwired Server. The previous replay results and new changes are downloaded to the client device in the download phase of the synchronization session.
    GenericList<SynchronizationGroup> sgs = new GenericList<SynchronizationGroup>();
    sgs.add(SUP101DB.getSynchronizationGroup("default")); // Customer MBO is in "default" sync group
    SUP101DB.beginSynchronize(sgs, "mycontext");