4 Invoking Synchronization APIs from Applications

The following sections describe the APIs available to start synchronization programmatically within your application, whether the application is C, C++, or Java:

4.1 Synchronization APIs For C or C++ Applications

You can initiate and monitor synchronization from a C or C++ client application. The synchronization methods for the C/C++ interface are contained in ocapi.h and ocapi.dll, which are located in the <ORACLE_HOME>\Mobile\bin directory.

A C++ example is provided in the <ORACLE_HOME>\Mobile\Sdk\Samples\sync\msync\src directory. The source code is contained in SimpleSync.cpp. The executable—SimpleSync.exe—is in the <ORACLE_HOME>\Mobile\Sdk\Samples\sync\msync\bin directory.

The functions available for setting up and initiating the synchronization are as follows:

  1. Section 4.1.1, "Overview of Synchronization API"

  2. Section 4.1.2, "Initializing the Environment With ocSessionInit"

  3. Section 4.1.3, "Managing the C/C++ Data Structures"

  4. Section 4.1.4, "Retrieving Publication Information With ocGetPublication"

  5. Section 4.1.5, "Managing User Settings With ocSaveUserInfo"

  6. Section 4.1.6, "Manage What Tables Are Synchronized With ocSetTableSyncFlag"

  7. Section 4.1.7, "Configure Proxy Information"

  8. Section 4.1.8, "Start the Synchronization With the ocDoSynchronize Method"

  9. Section 4.1.9, "Clear the Synchronization Environment Using ocSessionTerm"

  10. Section 4.1.10, "Retrieve Synchronization Error Message with ocGetLastError"

4.1.1 Overview of Synchronization API

The Synchronization API does not run under the eshell.exe. For starting synchronization, the application performs the following:

  1. Create, memset, and initialize the ocEnv structure.

  2. Set any optional fields in the ocEnv structure before you execute the ocSessionInit method. Additionally, you can set proxy information in the ocSetSyncOption method, or optionally specify synchronization type for each table with the ocSetTableSyncFlag function.

  3. Invoke the ocSessionInit() method.

  4. If you want to update the ocEnv structure after the ocSessionInit, you can perform the ocSaveUserInfo method.

  5. Invoke the ocDoSynchronize() method, which returns after the synchronization completes, an error occurs, or the user interrupts the process. While executing, the ocDoSynchronize function invokes any callback function set in the ocEnv.fnProgress field. The callback function must not call any blocking functions, as this process is not reentrant or threaded.

  6. Once synchronization completes, then invoke the ocSessionTerm() method to clear the ocEnv data structure.

  7. If synchronization failed, then use the ocGetLastError function to retrieve the error message.

For an example, see the msync.cpp sample code.

4.1.2 Initializing the Environment With ocSessionInit

The ocSessionInit function initializes the synchronization environment—which is contained in the ocEnv structure or was created with ocSaveUserInfo. For more information, see Section 4.1.5, "Managing User Settings With ocSaveUserInfo".

Note:

Every time you invoke the ocSessionInit function, you must also clean up with ocSessionTerm. These functions should always be called in pairs. See Section 4.1.9, "Clear the Synchronization Environment Using ocSessionTerm" for more information.

Syntax

int ocSessionInit( ocEnv env );

Table 4-1 lists the ocSessioninit parameter and its description.

Table 4-1 ocSessionInit Parameters

Name Description

env

An ocEnv class, which contains the synchronization environment.


This call initializes the ocEnv structure—which holds context information for the synchronization engine—and restores any user settings that were saved in the last ocSaveUserInfo call, such as username and password (See Section 4.1.5, "Managing User Settings With ocSaveUserInfo"). An ocEnv structure is passed as the input parameter. Perform the following to prepare the ocEnv variable:

  1. Create the ocEnv by allocating a variable the size of ocEnv.

  2. Memset the ocEnv variable before invoking the ocSessionInit function. If you do not perform a memset on the ocEnv variable, then the ocSessionInit function will not perform correctly.

  3. Set all required fields in the ocEnv structure before passing it to ocSessionInit. If the caller wants to overwrite user preference information after the ocSessionInit() call, it can be done by calling ocSaveUserInfo.

For a full description of ocEnv, see Section 4.1.3.1, "ocEnv Data Structure".

The following example allocates a new ocEnv, which is then passed into the ocSessionInit call.

env = new ocEnv;
// Reset ocenv
memset( env, 0, sizeof(ocEnv) );
 
// init OCAPI
ocError rc = ocSessionInit(env);

