beginTransaction Instruction

The beginTransaction instruction indicates the start of a transaction that updates persistent objects.

Syntax

The syntax of the beginTransaction instruction is:

beginTransaction;

Description

Persistent transactions allow updating of persistent objects only. The beginTransaction instruction causes the JADE Object Manager to place the process in transaction state. For more details, see "Locking Objects", in Chapter 6. Use the beginTransientTransaction instruction to update shared transient objects.

A persistent transaction has three effects, as follows.

No transaction is necessary when creating, deleting, or updating non-shared objects. These objects can be updated at any time. (For details about sharing uncommitted persistent objects, see "Sharing Uncommitted Persistent Objects", earlier in this chapter.)

Executing the beginTransaction instruction is prohibited in the current process when the prohibited parameter in the Process class prohibitPersistentUpdates method is set to true.

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.

To avoid having to specify beginTransaction; in full, you can simply press the Ctrl+Shift+B keys at the position in the method at which the instruction is to be inserted.

Example

The following example shows the use of the beginTransaction instruction.

initCompany();
begin
    company := Company.firstInstance;
    if company = null then
        beginTransaction;
        create company;
        company.name := "MegaCorp Inc";
        commitTransaction;
    endif;
end;