Use the chained read policy to chain an alternate read operation to a create, update, or delete (CUD) operation. This updates the consolidated database (CDB) at a finer granularity than could be achieved with just the CUD operation.
The parameters of the alternate read operation should be a subset of the parameters of operation to which it is chained. The parameter values of the chaining operation are passed to the alternate read operation, and the results returned from the alternate read operation are applied to the CDB.
This example uses the department table from the sampledb database, which is accessible from the "My Sample Database" connection profile.
- To create a mobile business object (MBO), drag and drop the sampledb table department onto the Mobile Application Diagram and accept the default operations, when prompted in the Quick Create wizard.
- Double-click the create operation to open the operation in the Properties view.
- Select the Cache Update Policy tab, and select Chained read.
- Select create to launch the New Operation wizard to define and add the alternate read operation:
- Name – AR
- Operation type – ALTERNATE READ
- Specify data source – My Sample Database
Select
Next and enter the SQL definition:
select * from department where dept_id < 400
- Click Finish.
- Deploy the MBO to Unwired Server.
- The result is an MBO that when accessed from a device application or test client (assuming that the MBO's Cache interval is long enough to complete the test without requiring a cache refresh) behaves as follows:
- The create operation inserts records into the EIS.
- The alternate read operation updates the CDB only for records where dept_id < 400, and is called after the create operation.
From an end-to-end perspective:
- The initial synchronization of this MBO from a test client or a device application results in the
client, CDB, and EIS with the same data:
dept_id dept_name dept_head_id
------- ----------- ------------
100 R & D 501
200 Sales 902
300 Finance 1293
400 Marketing 1576
500 Shipping 703
- This record is inserted into the EIS (using some method other than the MBO operation):
dept_id=1000, dept_name="QA", dept_head_id=501
The EIS now contains:dept_id dept_name dept_head_id
------- ----------- ------------
100 R & D 501
200 Sales 902
300 Finance 1293
400 Marketing 1576
500 Shipping 703
1000 QA 501
- The client and CDB are not updated with the new record.
- The client invokes the create operation to insert the record:
dept_id=350, dept_name="QA", dept_head_id=501
- The client invokes the alternate read operation and sync's the MBO. While the EIS contains dept_id=1000 and dept_id=350:
dept_id dept_name dept_head_id
------- ----------- ------------
100 R & D 501
200 Sales 902
300 Finance 1293
400 Marketing 1576
500 Shipping 703
1000 QA 501
350 QA 501
Based on the alternate read operation's definition, the only new record retrieved from the EIS and updated in the CDB and client is dept_id=350 record: dept_id dept_name dept_head_id
------- ----------- ------------
100 R & D 501
200 Sales 902
300 Finance 1293
400 Marketing 1576
500 Shipping 703
350 QA 501