Nonblocking Synchronization

An example that illustrates the basic code requirements for connecting to SAP Mobile 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. Make a blocking synchronize call to SAP Mobile Server to pull in all MBO data:
    SMP101DB.synchronize();
  2. List all customer MBO instances from the local database using an object query, such as findAll, which is a predefined object query.
    ObjectList customers = Customer.findAll();
    int n = customers.count();
    for (int i = 0; i < n; ++i )
    {
      Customer c = (Customer)customers.elementAt(i);
      //Work on customer information
    }
  3. 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();
    
  4. Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the SAP Mobile Server.
    cust.submitPending();
    
  5. Use non-blocking synchronize call to upload the pending changes to the SAP Mobile Server. The previous replay results and new changes are downloaded to the client device in the download phase of the synchronization session.
    ObjectList sgs = new ObjectList();
    sgs.add(SMP101DB.getSynchronizationGroup("default")); // Customer MBO is in "default" sync group
    SMP101DB.beginSynchronize(sgs, "mycontext");