beginLock and endLock Instructions
The beginLock and endLock instructions bracket a read‑only transaction to ensure that objects referenced after executing the current beginLock instruction and before the endLock instruction are the latest editions of the objects.
Syntax
The syntax of the beginLock instruction and the endLock instruction is:
beginLock;
endLock;
Description
As objects are referenced, an implicit shared lock is acquired on each object, which causes the latest edition to be fetched from the server, if required. (For more details about object editions, see "Unlocking Objects", in Chapter 6.)
Read transactions can be nested up to a maximum level of 255; that is, a beginLock and endLock transaction can be nested inside another beginLock and endLock transaction or inside a beginLoad and endLoad transaction.
For details about reading and writing transactions, see "Using Read and Write Transactions", earlier in this chapter and for details about the restrictions that apply to transactions when using the serverExecution or clientExecution method option, see "Server and Client Execution Restrictions", earlier in this chapter.
Example
The following example shows the use of the beginLock and endLock instructions to acquire an implicit shared lock on each car object as it is referenced.
vars totalAge : Integer; allCars : CarsArray; car : Car; begin create allCars transient; Car.allInstances(allCars, 0, Car.abstract); beginLock; foreach car in allCars do totalAge := totalAge + car.calculateAge; endforeach; endLock; write "Average age: " & (totalAge/allCars.size).String; delete allCars; end;