| |
 |
Wednesday, August 21, 2002 |
Use CreateDelta instead of OpenTransaction(false) for write operations
Many of you are familiar with the following pattern/style of code:
var pITelespace = PropertyList.OpenProperty(PROPERTY_TELESPACE).Telespace; var pITransaction = pITelespace.OpenTransaction(false); try { . pIRecord.SetField("Name", "Paresh"); pIRecord.SetField("Company", "Groove Networks"); . pITransaction.Commit(); } catch { pITransaction.Abort(); }
There are 2 problems with this pattern/style of coding:
1) There will be 2 deltas disseminated to all other endpoints (which is less efficient) 2) Any undo/redo of the operations for Dynamics sequencing will not treat the 2 deltas as one transactional command.
Since the intent of the code above is to group all of the write operations as one transactional command, the appropriate approach is to have Dynamics Manager govern the execution of the write operations. This is accomplished by using the CreateDelta method:
var pIDynamicsManager = PropertyList.OpenProperty(PROPERTY_DYNAMICS_MANAGER).DynamicsManager; var pIDelta = pIDynamicsManager.CreateDelta(); try { . pIRecord.SetField("Name", "Paresh"); pIRecord.SetField("Company", "Groove Networks"); . pIDelta.Commit(); } catch { pIDelta.Abort(); }
8:52:30 AM
|
|
Use shared object tables to hold sets of data with GrooveRunTimeData
Shared Object Tables are process wide object tables that can be used to store references to scalar or object types. They can be created with or without a developer specified name, but keep in mind that if a name is used, developers must think about other instances of their tool running on the same device (cross account/telespace/tool)
[code fragment for performing deletion of records in recordset] // Create shared object table that will use record ids as index and record // types as values. This shared object table will be primarily used to // provide information about a record upon receipt of asynchronous // deletion notifications var pISharedObjectTable = GrooveScriptFunctions.OpenSharedObjectTable(""); GrooveRunTimeData.SetItem("DeletedRecordSharedObjectTable", pISharedObjectTable);
// Get record and clone it var pIRecord = RecordSetEngine.OpenRecord(i_ID); var pIDeletedRecord = pIRecord.Clone();
// Add cloned record to shared object table var pISharedObjectTable = GrooveRunTimeData.GetItem("DeletedRecordSharedObjectTable"); pISharedObjectTable[i_ID] = pIDeletedRecord;
// Remove record from recordset RecordSetEngine.RemoveRecord(i_ID); . .
[code fragment from OnRecordSetChanged asynchronous event handler] case GrooveRecordSetChangeType_Removed: { // Get record id var RecordID = i_pIRecordIDEnum.OpenNext();
// Get cached reference to record var pISharedObjectTable = GrooveRunTimeData.GetItem("DeletedRecordSharedObjectTable"); var pIRecord = pISharedObjectTable[RecordID];
// Remove cached reference to record pISharedObjectTable[RecordID] = null; . .
8:12:23 AM
|
|
© Copyright 2005 Paresh Suthar.
|
|
|
|
| August 2002 |
| Sun |
Mon |
Tue |
Wed |
Thu |
Fri |
Sat |
| |
|
|
|
1 |
2 |
3 |
| 4 |
5 |
6 |
7 |
8 |
9 |
10 |
| 11 |
12 |
13 |
14 |
15 |
16 |
17 |
| 18 |
19 |
20 |
21 |
22 |
23 |
24 |
| 25 |
26 |
27 |
28 |
29 |
30 |
31 |
| Jul Sep |
|
|