Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Using Caché Objects - InterSystems Documentation
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Version Checking<br />
3. Process A saves the object using %Save and receives a success status.<br />
Examining the data on disk shows that the object was not written to disk.<br />
This is an example of concurrent operations that occurred without adequate concurrency<br />
control. In this example, Process B should not have been allowed to delete the object if Process<br />
A really intended to write the object back to disk. Since Process A did not modify the object,<br />
no physical write occurred and unexpected results were observed. Had Process A modified<br />
the object, then %Save would have succeeded as before but the object would have been<br />
written to disk. These inconsistent results are just one example of allowing concurrent access<br />
without adequate controls in place at the application level. (The inconsistent behavior<br />
exhibited by a successful call to %Save and the object not appearing on disk is not a bug in<br />
%Save. It is a concurrency failure which, by definition, will leave the database in an inconsistent<br />
state.)<br />
The solution to this problem is to have Process A open the object with concurrency 3 or 4;<br />
in this case, Process B would then either have been denied access (failed with a concurrency<br />
violation) or would have had to wait until Process A released the object.<br />
A.2 Version Checking<br />
<strong>Caché</strong> implements version checking using a class parameter called VERSIONPROPERTY.<br />
All persistent classes have this parameter. When defining a persistent class, the procedure<br />
for enabling version checking is:<br />
1. Create a property of type %Integer that holds the updatable version number for each<br />
instance of the class.<br />
2. Set the value of the property's InitialExpression keyword to 0.<br />
3. Set the value of VERSIONPROPERTY to the name of that property. The value of<br />
VERSIONPROPERTY cannot be changed to a different property by a subclass.<br />
This incorporates version checking into updates to instances of the class.<br />
When version checking is implemented, the property specified by VERSIONPROPERTY is<br />
automatically incremented each time an instance of the class is updated (either by objects or<br />
SQL). Prior to incrementing the property, <strong>Caché</strong> compares its in-memory value to its stored<br />
value. If they are different, then a concurrency conflict is indicated and an error is returned;<br />
if they are the same, then the property is incremented and saved.<br />
<strong>Using</strong> <strong>Caché</strong> <strong>Objects</strong> 203