Download Developer Guide for BlackBerry
Transcript
Development Task Flow
public class JavaMain extends net.rim.device.api.ui.UiApplication{
public JavaMain() {
}
public static void main(String [] args) throws Exception
{
//Configure synchronization profile to point to your host and
port
TestDB.getSynchronizationProfile().setServerName( "localhost" );
TestDB.getSynchronizationProfile().setPortNumber(2480);
//If the application requires a callback (for example, to allow
the client framework to provide
//notification of synchronization results),register the callback
//function after setting up the connection profile, by executing
MyCallbackHandler callback = new MyCallbackHandler();
TestDB.registerCallbackHandler(callback);
//Login to Unwired Server. This step is required for application
initialization.
TestDB.loginToSync("supAdmin", "s3pAdmin");
//Subscribe to Unwired Server. Unwired Server creates a
subscription for this particular application.
TestDB.subscribe();
//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");
//Wait for synchronization to complete. May not be required for a
typical UI application.
Thread.sleep(1000*10);
//List all customer MBO instances from the local database using a
named query. FindAll is a pre-defined object query.
//Alternatively you can use Dynamic Query to MBO instances too.
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 a particular MBO instance.
Customer cust = Customer.findByPrimaryKey(441);
cust.setAddress( "1 Sybase Dr.");
cust.setPhone( "9252360000");
//Update the customer MBO instance. Save to the local database.
cust.save();
//Submit the pending changes. The changes are ready for upload,
Developer Guide for BlackBerry
19