|
Oracle9i Lite Developer's Guide for Windows CE/Pocket PC
Release 5.0.2 Part No. B10100-01 |
|
This document discusses replication with the Mobile Server. Topics include:
Section 3.5, "Installing the Sample Application on the Device "
Section 3.7, "Mobile Sync Application Programming Interfaces (APIs)"
Mobile Server allows new and existing applications and data on handheld devices to be synchronized, and shared with an Oracle database. Data on the device can be mapped directly to an Oracle database through a Mobile Server agent. The Mobile Development Kit uses a publish/subscribe model that manages the data subsetting policy for the handheld client devices. Data on the device is mapped to the Oracle database through transport by HTTP or Active Sync.
The most common method of synchronization is a fast refresh, where changes are uploaded by the client, and changes for that client are downloaded. Meanwhile, a background process periodically collects the changes uploaded by all clients and applies them to the database tables, then composes new data, ready to be downloaded to each client during the next synchronization, based on predfined parameters referred to as subscriptions.
The other common method of synchronization is the complete refresh. During a complete refresh, all of the data for a publication is downloaded to the client. For example, during the very first synchronization session, all of the data on the client is refreshed from the Oracle database. This form of synchronization takes longer because all the tables referred to by that publication are transferred to the client device.
Data is synchronized between an Oracle Lite database on an offline client and an Oracle database instance by invoking the Mobile Sync Client module from the client device which interacts with the Mobile Server. The Mobile Server uses synchronization objects such as users, publications, publication items, and subscriptions to handle client operations during a synchronization session. This makes up the publish and subscribe model of synchronization which underlies Oracle Lite.
Publication items contain SQL queries that are defined against Oracle database tables. Publication items are snapshot definitions that can have optional subscription parameters, which determine what data is synchronized.
Publications serve as containers for publication items in the Mobile Server repository, and map to the snapshot created on a client device.
Publication items contain SQL queries that are defined against Oracle database tables. Publication items are snapshot definitions that can have optional subscription parameters, which determine what data is synchronized.
Parameters are used to define user-dependent data subsetting variables. Data subsetting allows refinement of the data requirements for a given user subscribed to a publication.
A publication is subscribed to by one or more users. Users and subscriptions are tracked by the Mobile Server.
Through established subscriptions, the Mobile Server prepares any new data for each client which is then downloaded when the client synchronizes. Only the required subset of data is downloaded to each client. If the publication has been flagged for complete refresh, all the data is downloaded.
Oracle Lite uses an asynchronous method for synchronization between Oracle Lite database clients and an Oracle database server through the Mobile Server. This means that the Mobile Sync module operates independently of the MGP; neither is dependent on the other to complete its operation.
Figure 3-1 Fast Refresh Synchronization
The default method of synchronization is the fast refresh mode which is displayed in Figure 3-1. Fast refresh is an incremental refresh where changes are uploaded and stored in inqueues during the upload phase, then the changes, which have been stored in outqueues, are downloaded and applied to the client. Meanwhile, the MGP periodically looks at the inqueues and takes anything found in an inqueue and applies it to the database during the apply phase. Changes generated by this client, other clients, and server-side applications to the Oracle database are then composed and stored in an outqueue until the next time the client synchronizes.
The upload/download phases are performed independently of any apply/compose phases. An apply phase is not dependent on an upload phase, nor is a download phase dependent on a compose phase. During any synchronization session, download occurs after upload, and compose occurs after apply.
When synchronization is initiated, the client opens a connection to the Mobile Server via the selected mode of transport, which causes the Mobile Server to open a connection to the Oracle database server. The following process is displayed in Figure 3-2.
Figure 3-2 Upload/ Download Phases
Changes to Oracle Lite database records are accumulated and flagged with codes for the type of Data Manipulation Language (DML) operation performed, Insert, Update, or Delete. The the data is encrypted, compressed, and sent to the Mobile Server to populate objects called inqueues. An inqueue is a persistent database object created to store data temporarily during synchronization.
During the same session, snapshots on the client are updated by applying data from the outqueue to the Oracle Lite database. An outqueue differs from an inqueue in that it is not a table but a datastructure containing a reference to the data contained in the Oracle database base tables. See Section 6.4.9, "Queue Interface for Customizing Replication" for information on customizing the way the inqueues and outqueues process data.
The MGP takes any contents of the inqueue and applies it to the base tables on the Oracle database. Any conflicts are detected and resolved at this time. See Section 6.5, "Synchronization Errors and Conflicts" for more information about this topic.
Figure 3-3 Apply/Compose Phases
After the apply phase, the MGP reviews the base tables and composes and stores in the outqueues any changes to be downloaded to the client. The apply/compose phase is displayed in Figure 3-3.
|
Note: The MGP is a background process which periodically becomes active, looks at the inqueues, and applies the changes to the Oracle database base tables. Depending on how the MGP has been configured, there may be a delay in how quickly it composes and readies the outqueues to be downloaded to the client regardless of how frequently you synchronize. The changes are stored safely in the inqueues, until the MGP to processes them, after which they are downloaded to the client on the next synchronization |
During a complete refresh, all contents of the snapshot tables present on the client are refreshed from the Oracle database tables. The MGP is not involved because all the contents are refreshed, but this form of synchronization is more time and system-resource intensive.
It is possible to encrypt an Oracle Lite database using a utility called ENCRYPDB. Synchronizing with an encrypted database is requires an understanding of how Oracle Lite manages encrypted databases. For more information, see Section B.4, "ENCRYPDB".
Mobile Client can be installed from Mobile Server using the Add/Remove feature of Microsoft Active Sync 3.5. Active Sync 3.5 is required for synchronization.
Active Sync allows data to be synchronized between a Windows based desktop system and a Windows CE device or devices. The synchronization process can occur through any form of transport between device and computer and can include addition, deletion, or other revision type operations.
|
Note: Active Sync does not allow peer-to-peer synchronization between devices. |
To distribute necessary files from Mobile Server to their devices, point your browser to the instance of Mobile Server you are using and append /setup to view the setup screen. For example, if your Mobile Server instance is called MyMobileServer, you would enter MyMobileServer/webtogo/setup.
Select the version which corresponds to the Windows CE device connected to your desktop via ActiveSync. Selecting the link causes a .cab file to be downloaded to the desktop and silently registered with Active Sync. You can then run the Active Sync, select the version in the list which they wish to download, and press "OK". Only the language set for the instance of Mobile Server you are using is available for download.
Data Source Names (DSN) are names the ODBC and JDBC interfaces used to identify a database. Applications connect to databases by providing their DSNs.
Mobile Client creates DSN automatically for each publication item that is synchronized to the client. This section describes how these names are generated.
Each publication item is mapped to a specific database on the client device.
Each database has a DSN associated to it. The name of the database and the name of the DSN are the same (except that the database file has the .ODB extension). You can define the name of the DSN and database created on the client when you publish the application. Under the publication panel, you can set the "Client Database Name". This string will be used as the DSN and database name. If you do not specify the name, a unique string will be generated and used as the DSN and database name.
For example, when you publish an application, if you create a publication with the Client Database Name set to "Orders", then on the client device after the first sync you will see the DSN "Orders" and the database file "Orders.odb" created.
Oracle Lite supports the storage of database files in flash memory cards. When a flashcard is inserted, a directory named "Storage Card" shows up on the root directory. You can use this directory as any other directory in the device. All files you move or copy in this directory are stored in the flash card.
You can tell Oracle Lite to store all databases in the flash card by modifying the polite.txt configuration file before your first sync. Note that if you modify the file after your first sync, only new publications will be stored in the new location specified.
To store all your databases in the flash card, before the first sync, follow these steps:
Install Oracle Lite for Windows CE from Active Sync application tools.
Run File Explorer on the device and open up the file /ORACE/polite.txt.
Add or change an entry under the section [All Databases]
DATADIRECTORY=/Storage Card:/Orace:/tmp
In fact, you can set DataDirectory to any valid directory and it will create all databases in that directory. However the directory must be created prior to the first sync.
4. Run mSync.exe to synchronization
First the first sync, you will see all your databases created in the /Storage Card directory and all the DSNs pointing to it in odbc.txt.
The are a few ways to start synchronizing, and it depends on the Sync Mode that you have selected. To change the Sync Mode, go to the ActiveSync Options dialog displayed in Figure 3-4, and click on the Sync Mode tab.
Figure 3-4 Sync Mode Options
If you have selected either "Continuously while the device is connected" or "Once upon connection", then the minute you place the device in the cradle, it will start to synchronize all the enabled providers. If you have "Manually" selected, then it will not synchronize unless you click on the "Sync" button in the ActiveSync main window. This button appears in the upper-left corner of the button-bar and has upward- and downward-pointing arrows on it.
Figure 3-5 Active Sync mSync Icon
There are two ways you can change the sync settings. If mSync is enabled, double- click on the mSync icon in the ActiveSync main window as shown in Figure 3-5. You can also go to the ActiveSync Options dialog, select mSync, then select the "Settings" button. In either case the dialog appears as displayed in Figure 3-6:
Figure 3-6 mSync Provider Settings Screen
The settings in the dialog are listed in Table 3-1:
Table 3-1 mSync Provider Settings Screen Options
| Option | Description |
|---|---|
| Use settings from device |
This is checked by default. If this is selected, then the local settings are disable and the provider attempts to use the synchronization settings from the device. In this case, the device profile must be set up by running mSync.exe from the device and entering the information, then click on "Apply". If this is not done prior to synchronization, an error returns, usually stating that it could not connect to the Mobile Server.
If this checkbox is not selected, the local settings controls are enabled. The local settings are used for the synchronization instead. This is useful for people who have different network settings on their desktop than from the direct modem or wireless connection with the Windows CE device. For example, use proxy when connected to the office network, and don't use proxy when using wireless modem. |
| Mobile Server: Hostname | This is the name of Mobile Server. You can also enter the IP address in the format XXX.XXX.XXX.XXX. No space are allowed. |
| Proxy Server | Select this button to change the proxy settings. |
| Username | Your login used to authenticate with the Mobile Server. |
| Password | Your password. |
If you open the Proxy Settings screen you are able to set the options displayed in Figure 3-7:
Figure 3-7 mSync Proxy Settings Screen
The proxy settings parameters are listed in Table 3-2:
Table 3-2 mSync Proxy Settings Screen Options
| Option | Description |
|---|---|
| Use Proxy Server | Selecting this check-box enables the proxy server for the provider. |
| Hostname | Hostname or IP address of the proxy server. |
| Port | Port number of the proxy server. You can also enter in the service name but it must be available in the system service table. |
| Use Default | Select this to copy the proxy settings from your browser or operating system. |
Replicating with the Windows CE devices using HTTP requires the TCP/IP communication protocol. This section provides instructions for enabling TCP/IP communications for Windows CE devices using Windows NT RAS.
To enable TCP/IP communications between Windows CE device and your Windows NT server using Windows NT RAS, perform the following steps:
In the Windows Control panel, double-click the network icon.
Click the Add button in the Services tab of the Network window.
Select Remote Access Service and then click the OK button.
Insert the Windows NT CD into the disk drive and specify the location where you want the setup program to search for existing Windows NT RAS files.
Click the Continue button. The setup program copies the Windows NT RAS files into the appropriate directories. If the setup program fails to detect a modem, it prompts you to add a modem.
Click the Yes button and enter the required information to install a modem. The Add RAS Device window appears.
Select COM1-Dial-Up Networking Serial Cable from the drop down list and click the OK button. The Remote Access Setup window appears.
Under Port, select COM1 and click the Configure button. The Configure Port Usage window appears.
Select the "Receive calls only" radio button and click the OK button.
Click the Network button in the Remote Access Setup window. The Network Configuration window appears.
Select TCP/IP and click the OK button. The RAS Server TCP/IP Configuration window appears.
Select "Entire network" and "Use static address pool".
You can specify a range of TCP/IP addresses for multiple devices. Enter the beginning of a TCP/IP address range in the Begin field and enter the ending of a TCP/IP address range in the End field. The range should be equal to the number of clients plus 1. For Example, if you have fifty devices you could enter the following range:
Begin: 10.1.0.1
End: 10.1.0.51
|
Important: You must ensure that the TCP/IP addresses in your selected range are not already in use by other computers in your network. |
Click the OK button.
In the Network Configuration window, select "Any authentication including clear text" and click the OK button. Click the Continue button. The Setup Message window appears. Click the OK button.
In the Network window, click the Close button. The Network Settings Change window appears. Click the Yes button.
Once the system reboots, click the Services icon in the Windows Control Panel. The Services window appears.
Select Remote Access Server and click the Startup button.
Select Automatic and click the OK button. Click the Close button.
From the Windows Start menu select Administrative Tools and then select User Manager. The User Manager window appears.
Select New User from the User menu. The New User window dialog appears.
Enter a user name, password, and password confirmation in the required fields.
Select "Password Never Expires".
Click the Dialin button. The Dialin Information dialog appears.
Select "Grant dial-in permission to user". Click the OK button.
Click the OK button to exit the New User dialog.
Exit the User Manager screen.
From the Windows Start menu select Administrative Tools and then select Remote Access Administration. The Remote Access Admin window appears. Installing the Sample Application on the Device.
Verify that the new RAS user is granted remote access permission and click the OK button.
When you configure RAS verify that:
The modem setting is "dial out and receive calls".
You select the option to allow the Windows CE device to connect to any computer in the domain.
The static IP addresses for the Windows CE device are in the same subnet as the desktop connected to the device. Otherwise, you cannot make an HTTP connection and replication fails.
The ending IP address for the Windows CE device is not in use on the network.
The Domain Logon server is available to the Windows CE device.
The IP address is set correctly for the Windows CE device before running Mobile Sync Client application.
When you configure the Windows desktop settings, verify that:
The baud rate is set correctly in the Modems and Ports configuration in the Control Panel. Also, the baud rate for the Windows CE device matches the baud rate on the desktop.
You reinstall your current Windows NT service pack after installing the Windows CE services.
The Mobile Development Kit provides a sample applications which can be found in the <ORACLE_HOME>\Mobile\SDK\wince\samples folder. Within each folder is a readme.txt file which describes how to compile the sample using Microsoft Embedded Visual Tools.
Start the Mobile client application by opening <ORACLE_HOME>\Moble\SDK\wince\ followed by the folder containing the version of Windows CE and the processor your device uses, and start mSync.exe from that folder. For information on how to determine which version of Windows CE and which processor your device uses, see the Oracle9i Lite Installation and Configuration Guide for Windows NT/2000/XP.
Mobile Sync requires the parameters listed in Table 3-3 to synchronize:
Table 3-3 Mobile Sync Client Parameters
| Parameter | Description |
|---|---|
| User Name | Mobile Client user name. This field is not case sensitive. |
| Password | Mobile Client password. This field is case sensitive. |
| Change | Leave this box clear. |
| Save Password | Select this check box to save the password. |
| http://<mobile server> | The Mobile Server IP address. |
| Use Proxy | Select if appropriate. |
Use the following user name and password to make use of the SAMPLE11 sample application. A separate user name and password must be provided for any custom made applications and user snapshots.
User Name = S11U1
Password = MANAGER
Tap the mSYNC icon to start the Mobile Sync Client. The "mSync" screen appears as displayed in Figure 3-8.
Figure 3-8 Mobile Sync Screen
Enter the information in the necessary fields. Remember to select the Save Password check box. The http:// field can contain a screen name or an IP address.
Select the 'Apply' button.
Select the 'Sync' button.
A progress bar appears to indicate the completion of each synchronization task: composing, sending receiving, and processing. The progress bar also displays the time each task took to complete. If synchronization executes successfully, the synchronization Success screen appears. If synchronization fails, a "sync failed" message appears. To determine the cause of a failed synchronization the server administrator can view tracing information in the Mobile Server log file.
There are three methods that a developer can use to create native applications which invoke synchronization using the underlying libraries, ocapi.dll. These APIs are provided for application development where a different approach is required than that provided by the Mobile Sync client, msync.exe.
|
Note: There are currently no client-side synchronization programming interfaces for Sun SPARC Solaris. Programming with these interfaces is assumed to use the Windows operating system. |
Using the Java interface to Mobile Sync client-side synchronization, 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 of 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, mSync.jar and msync_java.dll. In order to use the Java interface, msync.jar must be included in the classpath. The mSync.jar file is located in <ORACLE_HOME>\Mobile\classes directory. The msync_java.dll file is located in the <ORACLE_HOME>\Mobile\bin directory.
There are four parts to the Java interface:
This class initiates synchronization by using the provided synchronization options. The parameters for the constructor are listed in Table 3-4:
Sync(SyncOption option)
Table 3-4 Sync Class Constructor
| Parameter | Description |
|---|---|
option
|
Instance of the SyncOption class. This contains all the parameters needed to perform synchronization. See Section 3.7.1.3, "SyncOption Class" for more information.
|
The public method SyncProgressListener adds a progress listener to the object to monitor the progress of the synchronization.
SyncProgressListener add(ProgressListener listener)
The parameters for the SyncProgressListener public method are listed in Table 3-5:
Table 3-5 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 inform it of the synchronization progress.
|
void doSync()
|
Begins a synchronization session and blocks that thread until the 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());
}
This class signals a non-recoverable error during the synchronization process. SyncException() constructs a "clear" object. The parameters for the constructor are listed in Table 3-6:
SyncException()SyncException( interrorCode, String errorMessage)
Table 3-6 SyncException Constructor Parameters
| Parameters | Description |
|---|---|
errorCode
|
The error. Refer to the Oracle9i Lite Error Message Reference for a list of available codes. |
errorMessage
|
A readable text message that provides extra information. |
The methods for the SyncException are listed in Table 3-7:
Table 3-7 SyncException Class Public Method
| Parameters | Description |
|---|---|
int getErrorCode()
|
Gets the error code. |
String getErrorMessage()
|
Gets the error message. |
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.
SyncOption()
SyncOption
( String user,
String password,
String syncParam,
String transportDriver,
String transportParam)
The parameters for the SyncOption constructor are listed in Table 3-5:
Table 3-8 SyncOption Constructors
| Parameter | Description |
|---|---|
user
|
A string containing the name used for authentication by the Mobile Server. |
password
|
A string containing the user's password. |
syncParam
|
A string which defines an optional list of parameters for the synchronization session. See Section 3.7.1.4, "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 3.7.1.5, "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. |
These methods load and save the user profile. The parameters of the public methods are listed in Table 3-6:
Table 3-9 Sync Option Public Method Parameters
| Parameter | Description |
|---|---|
void load(String username)
|
This loads the profile for the username specified. If the username 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. |
void setPassword(String password)String getPassword()
|
This used to set and get the password. |
void setSyncParam(String syncParam)String getSyncParam()
|
This used to set and get the synchronization parameters. |
void setTransportDriver(String driverName)String getTransportDriver()
|
This 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. |
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();
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 3-10.
Table 3-10 Java Interface SyncParam Settings
| Name | Value/Options | Description |
|---|---|---|
"reset"
|
N/A | Clear all entries in the environment before applying any remaining settings. |
"security"
|
"SSL"
|
Use the appropriate selection to choose either SSL or CAST5 stream encryption. |
"pushonly"
|
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".
"RecieveOnly" 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 . |
"fullrefresh"
|
N/A | Forces a complete refresh. |
"clientDBMode"
|
"EMBEDDED"
" |
If set to "EMBEDDED", access to the database is by conventional ODBC, if set to "CLIENT" access is by multi-client ODBC.
|
The first example enables SSL security and disables application deployment for the current synchronization session:
"security=SSL; noapps;"
The second example resets all previous settings, activates upload for the "Dept" table only:
"reset;pushOnly;tableFlag[TestApp.Emp]=disable;tableFlag[TestApp.Dept]=enable;"
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 3-11.
Table 3-11 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. |
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;"
The SynchProgressListener 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 3-12:
void progress
(int progressType,
int completed);
Table 3-12 SyncProgressListener Abstract Method
| Parameter | Description |
|---|---|
progressType
|
This is set to one of the constants listed in Table 3-13. |
completed
|
This is the percentage of completion for specific progressType.
|
The names of the constants which report the synchronization progress are listed in Table 3-13.
Table 3-13 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. |
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
}
The COM Interface is used to program applications that can start the synchronization process and enable a variety of settings. This interface is modular and extensible and makes use of the ocapi.dll through a wrapper style interface. The interface is designed to allow applications to be written in Visual Basic, but other programming methods supported by the COM interface including VBScript and others.
The COM Interface supports the following features:
Starting the synchronization process
Tracking the progress of the synchronization process.
Setup of client side user profiles containing data such as user name, password, and server.
Assigning table level synchronization options.
Allow a choice of transport.
COM Interface API and samples are now installed in the <ORACLE_HOME>\Mobile\SDK\mSync\COM subdirectory. The following classes are contained in the mSync.dll library:
The interface is contained in the MSync library. When using the ISync interface, you should use MSync.ISync as the interface name.
The ISync interface, Msync.ISync allows the user to instantiate the synchronization process. Table 3-14 lists the format for the ISync interface.
Table 3-14 ISync Interface Parameters
| Name | Description |
|---|---|
HRESULT doSync()
|
Start the synchronization process. This blocks access until the synchronization process is completed. |
void abort()
|
Aborts the current synchronization. This can be called from a progress listener callback. |
HRESULT setOption(ISyncOption*syncObj)
|
Sets the pointer to the SyncOption to use for the next synchronization. If this function is not called before doSync(), the last saved options will be used.
|
The following Visual Basic code demonstrates how to start a synchronization session using the default settings:
Dim sync As Msync.syn
Set sync = CreateObject("MSync.Sync")
sync.DoSync
In case no SyncOption is used, the interface loads the last saved information to perform the sync.
The ISyncOption class MSync.SyncOption defines the parameters of the synchronization process. It can be constructed manually, or use data loaded or saved from the user profile. The public methods for the ISyncOption class are listed in Table 3-15.
Table 3-15 ISyncOption Public Methods
| Name | Description |
|---|---|
void load()
|
Load the profile of the last user sync. |
void save()
|
Save settings to the user profile. |
The public properties for the ISyncOption class are listed in Table 3-16.
Table 3-16 ISyncOption Public Properties
| Name | Description |
|---|---|
username
|
Name of the user. |
password
|
User password. |
syncParam
|
Synchronization preferences. See Section 3.7.2.4, "COM Interface SyncParam Settings" for more information. |
transportType
|
Type of transport to use. Only "HTTP" type is supported currently. |
transportParam
|
Parameters of the transport. See Section 3.7.1.5, "Java Interface TransportParam Parameters" for more information. |
The following Visual Basic code demonstrates how to start a synchronization session using the default settings:
Set syncOpt = CreateObject("MSync.SyncOption")
' Load last sync info
syncOpt.Load
' Change user name to Sam
syncOpt.usename = "Sam"
Set sync = CreateObject("MSync.Sync")
' Tell ISync to use this option
sync.setOptionObject (syncOpt)
' Do sync
sync.DoSync
The syncParam is a string that 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 3-17.
Table 3-17 COM Interface SyncParam Settings
| Name | Value/Options | Description |
|---|---|---|
"reset"
|
N/A | Clear all entries in the environment before applying any remaining settings. |
"security"
|
"SSL"
|
Use the appropriate selection to choose either SSL or CAST5 stream encryption. |
"pushonly"
|
N/A | Use this setting to upload changes from the client to the server only, download is not allowed.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 a slow connection or on a slow network. |
"syncDirection"
|
"SendOnly'
"ReceiveOnly" |
"SendOnly" is the same as "pushonly".
"RecieveOnly" 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.
|
"fullrefresh"
|
N/A | Forces a complete refresh. |
"clientDBMode"
|
"EMBEDDED"
" |
If set to "EMBEDDED", access to the database is by conventional ODBC, if set to "CLIENT" access is by multi-client ODBC.
|
The first example enables SSL security and disables application deployment for the current synchronization session:
"security=SSL; noapps;"
The second example resets all previous settings, activates upload for the "Dept" table only:
"reset;pushOnly;tableFlag[TestApp.Emp]=disable;tableFlag[TestApp.Dept]=enable;"
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 3-18.
Table 3-18 COM Interface 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. |
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;"
ISync implements a connection point container to allow synchronization progress information to be tracked. ISyncProgressListener must be implemented to return updates from the ISync interface. The abstract method for the ISyncProgressListener is listed in Table 3-19
Table 3-19 ISyncProgressListener Abstract Method
| Name | Description |
|---|---|
HRESULT progress([in] int progressType, int param1, int param2
|
Called by the synchronization engine when new progress information is available. The progressType is set to one of the progress type constants defined in the ISyncProgressListener Constants table. For more information, see Section 3.7.1.6. Current is the current count completed, and total is the maximum. When current equals to total, then the stage is completed. The unit for total and current differs depending on the progressType
|
The ISynchProgressListener is an interface that allows progress updates to be trapped during synchronization. The names of the constants which report the synchronization progress are listed in Table 3-20.
Table 3-20 ISyncProgressListener Constants
| Name | Progress Type |
|---|---|
| PT_INIT | Reports that synchronization engine is in the initializing stage. The current and total counts are both set to 0. |
| PT_PREPARE_SEND | Reports that synchronization engine is preparing local data to be sent to the server. This includes getting locally modified data. For streaming implementations, this will be much shorter. |
| PT_SEND | Reports that synchronization engine is sending the data to the network.The total count denotes the number of bytes to be sent, and current is the currently sent byte count. |
| PT_RECEIVE | Reports that the engine is receiving data from the serverThe total count denotes the number of bytes to be received, and current is the currently received byte count. |
| PT_PROCESS_RECV | Reports that the engine is applying the newly received data from the server to the local data stores |
| PT_COMPLETE | Reports that the engine has completed the sync process. |
The following Visual Basic code example demonstrates how to report events:
' Define the ISync object with eventsDim WithEvents sync As MSync.sync' Create the callback.' The name of the call back is the name of the ISync object (not the class), and ' underscore and then the function name - progressPrivate Sub sync_progress(ByVal progressType As Long, ByVal param1 As Long, ByVal param2 As Long) Desc = "" ' Decipher the progressType Select Case progressType Case PT_SEND Desc = "Sending data..." Case PT_RECV Desc = "Receiving..." End SelectEnd Sub
The C/C++ Interface consists of five function calls and a control structure, the definitions for which can be found in ocapi.h and ocapi.dll which are located in the <ORACLE_HOME>\Mobile\bin directory. This API allows an application to initiate and monitor synchronization with a database from a client rather than requiring that it be started from the Mobile Server. The default transport mechanism is HTTP, but other forms of transport can be specified if they are available.
This function is used to initialize the synchronization environment.
int ocSessionInit( ocEnv *env );
The parameter for ocSessionInit function is listed in Table 3-21:
Table 3-21 ocSessionInit Parameters
| Name | Description |
|---|---|
env
|
Pointer to an ocEnv structure buffer to hold the return synchronization environment. |
This call initializes the ocEnv structure and restores any user settings that are saved in the last ocSaveUserInfo() call. A pointer to an ocEnv structure is passed as a parameter, and should be allocated by the caller. If the caller wants to overwrite the user preference information after the ocSessionInit() call, that can be done by calling ocSaveUserInfo(). The caller must allocate memory for the ocEnv structure.
Frees and performs a cleanup of the synchronization environment.
int ocSessionTerm( ocEnv *env );
The parameter for ocSessionTerm function is listed in Table 3-22:
Table 3-22 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. They should always be called in pairs.
Saves user settings to the conscli.odb database file.
int ocSaveUserInfo( ocEnv *env );
The parameter for ocSaveUserInfo function is listed in Table 3-23:
Table 3-23 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
SyncNewPublication
For usage of these fields, please refer to the Section 3.7.3.6, "C/C++ Data Structures".
Starts the synchronization process.
int ocDoSynchronize( ocEnv *env );
The parameter for ocDoSynchronize function is listed in Table 3-24:
Table 3-24 ocDoSynchronize Parameters
| Name | Description |
|---|---|
env
|
Pointer to the synchronization environment. |
This starts the synchronization cycle. A round trip synchronization is activated if syncDirection is 0 (default). If syncDirection is 1, only the upload, or send operation, is performed. If syncDirection is 2, only the download, or receive operation is performed. Performing an upload-only synchronization is useful if client does not want to download data from the server.
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. When this option is used, it must occur before ocDoSync.
ocSetTableSyncFlag(ocEnv *env, const char* publication_name, const char* table_name, short sync_flag)
The parameters for the ocSetTableSyncFlag function are listed in Table 3-25:
Table 3-25 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 publication_name is NULL, sync_flag applies to all items in the publication.
|
table_name
|
This string is same as client_name_template parameter of the Consolidator CreatePublication. This string is the database_name + '.' + store, where store is the third parameter of CreatePublicationItem(). For more information see Section 5.2.4, "Creating Publications" and Section 5.2.5, "Creating Publication Items" or the Consolidator Admin API Specification.
|
sync_flag
|
If sync_flag is set to "1" then do synchronize. If sync_flag is set to "0" then do not synchronize. The value for sync_flag is not stored persistently. Each time before ocDoSynchronize() you need to call ocSetTableSyncFlag().
|
This function allows the 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.
Two data structures are part of the Mobile Sync API, ocEnv and ocTransportEnv.
The ocEnv is the data structure used by all the Mobile Sync module functions to hold internal memory buffers and state information. Before using the structure, the application must pass it to ocSessionInit to initialized the environment. The parameters for the structure appear in Table 3-26:
Table 3-26 ocEnv Structure Field Parameters
| Field | Type | Usage | Description |
|---|---|---|---|
| Username |
char[MAX_USERNAME]
|
Caller MUST set these fields before calling ocSessionInit.
|
Name of the user to authenticate. |
| Password |
char[MAX_USERNAME]
|
Caller MUST set these fields before calling ocSessionInit.
|
User password (clear text). |
| NewPassword |
char[MAX_USERNAME]
|
Caller can set these fields optionally after calling ocSessionInit.
|
If first character of this string is not null, in otherwords (char) 0, then this string will be sent to the server to request it to change the user's password effective on the next sync session. |
| SavePassword | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 1, then the password in the password field will be saved locally and will be loaded next time ocSessionInit is called. |
| AppRoot |
char[MAX_USERNAME]
|
Caller can set these fields optionally after calling ocSessionInit.
|
Directory where application will be copied to. If first character is null, then it will use the default directory. |
| Priority | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
Reserved. |
| Secure | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 0, no security on transport. If set to OC_DATA_ENCRYPTION, use CAST5 synchronization.If set to OC_SSL_ENCRYPTION, use SSL synchronization (Win32 only)
|
| SyncDirection | Enum |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 0 (OC_SENDRECEIVE) then sync is bi-directional (default).If set to OC_SENDONLY, then only push changes to server. This is stop the sync after the local changes are collected and sent. Useful for sync that requires the engine to separate the different stages (like floppy based).If set to OC_RECEIVEONLY, then send no changes and only receive update from server. This only only perform the receive and allow changes to local database stages.
|
| TrType | Enum |
Must be set before calling ocSessionInit.
|
If set to 0 (OC_BUILDIN_HTTP), then use HTTP built-in transport driver.If set to OC_USER_METHOD, then use user provided transport functions.
|
| ExError | ocError | Read only information updated by OCAPI. | Extended error code - either OS or OKAPI error code. |
| transportEnv | ocTransportEnv | Transport buffer. See Section 3.7.3.6.2. | |
| ProgressProc | FnProgress |
Caller can set these fields optionally after calling ocSessionInit.
|
If not null, points to the callback for progress listening. |
| TotalSendDataLen | Long | Read only information updated by OCAPI. |
Set by OCAPI informing transport the total number of bytes sent; set before first fnSend() is called
|
| TotalRecieveDataLen | Long | Read only information updated by OCAPI. |
Set by OCAPI informating transport total number of bytes to receive. should be set at first fnReceive() call.
|
| UserContext | Void* |
Caller can set these fields optionally after calling ocSessionInit.
|
Can be set to anything by the caller for context information (such as progress dialog handle, renderer object pointer, etc). |
| OcContext | Void* | Reserved. | |
| Logged | Short | Reserved. | |
| BufferSize | Long | Reserved (for Wirelss/Nettech only). | |
| PushOnly | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 1, then only push changes to server |
| SyncApps | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
Set to 1 (by default), performs application deployment. If set to 0, then no applications will be received from server |
| SyncNewPublications | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 1 (default), then 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 |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to OC_DBMODE_EMBEDDED (default), it will use local Oracle Lite ODBC driver.If set to OC_DBMODE_CLIENT, it will use the Branch Office driver.
|
| SyncTimeLog | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
If set to 1, log sync stat time to conscli.odb |
| UpdateLog | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
Debug only.If set to 1, logs serverside insert and update row info to publication odb |
| Options | Short |
Caller can set these fields optionally after calling ocSessionInit.
|
Debug only. A bitset of the following flags:
|
The environment structure also contains fields that the caller can update to change the way Mobile Sync module functions work.
typedef struct ocEnv_s {
// User infos
char username[MAX_USERNAME]; // Mobile Sync Client id
char password[MAX_USERNAME]; // Mobile Sync Client password for
// authentication during sync
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
// For Palm 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
} ocEnv;
This structure is used to override the built-in transport functions. By providing the list of functions in the structure, applications can define their own implementation for the transport layer used by the synchronization engine.
typedef struct ocTransportEnv_s {
void* ocTrInfo; // transport internal context
// for built-in Http, mapped to ocTrHttp
connectProc fnConnect; // plug-in callback to establish a connection from
// device to server
disconnectProc fnDisconnect; // plug-in callback to dismantle connection
// from device to server
sendProc fnSend; // plug-in callback to send data receiveProc fnReceive; // plug-in callback to receive data }ocTransportEnv;
This feature allows the mobile application to select the way specific tables are synchronized. The mobile application uses the C/C++ interface API ocSetTableSyncFlag function to determine which publication and publication items need to be synchronized. The application calls this function and sets the sync_flag parameter to either "1" (synchronize) or" 0" (no synchronization) for each table. The list of tables therefore can be changed dynamically during runtime allowing the application developer to programmatically control selective synchronization.
|
![]() Copyright © 2002 Oracle Corporation All rights reserved |
|