The beginLoad and endLoad instructions bracket an atomic read-only transaction.
Syntax
The syntax of the beginLoad instruction and the endLoad instruction is:
beginLoad;
endLoad;
Description
All database objects locked between the current beginLoad and endLoad instructions remain locked until the endLoad instruction is executed at which time they are unlocked. Objects locked with session duration and objects locked before the current beginLoad instruction are not unlocked by the endLoad instruction.
Unlock object requests are ignored between beginLoad and endLoad instructions.
Read transactions can be nested up to a maximum level of 255; that is, a beginLoad and endLoad transaction can be nested inside another beginLoad and endLoad transaction or inside a beginLock and endLock transaction.
commitTransaction and abortTransaction instructions end any current read-only transactions and release all transaction duration locks.
An object must be locked directly or indirectly to guarantee that the latest edition of the object is loaded. (For more details about object editions, see "Unlocking Objects", in Chapter 6.)
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 beginLoad and endLoad instructions.
getBalance(client: Client): Decimal; vars balance : Decimal[19,2]; begin balance := 0; beginLoad; foreach account in client.accounts do sharedLock(account); balance := balance + account.getBalance; endforeach; // unlock all accounts endLoad; return balance; end;
In this example, a shared (read) lock is acquired on each account as it is processed. The shared lock ensures that the account objects remain consistent for the duration of the totaling of account balances.
The foreach instruction implicitly acquires a shared lock on the client.accounts collection, which prevents accounts being added or deleted for the duration of the processing loop. This ensures that the totaling process sees a consistent view of accounts.