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.
- Configure a synchronization profile to point to your host and port.
TestDB.getSynchronizationProfile().setServerName( "localhost" );
TestDB.getSynchronizationProfile().setPortNumber(2480);
- Log in to Unwired Server using a user name and password. This step is required for application initialization.
TestDB.loginToSync("supAdmin", "s3pAdmin");
- Subscribe to Unwired Server. Unwired Server creates a subscription for this particular application.
- 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");
- 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());
}
- 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();
- Submit the pending changes. The changes are ready for upload, but have not yet been uploaded to the Unwired Server.
Customer.submitPendingOperations();
- Upload the pending changes to the Unwired Server and get the replay results and all the changed MBO instances.
<PkgName>DB.beginSynchronize(sgs, "mycontext");
- Unsubscribe the device application if the application is no longer used.