| Oracle9i Lite Developer's Guide for Windows CE Release 5.0 Part Number A90252-01 |
|
This document discusses replication with the Mobile Server. Topics include:
Mobile Server allows new and existing applications and data on handheld devices to be replicated, synchronized, and shared with an Oracle server. Data on the device can be mapped directly to an Oracle8 data server through a Mobile Server agent on the Oracle8 database. The Mobile Server uses a publish/subscribe model that manages the data subsetting policy for the mobile devices. Data on the device is mapped to Oracle8i through transport by HTTP.
The Message Generator and Processor (MGP) is a Java background process that uploads transactions from the applications running on the client devices. The MGP then applies the transactions to Oracle databases. It also generates new updates (data) for the client devices to download. Please refer to the Oracle9i Lite Publishing, Managing, and Deploying Guide for more information concerning administration of the MGP.
The Mobile Server uses publications and subscriptions. Publications are (optionally parameterized) queries that are defined against Oracle8i tables or views. A publication is subscribed to by one or more users. The Mobile Server tracks users for devices. Through established subscriptions, the Mobile Server prepares any new data for each client device. Data can be partitioned either horizontally by rows, or vertically by columns. Only the required subset of data is downloaded to each client.
In the Mobile Server publish and subscribe model, each publication can contain multiple publication items. A publication item typically maps to a table on the device. You can rename table columns within publication items. Each publication item can contain multiple parameters. See Section 2.3, "The Publish and Subscribe Model" for more information.
The first time a client device replicates, the Mobile Server automatically creates the database objects on the client device. By default, the primary key index of a table is automatically replicated from the server. You can create secondary indexes on the device through a publication item. If you do not want the primary index, you must explicitly drop it from the publication items. See the Consolidator Admin API Specification, for specific API information.
On the server side, the Mobile Server works against Oracle8. On the client side, the Mobile Sync supports replication with the Oracle Lite database on any platform supported by Oracle Lite.
The Mobile Server synchronization process can be customized in many ways. You can attach application logic to the Mobile Server by binding PL/SQL packages to publication items. The packages must expose the BeforeCompose, AfterCompose, BeforeApply, and AfterApply methods. The Mobile Server calls these methods before and after it:
The Mobile Server passes the current Mobile Sync Client user to these methods.
User-defined PL/SQL packages can cache or pre-compute data. They can also resolve foreign key constraint violation problems. See Section 2.1.7, "Foreign Key Constraints in Updatable Publication Items" for more information. See Section 2.4.1, "Callback Customization Using Compose and Apply" for details on using these calls.
Special characters including spaces are supported in client, table, view, and column names. Callers must provide object names to the Mobile Server exactly as they are stored in the database (in most cases, using uppercase letters).
The Mobile Server supports fast refresh and update operations for complex multiple table publications that meet specific criteria.
For a view to be updatable, it must have a parent table. A parent table contains any of the view's base tables in which a primary key is included in the view's column list and is unique in the view's row set. If you want to make a view updatable, you must provide the Mobile Server with the appropriate hint and the view's parent table before you create a publication item on the view.
To make view-based publication items updatable, you must use the following two mechanisms:
Parent table hints define the parent table for a given view. Parent table hints are provided through the ParentHint function in the Consolidator Admin API. See "Parent Hint" in the Consolidator Admin API Specification, for more information.
INSTEAD OF triggers are used to execute INSTEAD OF INSERT, INSTEAD OF UPDATE, or INSTEAD OF DELETE commands. INSTEAD OF triggers also map these DML commands into operations that are performed against the view's base tables. INSTEAD OF triggers are a function of Oracle8. See the Oracle8i documentation for details on INSTEAD OF triggers.
Publication items are created for fast refresh by default. Under fast refresh, only incremental changes are replicated. The advantages of fast refresh are reduced overhead and increased speed when replicating data stores with large amounts of data where there are limited changes between synchronization sessions.
The Mobile Server performs a fast refresh of a view if the view meets the following criteria:
The view requires only a unique primary key for the parent table. The primary keys of other tables may be duplicated. For each base table primary key column, you must provide the Mobile Server with a hint about how this column is called in the view. You can accomplish this by using PrimaryKeyHint in the Consolidator Admin API. See the Consolidator Admin API Specification for more information.
Publication items can be created for complete refresh using the CompleteRefresh call from the Consolidator Admin API. When this mode is specified, client data is completely refreshed with current data from the server after every sync. An administrator can force a complete refresh on an entire publication on an entire publication via an API call. The complete refresh function forces complete refresh of a publication for a given client. See the Consolidator Admin API Specification for more information.
Replicating tables between Oracle8 and client devices in updatable mode can result in foreign key constraint violations if the tables have referential integrity constraints. When a foreign key constraint violation occurs, the server rejects the client transaction.
For example, two tables EMP and DEPT have referential integrity constraints. The DeptNum (department number) attribute in the DEPT table is a foreign key in the EMP table. The DeptNum value for each employee in the EMP table must be a valid DeptNum value in the DEPT table.
A Mobile Server user adds a new department to the DEPT table, and then adds a new employee to this department in the EMP table. The transaction first updates DEPT and then updates the EMP table. However, the database application does not store the sequence in which these operations were executed.
When the user replicates with the Mobile Server, the EMP table is updated first. In doing so, it attempts to create a new record in EMP with an invalid foreign key value for DeptNum. Oracle8 detects a referential integrity violation. The Mobile Server rolls back the transaction and places the transaction data in the Mobile Server error queue. In this case, the foreign key constraint violation occurred because the operations within the transaction are performed out of their original sequence.
PL/SQL allows you to avoid foreign key constraint violations based on out-of-sequence operations by using DEFERRABLE constraints in conjunction with the BeforeApply and AfterApply functions. DEFERRABLE constraints can be either INITIALLY IMMEDIATE or INITIALLY DEFERRED. The behavior of DEFERRABLE INITIALLY IMMEDIATE foreign key constraints is identical to regular immediate constraints. They can be applied interchangeably to applications without impacting functionality.
The Mobile Server calls the BeforeApply function before it applies client transactions to the server and calls the AfterApply function after it applies the transactions. Using BeforeApply function, you can set constraints to DEFFERED to delay referential integrity checks. After the transaction is applied, call the AfterApply function to set constraints to IMMEDIATE. At this point, if a client transaction violates referential integrity, it is rolled back and moved into error queues.
To prevent foreign key constraint violations using DEFERRABLE constraints:
AfterApply function as follows:
procedure BeforeApply(clientname varchar2) is cur integer; begin cur := dbms_sql.open_cursor; dbms_sql.parse(cur,'SET CONSTRAINT SAMPLE3.address14_fk DEFERRED', dbms_sql.native); dbms_sql.close_cursor(cur); end; procedure AfterApply(clientname varchar2) is cur integer; begin cur := dbms_sql.open_cursor; dbms_sql.parse(cur, 'SET CONSTRAINT SAMPLE3.address14_fk IMMEDIATE', dbms_sql.native); dbms_sql.close_cursor(cur); end;
Table weight is an integer property of association between publications and publication items. Mobile Server uses table weight to determine which order to apply Client Operations to master tables as follows:
In the example listed in Section 2.1.7.1, "Foreign Key Constraint Violation Example", a constraint violation error could be resolved by assigning DEPT a lower table weight than EMP. For example:
(DEPT weight=1, EMP weight=2)
With the Mobile Server, a compatibility with Oracle8 advanced replication error occurs when the client updates a row at the same time that the server deletes it. All other errors, such as nullity violations or foreign key constraint violations, are replication errors.
The Mobile Server does not automatically resolve replication errors. Instead, the Mobile Server rolls back corresponding transactions, and moves transaction operations into the Mobile Server error queue. Later, Mobile Server database administrators can change these transaction operations and re-execute or purge the transactions from the error queue.
A Mobile Server replication conflict occurs if:
See Section 2.4.5, "Resolving Conflicts Using the Error Queue" for more information on conflict resolution techniques.
The Mobile Server uses internal versioning to detect replication conflicts. A version number is maintained for each client record as well as for each server record. When a client's changes are applied to the server, the Mobile Server will detect version mismatches and resolve conflicts according to winning rules.
The Mobile Server uses winning rules to automatically resolve replication conflicts. The following winning rules are supported:
When the client wins, the Mobile Server automatically applies client changes to the server. When the server wins, the Mobile Server automatically composes changes for the client.
You can customize the Mobile Server's conflict resolution mechanism by setting the winning rule to "Client Wins" and attaching BEFORE INSERT, UPDATE, and DELETE triggers to database tables. The triggers compare old and new row values and resolve client changes as specified.
The Oracle8 and Oracle9i Lite tables that the Mobile Server synchronizes must use compatible datatypes. Oracle8 datatypes are compatible with Oracle9i Lite datatypes.
All Oracle9i Lite-based snapshots are created by the Mobile Sync during replication. The Mobile Server automatically selects Oracle9i Lite datatypes depending on data precision in Oracle8. The following table shows the data conversion. Oracle datatypes appear in the left column and Oracle9i Lite datatypes appear in the top row. "X" indicates unconditionally supported and "-" indicates not supported. Datatypes 1B, 2B, and 4B are specifically OKAPI datatypes. See the Oracle9i Lite Object Kernal API Reference for more information.
Table 2-1 Oracle Lite Datatypes
The Mobile Server uses a publish and subscribe model to centrally manage data distribution between Oracle servers and handheld devices. The publish and subscribe model can be implemented programmatically to invoke certain specialized features using the Mobile Server Admin API and the Consolidator Admin API both of which are part of the Mobile Server. This model includes the following:
Table 2-2 Publish/Subscribe Model Elements
To implement the Mobile Server publish/subscribe model, perform the following:
You can implement the Mobile Server publish/subscribe model by using one of the following:
Table 2-3 Methods to Implement Publish and Subscribe Model
| Implementation Method | Definition |
|---|---|
|
Packaging Wizard |
The preferred method. See Chapter 4, "Using the Packaging Wizard" for more information. |
|
Pure Java methods |
The Consolidator Admin and Mobile Server Admin API are executed from a Java program using pure Java methods. |
|
Note: The Consolidator Admin API is case sensitive. The Mobile Server Admin API is not case sensitive. |
This section describes how to connect to the Mobile Server using Java methods.
ResourceManager.openConnection("MOBILEADMIN", "MANAGER");
This section describes how to create a user, change a password, and drop a user using the Mobile Server Admin API.
You can create Mobile Server users with the CreateUser() function which has the following syntax:
public static boolean createUser(String userName, String password, String fullName, String privilege);
The following example creates a user "MOBILE" with the parameters listed in the table:
Table 2-4 Create User Example Parameters
ResourceManager.createUser("MOBILE","MOBILE","MOBILEUSER","C");
You can change passwords for Mobile Server users with the SetPassword() function which as the following syntax:
public static void setPassword(String userName, String newpwd);
The following example changes the password for the user "MOBILE":
Table 2-5 Set Password Example Parameters
| Parameter | Value | Definition |
|---|---|---|
|
|
|
Specifies user name for mobile client. |
|
|
|
Specifies the new password for the mobile client. |
ResourceManager.setPassword("MOBILE","MOBILENEW");
You can drop existing Mobile Server users with the dropUser() function using the following syntax:
public static void dropUser(String userName);
The following example drops the user "MOBILE":
Table 2-6 Drop User Example Parameters
| Parameter | Value | Definition |
|---|---|---|
|
userName |
"MOBILE" |
Specifies user name for mobile client. |
ResourceManager.dropUser("MOBILE");
This section describes how to create a publication.
Publication item names are limited to twenty-six characters and must be unique across all publications. Publication items can be defined for both tables and views. When publishing an object, the user is required to specify the publication item in which the object resides. When publishing Updatable multi-table views, there are certain restrictions that apply:
When creating publication items, the user can define a parameterized select statement with a character limit of up to an 8k. Subscription parameters can be specified at this time, and will be used during replication to limit the data published to each client. String substitution is used to replace the values of the parameters when a user subscribes.
You can create publications using the CreatePublication function, which has the following syntax:
public static void CreatePublication(String name, int client_storage_type, String client_name_template, String enforce_ri) throws ThrowableConsolidator
The following example creates a publication named "T_SAMPE1" with the parameters listed in the table:
Table 2-7 Create Publication Sample Parameters
Consolidator.CreatePublication("T_SAMPLE1", Consolidator.OKPI_WINCE, "%s", null);
|
Note: If you use Oracle Lite database as the client storage type, the database does not have an extension. |
This section describes how to create publication items.
You can create publication items using the CreatepublicationItem function, which has the following syntax:
public static void CreatePublicationItem(String name, String owner,String store, String refresh_mode, String select_stmt, String cbk_owner, String cbk_name) throws Throwable
The following examples create a publication item named P_SAMPLE1 with the parameters listed in the table:
Table 2-8 Create Publication Item Sample Parameters
| Parameter | Value | Definition |
|---|---|---|
|
|
SAMPLE1 |
Specifies that SAMPLE1 is the base object owner. |
|
|
ADDROLRL4P |
Specifies that ADDROLRL4P is the base object name. |
|
|
F or C |
Defines the refresh mode as fast or complete. See Section 2.1.6, "Fast Refresh and Update Operation for Views" for more information. |
|
|
See the examples. |
Selects data from the specified columns in |
|
|
null |
Specifies the callback package owner as NULL. For more information, see Section 2.4.1, "Callback Customization Using Compose and Apply". |
|
|
null |
Specifies the callback package name as NULL. For more information, see Section 2.4.1, "Callback Customization Using Compose and Apply". |
Consolidator.CreatePublicationItem("P_SAMPLE1", "SAMPLE1", "ADDROLRL4P", "F" , "SELECT "LastName","FirstName", company, phone1, phone2, phone3, phone4, phone5, phone1id, phone2id, phone3id, phone4id, phone5id, displayphone, address, city, state, zipcode, country, title, custom1, custom2, custom3, custom4, note FROM sample1.addrolrl4p" + " WHERE upper(company) > " + ":COMP", null, null);
Mobile Server makes a callout during synchronization indicating whether the client device is attempting a null sync. A null sync refers to the fact that the client has no changes to upload. This callout can be implemented by creating a PL/SQL package within the Mobile Server repository. The package must have the following specification:
create or replace package CUSTOMIZE as procedureNullSync(p_Client IN varchar2, p_NullSync as boolean); end CUSTOMIZE;
This section describes how to retrieve publication item names.
public static String getPublicationItemName(String Publication Item, int platform);
The constant int platform identifies the platform for which the snapshot was created. The constant argument is "ResourceManager." followed by "WTG", "PALM", "EPOC", or "WINCE" depending on the platform See the Mobile Server Admin Specification for more information.
The following example returns a publication item called "DEPT" for an EPOC application.
Table 2-9 Get Publication Item Name Example Parameters
| Parameter | Value | Definition |
|---|---|---|
|
|
DEPT |
String name identifying a snapshot or table. |
|
|
ResourceManager.WTG |
Constant representing the platform type for which the snapshot was created. |
ResourceManager.getPublicationItemName("DEPT",ResourceManager.EPOC);
The Mobile Server supports automatic deployment of indexes in Oracle Lite databases on client devices. The Mobile Server automatically replicates primary key indexes from the server database. The Consolidator Admin API provides calls to explicitly deploy unique, regular, and primary key indexes to client devices as well.
You can deploy a publication item index with the CreatePublicationItemIndex function, which has the following syntax:
public static void CreatePublicationItemIndex(String name, String publication_item, String pmode, String columns) throws Throwable
The examples in this section create a publication item index named INDEX001 for the publication item PSAMPLE1. The publication item index is a regular index which includes the ZIPCODE column as defined in the table:
Table 2-10 Create Publication Item Index Sample Parameters
Consolidator.CreatePublicationItemIndex("INDX001", "P_SAMPLE1", "I", "ZIPCODE");
Client-side indexes can be defined for existing publication items. There are three types of indexes that can be specified:
Note: When an index of type 'U' or 'P' is defined on a publication item, there is no check for duplicate keys on the server. If the same constraints do not exist on the base object of the publication item, Mobile Sync may fail with a duplicate key violation. See the Consolidator Admin API Specification for more information.
Once you create a publication item, you must associate it with a publication. To change the definition, you can either remove the publication item and then recreate it with the new definition or use schema evolution depending on your requirements. See "Drop Publication Item" and "Alter Publication Item" respectively in the Consolidator Admin API Specification for more information.
You can add publication items to the publication using the AddPublicationItem function, which has the following syntax:
public static void AddPublicationItem(String publication, String item,String columns, String disabled_dml, String conflict_rule, String restricting-predicate, String weight) throws Throwable
The following examples add a publication item named P_SAMPLE1 to the publication T_SAMPLE1. The added publication item has the following parameters:
Table 2-11 Add Publication Item Sample Parameter
| Parameter | Value | Definition |
|---|---|---|
|
|
T_SAMPLE |
Defines T_SAMPLE as the publication to receive the new item. |
|
|
P_SAMPLE |
Defines P_SAMPLE as the publication item to be added. |
|
|
null |
Specifies that no columns are renamed. |
|
|
null |
Specifies that no options are selected for disabling DML. See the Consolidator Admin API Specification for other values. |
|
|
S |
Defines the server as the winner in conflict resolution. See Section 2.3.7.2, "Defining Conflict Rules" for other values. |
|
|
null |
Specifies that high-priority mode. A restricting predicate can be assigned to a publication item as it is added to a publication. When a client is synchronizing in high priority mode, the predicate is used to limit data pushed to the device. This parameter can be null. This parameter is for advanced use. |
|
weight |
null |
Specified as null or an integer to determine priority in executing Client Operations to master tables. See Section 2.3.7.3, "Using Table Weight" for more information. |
Consolidator.AddPublicationItem("T_SAMPLE1", "P_SAMPLE1", null, null, "S");
Publication items can be defined as read-only by disabling the DML. See the Consolidator Admin API Specification for more information.
When adding a publication item to a publication, the user can specify winning rules to resolve replication conflicts in favor of either the client 'C' or the server 'S'. A Mobile Server replication conflict is detected under any of the following situations:
See the Consolidator Admin API Specification for more information.
Table weight is an integer property of association between publications and publication items. Mobile Server uses table weight to determine which order to apply Client Operations to master tables as follows:
The Mobile Server supports sequence partitioning and replication to client devices.
You can create a sequence with the CreateSequence function, which has the following syntax:
public static void CreateSequence(String name) throws Throwable
The following examples create a sequence named CUSTOM1:
Consolidator.CreateSequence("CUSTOM1");
You can create a user subscription to a publication by using one of the following methods.
You can subscribe users to a publication using the CreateSubscription function, which has the following syntax:
public static void CreateSubscription(String publication, String clientid) throws Throwable
The following examples subscribe the client, DAVIDL, to the publication, T_SAMPLE1, with the parameters listed in the following table.
Table 2-12 Create Subscription Sample Parameters
| Parameter | Value | Definition |
|---|---|---|
|
|
T_SAMPLE1 |
Defines the publication as T_SAMPLE1. |
|
|
DAVIDL |
Defines the client as DAVIDL. |
Consolidator.CreateSubscription("T_SAMPLE1", "DAVIDL");
You can use Mobile Server sequences to generate unique primary keys on client devices. To use a replicated sequence, you need to first create it and then partition it for Mobile Sync Client users.
You can create sequence partitions using the CreateSequencePartition function, which has the following syntax:
public static void CreateSequencePartition(String name, String clientid, long curr_val, long incr) throws Throwable
The following examples partition the CUSTOM1 sequence using the parameters specified in the table:
Table 2-13 Create Sequence Partition Sample Parameters
Consolidator.CreateSequencePartition("CUSTOM1", "DAVIDL", 1000, 1);
|
Note: To ensure that the sequence is unique, use a unique starting position and set the increment value equal to the total number of clients on the server. |
Some publications have parameters. When a publication has parameters, you must set those parameters for the publication's subscription.
You can define subscription instantiation parameters with the SetSubscriptionParameter function, which has the following syntax:
public static void SetSubscriptionParameter(String publication, String clientid, String param_name, String param_value) throws Throwable
The following examples subscribe the client, DAVIDL, to the publication, T_SAMPLE1, with the parameters listed in the table:
Table 2-14 Set Subscription Parameter Sample Parameters
Consolidator.SetSubscriptionParameter("T_SAMPLE1", "DAVIDL", "COMP", "'P'");
After you set a subscription's publication parameters, you complete the subscription process by instantiating the subscription. When the Mobile Server instantiates a subscription, it creates a complete internal representation of the subscription.
You can instantiate a subscription with the InstantiateSubscription function, which has the following syntax:
public static void InstantiateSubscription(String publication, String clientid) throws Throwable
The following examples instantiate a client's subscription to a publication, with the values specified in the table:
Table 2-15 Instantiate Subscription Sample Parameters
| Parameter | Value | Definition |
|---|---|---|
|
|
T_SAMPLE1 |
Defines the publication as T_SAMPLE1. |
|
|
DAVIDL |
Defines the client as DAVIDL. |
Consolidator.InstantiateSubscription("T_SAMPLE1", "DAVIDL");
You can add additional columns to existing publication items. These new columns are pushed to all subscribing clients the next time they synchronize. This is accomplished through a complete refresh of all changed publication items.
This allows additional columns to be added to an existing publication item.
public static void AlterPublicationItem(String name, String select_stmt) throws ThrowableTable 2-16 Alter Publication Item Sample Parameters
Consolidator.AlterPublicationItem("P_SAMEPLE1", "select * from EMP");
The following features include special functions which are not required for most application designs.
When creating publication items, the user can specify a customizable package to be called during the Apply and Compose phase of the MGP background process. These procedures enable you to incorporate customized code into the process. The clientname and tranid are passed to allow for customization at the user and transaction level.
This procedure must be called before any client's data from inqueue is applied.
procedure BeforeApply(clientname varchar2)
This procedure must be called after all client's data is applied.
procedure AfterApply(clientname varchar2)
This procedure must be called before client's data with tranid is applied.
procedure BeforeTranApply(tranid number)
This procedure must be called after client's data with tranid is applied.
procedure AfterTranApply(tranid number)
This procedure must be called before outqueue is composed.
procedure BeforeCompose(clientname varchar2)
This procedure must be called after outqueue is composed.
procedure AfterCompose(clientname varchar2)
Once a publication item has been created, a user can specify a customized PL/SQL procedure to be called in place of DML operations for that publication item. There can be only one mobile_dml_procedure per publication or pub_item. For example, if you want to have a DML procedure for a publication item A that has the following query:
select A,B,C from pub_item_a_table
where A is a primary key, then your DML procedure should have the following signature:
any_schema.any_package.any_name (DML in CHAR(1), A in TYPE, B in TYPE, C in TYPE, A_OLD in TYPE)
This procedure will be called with 'I', 'U', 'D' as the DML type. In case of inserts and deletes, A_OLD will be null. In case of updates, it will be set to the primary key of the row that is being updated.
You can specify a virtual primary key for publication items where the base object does not have a primary key defined. There are methods for creating and dropping a virtual primary key.
This creates a virtual primary key column.
This is used to create an updateable publication item where the primary key is a virtual column.
public static void CreateVirtualPKColumn(String owner, String store, String column) throws ThrowableTable 2-17 Create Virtual Primary Key Column Parameters
Consolidator.CreateVirtualPKColumn("SAMPLE1", "DEPT", "DEPT_ID");
This allows a primary key to be dropped.
public static void DropVirtualPKColumn(String owner, String store) throws ThrowableTable 2-18 Drop Virtual Primary Key Column Parameters
| Parameter | Value | Description |
|---|---|---|
|
|
|
A string specifying a the owner of the base object. |
|
|
|
A string specifying the base object. |
Consolidator.DropVirtualPKColumn("SAMPLE1", "DEPT");
A restricting predicate can be assigned to a publication item as it is added to a publication. When a client is synchronizing in high priority mode, the predicate is used to limit data pushed to the device. This parameter can be null. This parameter is for advanced use.
For each publication item created, a separate and corresponding error queue is created. The purpose of this queue is to store transactions that fail due to unresolved conflicts. The administrator can attempt to resolve the conflicts, either by modifying the error queue data or that of the server, and then she may attempt to re-apply the transaction via the Execute Transaction API call. The administrator may also purge the error queues through the Purge Transaction API call.
The execute transaction function re-executes transactions in the Mobile Server Error Queue.
public static void ExecuteTransaction(String clientid, long tid) throws ThrowableTable 2-19 Execute Transaction Parameters
| Parameter | Description |
|---|---|
|
|
The Mobile Sync Client name. |
|
|
The transaction ID. |
Consolidator.ExecuteTransaction("DAVIDL", 100002);
The purge transaction function purges a transaction from the Mobile Server error queue.
public static void PurgeTransaction(String clientid, long tid) throws ThrowableTable 2-20 Purge Transaction Parameters
| Parameter | Value | Description |
|---|---|---|
|
clientid |
DAVIDL |
The Mobile Server user name. |
|
tid |
100001 |
Transaction ID |
Consolidator.PurgeTransaction("DAVIDL", 100001);
The Mobile Sync API allows an application to initiate and monitor synchronization with a database from a client device 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.
Mobile Sync consists of five function calls and a control structure.
Initialize the synchronization environment.
int ocSessionInit( ocEnv *env );
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. ocEnv structure is passed as a parameter, and should be initialized by the caller. If the caller wants to overwrite the user preference information after the ocSessionInit() call, that can be done by calling ocSaveUserInfo().
Frees and performs a cleanup of the synchronization environment.
int ocSessionTerm( ocEnv *env );
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 pair.
Saves user settings.
int ocSaveUserInfo( ocEnv *env );
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:
For usage of these fields, please refer to the section Section 2.6, "Mobile Sync API Data Structures".
Starts the synchronization process.
int ocDoSynchronize( ocEnv *env );
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 upload (send) is performed. If syncDirection is 2, only download (receive) is performed. Performing an upload only synchronization is useful if client device does not want to download data from the server.
Update the table flags for Selective Sync.
ocSetTableSyncFlag(ocEnv *env, const char* publication_name, const char* table_name, short sync_flag)
Env
Pointer to the synchronization environment.
publication_name
Used on CreatePublication(), which is part of the Consolidator Admin API. See the Oracle9i Lite Consolidator Admin API Specification for more information.
If publication_name is NULL, sync_flag apply for all items in the publication.
This string is same as client_name_template of CreatePublication(). In OKAPI case, it is database_name + '.' + store, where store is CreatePublicationItem()'s third parameter. See the Oracle9i Lite Consolidator Admin API Specification for more information on CreatePublication() and CreatePublicationItem().
If 1 do synchronize, If 0 do not synchronize. 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.
ocEnv is the data structure used by all the Mobile Sync 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 environment structure also contains fields that the caller can update to change program the way Mobile Sync 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 ocErrorexError; // extra error code ocTransportEnvtransportEnv; // transport control information // GUI related function entry progressProcfnProgress; // callback to track progress; this is optional // Values used for Progress Bar. If 0, progress bar won't show. longtotalSendDataLen; // 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, maped to ocTrHttpconnectProc fnConnect; // plug-in callback to establish a connection from// device to serverdisconnectProc fnDisconnect; // plug-in callback to dismantle connection from// device to serversendProc fnSend; // plug-in callback to send data receiveProc fnReceive; // plug-in callback to receive data }ocTransportEnv;
Once you configure transport between Oracle8 and the Windows, you must install and configure Mobile Sync on the device. Setting up the Mobile Client on the Windows CE device is a two step approach:
The Mobile Development Kit for Windows CE is installed in the Oracle_Home\Mobile\SDK\wince directory. Inside this directory are five folders labelled samples, wce200, wce211, wce212, and wce300.
The following table lists and describes the contents of this directory.
Run the appropriate CESETUP.EXE file in the Oracle_Home\Mobile\SDK\wince directory matching your processor and operating system combination. This program copies the necessary files to the Windows CE device, configures the Windows CE data source name (DSN), and sets up the environment on the device. Unless you modify it, the installation places the default database file, POLITE.ODB, in the \orace directory on the device. The setup initialization file, CESETUP.INI lists the files that are loaded to the device.
Replicating with the Windows CE devices using HTTP requires the TCP/IP communication protocol. This document 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:
|
Important: You must ensure that the TCP/IP addresses in your selected range are not already in use by other computers in your network. |
When you configure RAS verify that:
When you configure the Windows desktop settings, verify that:
The Mobile Development Kit provides a sample application called "Sample Orders" which can be installed using CEServices. Run CEServices and select the okdemo file from the Oracle_Home\Mobile\SDK\wince\samples folder corresponding to your processor into the \orace folder on your Windows CE device.
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 ConsolidatorClient.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.
Mobile Sync requires the following parameters to sync:
Table 2-21 Mobile Sync Client Parameters
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.
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.
Consolidator contains system catalog views for locating Consolidator components. Use the Consolidator system catalog views to locate the following:
See Appendix A, "Mobile Server System Catalog Views", for more information.
|
|
![]() Copyright © 2001 Oracle Corporation. All Rights Reserved. |
|