4.1.3 Managing the C/C++ Data Structures

Two data structures—ocEnv Data Structure and ocTransportEnv Data Structure—are used for certain functions in the Mobile Sync API.

4.1.3.1 ocEnv Data Structure

The ocEnv data structure holds internal memory buffers and state information. Before using this structure, the application initializes it by passing it to the ocSessionInit method.

Table 4-2 lists the field name, type, usage, and corresponding description of the ocEnv structure parameters.

  • Required—If the usage is required, then you either set before calling the ocSessionInit function or you have saved these parameters previously with the ocSaveUserInfo function.

  • Optional—If the usage is optional, then optionally set after calling the ocSessionInit function and before the ocDoSynchronize function.

  • Read Only.

Table 4-2 ocEnv Structure Field Parameters

Field Type Usage Description

username

char[32]

Required.

Name of the user to authenticate. This name is limited to 28 characters, because of other parts of the product.

password

char[32]

Required.

User password (clear text). This name is limited to 28 characters, because of other parts of the product.

trType

Enum

Required.

If set to 0 (OC_BUILDIN_HTTP), then use HTTP built-in transport driver. This is the default. If set to OC_USER_METHOD, then use user provided transport functions.

newPassword

char[32]

Optional.

If first character of this string is not null—in otherwords (char) 0—this string is sent to the server to change the user password; the password change is effective on the next synchronization session.

savePassword

Short

Optional.

If set to 1, the password is saved locally and is loaded the next time ocSessionInit is called.

appRoot

char[32]

Optional.

Directory to where the application will be copied. If first character is null, then it uses the default directory.

priority

Short

Optional.

0= OFF (default)

1= ON; Only high priority table or rows are synchronized when turned on.

secure

Short

Optional.

If set to 0, then AES is used on the transport. If set to OC_SSL_ENCRYPTION, use SSL synchronization (SSL-enabled device only).

syncDirection

Enum

Optional.

If set to 0 (OC_SENDRECEIVE), then sync is bi-directional (default).If set to OC_SENDONLY, then push changes only to the server. This stops the sync after the local changes are collected and sent. User must write own transport method (like floppy bases) when using this method.If set to OC_RECEIVEONLY, then send no changes and only receive update from server. This only performs the receive and allow changes function to local database stages.

exError

ocError

Read-only.

Extended error code - either OS or OKAPI error code.

transportEnv

ocTransportEnv

 

Transport buffer. See Section 4.1.3.2, "ocTransportEnv Data Structure".

progressProc

fnProgress

Optional.

If not null, points to the callback for progress listening. See Section 4.1.8.1, "See Progress of Synchronization with Progress Listening".

totalSendDataLen

Long

 

Reserved

totalRecieveDataLen

Long

 

Reserved

userContext

Void*

Optional.

