Configuring an Application to Synchronize and Retrieve MBO Data

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

  1. Configure a synchronization profile to point to your host and port.
    TestDB.getSynchronizationProfile().setServerName( "localhost" );
    TestDB.getSynchronizationProfile().setPortNumber(2480);
  2. Log in to Unwired Server using a user name and password. This step is required for application initialization.
    TestDB.loginToSync("supAdmin", "s3pAdmin"); 
  3. Subscribe to Unwired Server. Unwired Server creates a subscription for this particular application.
    TestDB.subscribe();
  4. Synchronize with Unwired Server. Synchronization uploads all the local changes and downloads new data with related subscriptions.
    ObjectList sgs = new ObjectList();
    sgs.add(TestDB.getSynchronizationGroup("default"));
    TestDB.beginSynchronize(sgs, "mycontext");
  5. List all customer MBO instances from the local database using an object query. FindAll is a pre-defined object query.
    ObjectList customers = Customer.findAll();
    for(int i = 0; i < customers.size(); i++)
    {
      Customer customer = (Customer)(customers.elementAt(i));
      System.out.println("customer: " + customer.getFname() + " " + customer.getLname() 
      + " " + customer.getId()  + customer.getCity());
    }
    
  6. Find and update a particular MBO instance, and save to the local database.
    Customer cust = Customer.findByPrimaryKey(100);
    cust.setAddress(“1 Sybase Dr.”);
    cust.setPhone(“9252360000”);
    cust.save();//or cust.update();
    
  7. Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the Unwired Server.
    Customer.submitPendingOperations();
    
  8. Upload the pending changes to the Unwired Server and get the replay results and all the changed MBO instances.
    <PkgName>DB.beginSynchronize(sgs, "mycontext");
  9. Unsubscribe the device application if the application is no longer used.
    TestDB.unsubscribe();