Sun GlassFish Mobility Platform 1.1 Developer's Guide for Client Applications

Synchronizing Data with the Server

Once users have created or modified objects on the client using BusinessObjectStorage methods, they can use SyncManager methods to synchronize the modified data with the server. Synchronization includes the following tasks:

Setting User Credentials

The gateway requires username/password authentication for secure access. Before performing a synchronization, the MIDlet must call the SyncManager.setCredentials method, which takes three arguments: the username, the password, and the HTTP/S URL of the gateway. In SecureJdbcMIDlet.java, the arguments are supplied by three GUI methods, as follows:

syncMgr.setCredentials(
        getUserName().getString(),
        getPassword().getString(),
        getSyncServer().getString());

These methods obtain input from the user and return TextField values.

The initial creation of users is a Sun GlassFish Mobility Platform administrative task, described in the Sun GlassFish Mobility Platform 1.1 Administration Guide

Performing Synchronization

Once user credentials are established, synchronization can take place. The SecureJdbcMIDlet code calls the SyncManager.sync method, which takes a SyncType argument. In this case, the code calls a method that returns a SyncType value:

syncMgr.sync(getSelectedSyncType());

The getSelectedSyncType method in turn uses the value returned by a GUI method, getSyncType.

Retrieving Synchronization Results

After a successful synchronization, you can retrieve and display information about the synchronization results. The SecureJdbcMIDlet code retrieves the results using the SyncManager.getSyncResults method, which returns a SyncResults value:

SyncResults results = syncMgr.getSyncResults();

It then displays the results in a GUI form by calling SyncResults methods. These methods can return either the number of items changed or a list of the actual business objects that were changed. The SecureJdbcMIDlet code displays only the number of items changed.