Can be set to anything by the caller for context information (such as progress dialog handle, renderer object pointer, and so on.

ocContext

Void*

 

Reserved.

logged

Short

 

Reserved.

bufferSize

Long

 

Reserved (for Wireless/Nettech only).

pushOnly

Short

Optional.

If set to 1, then only push changes to the server.

syncApps

Short

Optional.

Set to 1 (by default), performs application deployment. If set to 0, then no applications will be received from the server.

syncNewPublications

Short

Optional.

If set to 1 (default), receives any new publication created from the server since last synchronization. If set to 0, only synchronizes existing publications (useful for slow transports like wireless).

clientDbMode

Enum

Optional.

If set to OC_DBMODE_EMBEDDED (default), it uses local Oracle Database Lite ODBC driver. If set to OC_DBMODE_CLIENT, it uses the Branch Office driver.

syncTimeLog

Short

Optional.

If set to 1, log sync start time is recorded in the conscli.odb file.

updateLog

Short

Optional.

Debug only. If set to 1, logs server-side insert and update row information to the publication odb.

options

Short

Optional.

Debug only. A bitset of the following flags:

  • OCAPI_OPT_SENDMETADATA

    Sends meta-info to the server.

  • or OCAPI_OPT_DEBUG

    Enables debugging messages.

  • OCAPI_OPT_DEBUG_F

    Saves all bytes sent and received for debugging.

  • OCAPI_OPT_NOCOMP

    Disables compression.

  • OCAPI_OPT_ABORT

    If set, OCAPI will try to abort the current sync session.

  • OCAPI_OPT_FULLREFRESH

    Forces OCAPI to purge all existing data and do a full refresh.

cancel

Short

 

Caller can set to 1 on next operation. ocDoSyncrhonize returns with -9032.


The environment structure contains fields that the caller can update to change the way Mobile Sync module works. The following example demonstrates how to set the fields within the ocEnv structure.

typedef struct ocEnv_s {
 // User info
char username[MAX_USERNAME];    // Mobile Sync Client id, limited to 28 characters

char password[MAX_USERNAME];    // Mobile Sync Client password for 
                                // authentication during sync, limited to 28 chars

char newPassword[MAX_USERNAME]; // resetting Mobile Sync Client password 

                                   // on server side if this field is not blank 
short savePassword;           // if set to 1, save password 

char appRoot[MAX_PATHNAME];     // dir path on client device for deploying files

short priority;              // High priority table only or not

short secure;            // if set to 1, data encrypted over the wire 

enum {

OC_SENDRECEIVE = 0,     // full step of synchronize

OC_SENDONLY,     // send phase only

OC_RECEIVEONLY,     // receive phase only
OC_SENDTOFILE,     // send into local file | pdb

OC_RECEIVEFROMFILE     // receive from local file | pdb

}syncDirection;     // synchronize direction


enum {
OC_BUILDIN_HTTP = 0,     // Use build-in HTTP transport method

OC_USER_METHOD     // Use user defined transport method

}trType;           // type of transport


ocError exError;     // extra error code


ocTransportEnv transportEnv;     // transport control information 


                       // GUI related function entry

progressProc fnProgress;     // callback to track progress; this is optional


                 // Values used for Progress Bar. If 0, progress bar won't show.
long totalSendDataLen; // set by Mobile Sync API informing transport total number 
                     // of bytes to send; set before the first fnSend() is called

long totalReceiveDataLen;     // to be set by transport informing Mobile Sync API 

                       // total number of bytes to receive; 

                       // should be set at first fnReceive() call. 

void* userContext;     // user defined context
void* ocContext;       // internal use only
short logged;          // internal use only
long bufferSize;       // send/receive buffer size, default is 0
short pushOnly;        // Push only flag
short syncApps;        // Application deployment flag
short cancel;          // cancel   

} ocEnv;

4.1.3.2 ocTransportEnv Data Structure

You can configure the HTTP URL, proxy, proxy port number and other HTTP-specific transport definitions in the ocTrHttp structure. This structure is an HTTP public structure defined in octrhttp.h.

You access the ocTrHttp structure from within the ocTransportEnv data structure, which is provided as part of the ocEnv data structure. The following demonstrates the fields within the ocTransportEnv structure:

typedef struct ocTransportEnv_s {

void* ocTrInfo;            // transport internal context

The ocTrInfo is a pointer that points to the HTTP parameters in the ocTrHttp structure. The following code example retrieves the ocTrInfo pointer to the HTTP parameters and then modifies the URL, proxy, and proxy port number to the input arguments:

ocTrHttp* http_params = (ocTrHttp*)(env->transportEnv.ocTrInfo);
// set server_name
strcpy(http_params->url, argv[3]); 
// set proxy
strcpy(http_params->proxy, argv[4]); 
// set proxy port
http_params->proxyPort = atoi(argv[5])

4.1.4 Retrieving Publication Information With ocGetPublication

This function gets the publication name on the client from the Web-to-Go application name. The Web-to-Go user knows only the application name, which happens when the Packaging Wizard is used to package an application before publishing it. If the Web-to-Go application needs the publication name in order to interact with the database, then this function is used to retrieve that name, given the application name.

Syntax

ocError ocGetPublication(ocEnv* env, const char* application_name, 
 char* buf, int buf_len);

The parameters for the ocGetPublication function are listed in Table 4-3 below.

Table 4-3 ocGetPublication Parameters

Name Description

ocEnv* env

Pointer to an ocEnv structure buffer to hold the return synchronization environment.

const char* application_name(in)

The name of the application.

char* buf(out)

The buffer where the publication name is returned.

int buf_len(in)

The buffer length, which must be at least 32 bytes.


Return value of 0 indicates that the function has been executed successfully. Any other value is an error code.

The following code example demonstrates how to get the publication name.

void sync()

{

         ocEnv env;

         int rc;


         // Clean up ocenv

         memset(&env 0, sizeof(env) );

         

         // init OCAPI

         rc = ocSessionInit(&env);


         strcpy(env.username, "john");

         strcpy(env.password, "john");


         // We use transportEnv as HTTP paramters

         ocTrHttp* http_params = (ocTrHttp*)(env.transportEnv.ocTrInfo);

         strcpy(http_params->url, "your_host");


         // Do not sync webtogo applicaton "Sample3"
         char buf[32];

         rc = ocGetPublication(&env, "Sample3", buf, sizeof(buf));

         rc = ocSetTableSyncFlag(&env, buf, NULL, 0);


         // call sync

         rc = ocDoSynchronize(&env);

         if (rc < 0)

                fprintf(stderr, "ocDoSynchronize failed with %d:%d\n",                      rc, env.exError);

         else

                printf("Sync compeleted\n");

         

         // close OCAPI session

         rc = ocSessionTerm(&env);

         return 0;

}

4.1.5 Managing User Settings With ocSaveUserInfo

Saves user settings for the ocEnv structure. These settings can be used for the current session or used by the ocSessionInit function to initialize the environment when next invoked.

Syntax

int ocSaveUserInfo( ocEnv *env );

Table 4-4 lists the ocSaveUserInfo parameter and its description.

Table 4-4 ocSaveUserInfo Parameters

Name Description

env

Pointer to the synchronization environment.


This saves or overwrites the user settings into a file or database on the client side. The following information provided in the environment structure is saved:

  • username

  • password

  • savePassword

  • newPassword

  • priority

  • secure

  • pushOnly

  • syncApps

  • syncNewPublications

If you use the HTTP default transport set in the ocTransportEnv structure, then the following is also saved:

  • url

  • useProxy

  • proxy

  • proxyPort

For more information on how to use these fields, see Section 4.1.3, "Managing the C/C++ Data Structures".

4.1.6 Manage What Tables Are Synchronized With ocSetTableSyncFlag

Update the table flags for selective sync. Call this for each table to specify whether it should be synchronized(1) or not (0) for the next session. Selective sync only works if you have first performed at least one synchronization for the client. Then, set the flag so that on the next synchronize—that is, before the next invocation of the ocDoSynchronize method—a selective sync occurs.

Note:

Automatic synchronization is based on a different model than manual synchronization. Automatic synchronization operates on a transactional basis. Thus, the selective sync option is not supported when you use automatic synchronization for a publication, since we are no longer concerned with synchronization of only a subset of data.

The default sync_flag setting for ocSetTableSyncFlag is TRUE (1) for all the tables; that is, all tables are flagged to be synchronized. If you want to selectively synchronize specific tables, you must first disable the default setting for all tables and then enable the synchronization for only the specific tables that you want to synchronize.

Syntax

ocSetTableSyncFlag(ocEnv *env, const char* publication_name, 
              const char* table_name, short sync_flag)

Table 4-5 lists the name and description of parameters for the ocSetTableSyncFlag function.

Table 4-5 ocSetTableSyncFlag Parameters

Name Description

env

Pointer to the synchronization environment.

publication_name

The name of the publication which is being synchronized. If the value for the publication_name is NULL, it means all publications in the database. This string is the same as the client_name_template parameter of the Consolidator Manager CreatePublication method. In most cases, you will use NULL for this parameter. For more information, see Section 3.4, "Creating Publications Using Oracle Database Lite APIs".

table_name

This is the name of the snapshot. It is the same as the name of the store, the third parameter of CreatePublicationItem(). For more information, see Section 3.4, "Creating Publications Using Oracle Database Lite APIs".

sync_flag

If the sync_flag is set to 1, you must synchronize the publication. If the sync_flag is set to 0, then do not synchronize. The value for the sync_flag is not stored persistently. Each time before ocDoSynchronize(), you must call ocSetTableSyncFlag().


This function allows client applications to select the way specific tables are synchronized.

Set sync_flag for each table or each publication. If sync_flag = 0, the table is not synchronized.

To synchronize specific tables only, you must perform the following steps:

  1. Disable the default setting, which is set to 1 (TRUE) for all the tables.

    Example:

    ocSetTableSyncFlag(&env, <publication_name>,null,0)
    
    

    Where <publication_name> must be replaced by the actual name of your publication, and where the value null is specified to mean all the tables for that publication without exception.

  2. Enable the selective sync for specific tables.

    Example:

    ocSetTableSyncFlag(&env, <publication_name>,<table_name>,1)
    

4.1.7 Configure Proxy Information

If you are using a firewall and need to configure proxy information, perform the following before you execute the ocDoSynchronize method:

  1. Configure the proxy URL, IP address and/or port number through the ocSaveUserInfo function. See Section 4.1.5, "Managing User Settings With ocSaveUserInfo" for more information.

  2. If required, configure the proxy username and password. To configure the proxy username and password, use the ocSetSyncOption and provide the following:

    ocSetSyncOption( env, "HTTPUSER=<username>;HTTPPASS=<password>");
    

    Note:

    The username and password are limited to 28 characters.

    Where the ocSetSyncOption syntax is as follows:

    int ocSetSyncOption(ocEnv *env, const char *str);
    
    

You can set one or more name/value pairs searated by a semi-colon in the string. The previous example shows the HTTPUSER and HTTPPASS name/value pairs. You can also set the URL string as follows: URL=www.myhost.com.

4.1.8 Start the Synchronization With the ocDoSynchronize Method

Starts the synchronization process.

Syntax

int ocDoSynchronize( ocEnv *env );

Table 4-6 lists the name and description of the ocDoSynchronize parameter.

Table 4-6 ocDoSynchronize Parameters

Name Description

env

Pointer to the synchronization environment.


This starts the synchronization cycle. A round trip synchronization is activated if syncDirection is OC_SENDRECEIVE (default). If syncDirection is OC_SENDONLY or OC_RECEIVEONLY, then the developer must implement a custom transport. If the developer wishes to upload only changes, then set pushonly=1. You cannot only download changes under the existing synchronization architecture.

This method returns when the synchronize completes. A return value of 0 indicates that the function has been executed successfully. If an error occurred, local errors are returned by ocDoSynchronize, which are defined in ocerror.h. For errors returned by the server, see the ol_sync.log error log file, which is written into the working directory of the application. Each line in the error file has the following format:

<type>, <code>, <date>, <message>

Where:

  • <type>: The type of the message, which can either be set to ERROR or SUCCESS.

  • <code>: Error code of the last operation of the synchronization.

  • <date>: Date and timestamp for when the synchronization completes. This is in the format of dd/mm/yyyy hh:mm:ss.

  • <message>: A readable message text.

4.1.8.1 See Progress of Synchronization with Progress Listening

If you create and set the progress callback function, then Oracle Database Lite invokes this callback function at different times while the ocDoSynchronize method is executing. Create the callback function, as follows:

void myProgressProc ( void *env, int stage, int present);

When the ocDoSynchronize invokes your myProgressProc function, it provides the following information as input to your function:

  • env—A pointer to the environment (ocEnv structure) for the synchronization session. This provides the function to retrieve the userContext pointer.

  • stage—A number that denotes the stage in the synchronization process, which is one of the following values, where these values are defined in ocapi.h:

    Table 4-7 Description of the Stage Values

    Stage Value Description

    OC_PREPARE_START

    Start of the prepare stage, which collects all internal data from the database and prepares to send the data to the server.

    OC_PREPARING

    Progress in the prepare stage.

    OC_PREPARE_FINISH

    Prepare stage is completed.

    OC_SEND_START

    Starting to send the data to the server.

    OC_SENDING

    Sending the data.

    OC_SEND_FINISH

    Completed sending the data.

    OC_RECEIVE_START

    Starting to receive data.

    OC_RECEIVING

    Receiving data from the server.

    OC_RECEIVE_FINISH

    Completed receiving data from the server.

    OC_PROCESS_START

    Starting to process received data.

    OC_PROCESSING

    Processing received data.

    OC_PROCESS_FINISH

    Completed processing. Synchronization is finished.


  • present—The percentage completed in the particular stage that synchronization is in from 0 to 100.

If the function is a member of a class, then it must be defined as static.

After you create the callback function, set the function pointer in the ocEnv.fnProgress (Table 4-2) to the address of your callback function. Save this with the ocSaveUserInfo or ocSessionInit methods.

4.1.9 Clear the Synchronization Environment Using ocSessionTerm

Clears and performs a cleanup of the synchronization environment and buffers. This function must be invoked for every ocSessionInit, even if the ocDoSynchronize function is not performed.

Syntax

int ocSessionTerm( ocEnv *env );

Table 4-8 lists the ocSessionTerm parameter and its description.

Table 4-8 ocSessionTerm Parameters

Name Description

env

Pointer to the environment structure returned by ocSessionInit.


De-initializes all the structures and memory created by the ocSessionInit() call. Users must ensure that they are always called in pairs.

4.1.10 Retrieve Synchronization Error Message with ocGetLastError

Retrieves the synchronization error message and code. For a Symbian device, this function can also report if the synchronization is still in process.

Syntax

int ocGetLastError( ocEnv *env, char *buf, int buf_size);

Table 4-9 lists the ocGetLastError parameters.

Table 4-9 ocGet Parameters

Name Description

env

Pointer to the environment structure returned by ocSessionInit.

buf

A string with the error message.

buf_size

The size of the error message string.


4.2 Synchronization API for Java Applications

The following sections describe how you can use Java on a WinCE device to build your own client synchronization initiation:

4.2.1 Overview

Using the Java interface for Mobile Sync client-side synchronization tasks, programs written in Java can use the functionality provided by the OCAPI library. The Java interface resides in the oracle.lite.msync package.

The Java interface provides for the following functions:

  • Setting client side user profiles containing data such as user name, password, and server

  • Starting the synchronization process

  • Tracking the progress of the synchronization process

The Java interface consists of two files, olite40.jar and msync_java.dll. To use the Java interface, the olite40.jar file must be included in the CLASSPATH. The olite40.jar file is located in the following directory.

<ORACLE_HOME>\Mobile\classes

The msync_java.dll file is located in the following directory.

<ORACLE_HOME>\Mobile\bin

There are four parts to the Java interface. They are:

  • Sync Class

  • SyncException Class

  • SyncOption Class

  • SyncProgressListener Interface

The following sections describe the Java interface.

4.2.2 Sync Class

This class initiates synchronization by using the provided synchronization options. The parameters for the constructor are listed in Table 4-10.

Constructors

Sync(SyncOption option)

Table 4-10 Sync Class Constructor

Parameter Description

option

Instance of the SyncOption Class. This contains all the parameters needed to perform synchronization.


Public Methods

To monitor the progress of the synchronization process, the public method SyncProgressListener adds a progress listener to the object.

SyncProgressListener add(ProgressListener listener)

The parameters for the SyncProgressListener method are described in Table 4-11.

Table 4-11 Sync Class Public Method

Parameter Description

listener

An object that implements the ProgressListener interface. The synchronization object calls the progress() function of this object to notify it of the synchronization progress.

void doSync ()

Starts a synchronization session and blocks that thread until synchronization is complete.

void abort ()

Aborts the synchronization session.


The following code demonstrates how to start a session using the default settings.

try
{
  Sync mySync = new Sync( new SyncOption());
  mySync.doSync();
}
catch ( SyncException e)
{
  System.err.println( "Sync Error:"+e.getMessage());
}

4.2.3 SyncException Class

This class signals a non-recoverable error during the synchronization process. The SyncException() class constructs a clear object. The parameters for the constructor are listed inTable 4-12:

Constructors

SyncException()

SyncException(int errorCode, string errorMessage)

Table 4-12 syncException Constructor Parameter Description

Parameter Description

errorCode

The error. Refer the Oracle Database Lite Message Reference.

errorMessage

A readable text message that provides extra information.


Public Methods

The methods for the SyncException are listed in Table 4-13.

Table 4-13 SyncExceptionClass Public Methods

Parameters Description

int getErrorCode()

Gets the error code.

String getErrorMessage

Gets the error message.


4.2.4 SyncOption Class

The SyncOption class is used to define the parameters for the synchronization process. It can either be constructed manually, or can save or load data from the user profile.

Constructors

SyncOption()
 
SyncOption
   ( String user,
     String password,
     String syncParam,
     String transportDriver,
     String transportParam)

The parameters for the SyncOption constructor are listed in Table 4-14:

Table 4-14 SyncOption Constructors

Parameter Description

user

A string containing the name used for authentication by the Mobile Server.

password

A string containing the user password.

syncParam

A string which defines an optional list of parameters for the synchronization session. See Section 4.2.5, "Java Interface SyncParam Settings" for more information.

transportDriver

A string containing the name of the transport driver. Currently, only "HTTP" is supported.

transportParam

A string containing all the parameters needed for the specified driver to operate. See Section 4.2.6, "Java Interface TransportParam Parameters" for more information.

priority

A boolean value which limits synchronization to server tables flagged as high priority, otherwise all tables are synchronized.

pushOnly

A boolean value which makes synchronization push only.


Public Methods

These methods load and save the user profile. The parameters of the public methods are listed in Table 4-15:

Table 4-15 Sync Option Public Method Parameters

Parameter Description

void load(String username)

This loads the profile for the specified user name. If the user name is left null, the profile is loaded for the last user to synchronize.

void save()

This saves the settings to the profile for the active user.

void setUser(String username)

This is used to set and get the current user.

String getuser()

 

void setPassword(String password)

String getPassword()

This is used to set and get the password.

void setSyncParam(String syncParam)

string getSyncParam()

This is used to set and get the synchronization parameters.

void setTransportDriver(String driverName)

String getTransportDriver()

This is used to set and get the driver name. Release 5.0.2 supports the "HTTP" driver.

void setTransportParam(String transportParam)

String getTransportParam()

Set and get the transport parameters.


Example 1

The following code example demonstrates how to start a synchronization session using the default settings:

SyncOption opt = new SyncOption
 
("sam","lion","pushonly","HTTP","server=server1;proxy=www-proxy.us.oracle.com;proxyPort=80");
 
opt.save();

Example 2

The following example is of a client that creates the SyncOption class and then performs the synchronization with the doSync method.

import oracle.lite.mSync.*;
 
public class JavaSyncClient{
    String user = "SALES1";
    String password = "MANAGER";
    //Set the Sync params
    //Set syncParam to fullrefresh
    String syncParam = "";//fullrefresh;
    // Set the Transport params
    String transportDriver = "HTTP";
    String trasportParam = "server=localhost";
    
    /**
     * Constructor
     */
    public JavaSyncClient() throws Exception{
        //Create the SyncOption class
        SyncOption syncOpt = new SyncOption(user, password,
            syncParam, transportDriver, trasportParam);
        syncOpt.setSyncFlag("MYORDERS", "", (short) 0);
        //Save the options before the sync
        syncOpt.save();
        //Create the Sync class
        Sync mySync = new Sync(syncOpt);
        //Perform the synchronization
        mySync.doSync();
    }
 
    /**
     * main
     */
    public static void main(String[] args)  throws Exception {
        JavaSyncClient JavaSyncClient = new JavaSyncClient();
    }
}

4.2.5 Java Interface SyncParam Settings

The syncParam is a string that can be passed when creating the SyncOption object. It allows support parameters to be specified to the synchronization session. The string is constructed of name-and-value pairs. For example:

"name=value;name2=value2;name3=value3, ...;"

The names are not case sensitive, but the values are. The field names which can be used are listed in Table 4-16.

Table 4-16 Java Interface SyncParamSettings

Name Value/Options Description

"reset"

N/A

Clear all entries in the environment before applying any remaining settings.

"security"

SSL or AES

Use the appropriate selection to choose either SSL or AES stream encryption.

"push only"

N/A

Use this setting to upload changes from the client to the server only, do not download. This is useful when data transfer is one way, client to server.

"noapps"

N/A

Do not download any new or updated applications. This is useful when synchronizing over slow connection or on a slow network.

"syncDirection"

"sendonly" "receiveonly"

"SendOnly" is the same as "pushonly".

"ReceiveOnly" allows no changes to be posted to the server.

"noNewPubs"

N/A

This setting prevents any new publications created since the last synchronization from being sent, and only synchronizes data from the current publications.

"tableFlag"

"enable"

The "enable" setting allows [Publication.Item] to be synchronized, "disable" prevents synchronization.

[Publication.Item]

"disable"

 

"fullrefresh"

N/A

Forces a complete refresh.

"clientDBMode"

"EMBEDDED" or "CLIENT"

If set to "EMBEDDED", access to the database is by conventional ODBC, if set to "CLIENT" access is by multi-client ODBC.


Example 1

The first example enables SSL security and disables application deployment for the current synchronization session:

"security=SSL; noapps;"

Example 2

The second example resets all previous settings, activates upload for the "Dept" table only:

"reset;pushOnly;tableFlag[TestApp.Emp]=disable;tableFlag[TestApp.Dept]=enable;"

4.2.6 Java Interface TransportParam Parameters

The format of the TransportParam string is used to set specific parameters using a string of name-and-value pairs, for example:

"name=value;name2=value2;name3=value3, ...;"

The names are not case sensitive, but the values are. The field names which can be used are listed in Table 4-17.

Table 4-17 TransportParam Parameters

Name Value Description

"reset"

N/A

Clear all entries in the environment before applying the rest of the settings.

"server"

server hostname

The hostname or IP address of the Mobile Server.

"proxy"

proxy server hostname

The hostname or IP address of the proxy server.

"proxyPort"

port number

The port number of the proxy server.

"cookie"

cookie string

The cookie to be used for transport.


Example

The example directs the Mobile Sync engine to use the server at "test.oracle.com" through the proxy "proxy.oracle.com" at port 8080:

"server=test.oracle.com;proxy=proxy.oracle.com;proxyPort=8080;"

4.2.7 Manage What Tables Are Synchronized With Selective Sync

Update the table flags for selective sync. Call this for each table to specify whether it should be synchronized(1) or not (0) for the next session. Selective sync only works if you have first performed at least one synchronization for the client. Then, set the flag so that on the next synchronize—that is, before the next invocation of the doSynchronize method—a selective sync occurs.

The default setting is TRUE (1) for all the tables; that is, all tables are flagged to be synchronized. If you want to selectively synchronize specific tables, you must first disable the default setting for all tables and then enable the synchronization for only the specific tables that you want to synchronize.

Note:

Automatic synchronization is based on a different model than manual synchronization. Automatic synchronization operates on a transactional basis. Thus, the selective sync option is not supported when you use automatic synchronization for a publication, since we are no longer concerned with synchronization of only a subset of data.

Syntax

public void setSyncFlag(java.lang.String publication_name, 
          java.lang.String table_name, 
          short sync_flag) throws SyncException

Table 4-5 lists the name and description of parameters for the setSyncFlag function.

Table 4-18 setSyncFlag Parameters

Name Description

publication_name

The name of the publication which is being synchronized. If the value for the publication_name is NULL, it means all publications in the database. This string is the same as the client_name_template parameter of the Consolidator Manager createPublication method. In most cases, you will use NULL for this parameter. For more information, see Section 3.4, "Creating Publications Using Oracle Database Lite APIs".

table_name

This is the name of the snapshot. It is the same as the name of the store, the third parameter of createPublicationItem(). For more information, see Section 3.4, "Creating Publications Using Oracle Database Lite APIs".

sync_flag

If the sync_flag is set to 1, you must synchronize the publication. If the sync_flag is set to 0, then do not synchronize. The value for the sync_flag is not stored persistently. Each time before doSynchronize(), you must call setSyncFlag().


This function allows client applications to select the way specific tables are synchronized.

Set sync_flag for each table or each publication. If sync_flag = 0, the table is not synchronized. To synchronize specific tables only, you must perform the following steps:

  1. Disable the default setting, which is set to 1 (TRUE) for all the tables.

    Example:

    setSyncFlag(<publication_name>,null,0)
    
    

    Where <publication_name> must be replaced by the actual name of your publication, and where the value null is specified to mean all the tables for that publication without exception.

  2. Enable the selective sync for specific tables.

    Example:

    setSyncFlag(<publication_name>,<table_name>,1)
    
    

Alternatively, see the following code snippet on how to enable the selective sync flag for EVERY table EXCEPT the OrdersODB.TEST table.

SyncOption op = new SyncOption(user, passwd, 
                    "noNewPubs","HTTP",server.toString());
op.setSyncFlag("","",(short)1); //turn on sync flag for all the tables
op.setSyncFlag("","OrdersODB.TEST",(short)0); 
                     //turn off sync flag for OrdersODB.TEST

4.2.8 SyncProgress Listener Service

The SyncProgressListener is an interface that allows progress updates to be trapped during synchronization.

This class initiates synchronization by using the provided synchronization options. The parameters for the method are listed in Table 4-19:

Method

void progress
 
   (int progressType, 
    int completed);

Table 4-19 SyncProgressListener Abstract Method

Parameter Description

progressType

This is set to one of the constants listed in Table 4-20.

completed

This is the percentage of completion for specific progressType.


The names of the constants which report the synchronization progress are listed in Table 4-20.

Table 4-20 SyncProgressListener Interface Constants

Constant Name Progress Type

PT_INT

States that the synchronization engine is in the initializing stage. The current and total counts are set to 0.

PT_PREPARE_SEND

States that the synchronization engine is preparing local data to be sent to the server. This includes getting locally modified data. For streaming implementations this takes a shorter amount of time.

PT_SEND

States that the synchronization engine is sending data to the network.

The total count equals the number of bytes to be sent, and the current count equals the byte count being sent currently.

PT_RECV

States that the synchronization engine is receiving data from the server.

The total count equals the number of bytes to be received, and the current count equals the byte count being received currently.

PT_PROCESS_RECV

States that the synchronization engine is applying the newly received data from the server to the local data stores.

PT_COMPLETE

States that the synchronization engine has completed the synchronization process.


Example

This simple class implements the SyncProgressListener.

class myProgressTracker implements SyncProgress Listener;
 {
  public void progress
     (int progressType, 
     int completed)
    {
      System.out.println( "Status: "+progressType+"="+ completed+"%" );
     } //progress
 }

4.3 msync/OCAPIs/mSyncCom

For more information, refer to the Oracle Database Lite API Specification.