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.
-
It allows persistent objects to be created, deleted, or updated. (An exception is raised if you attempt to create, delete, or update persistent objects outside of a transaction.)
-
It coordinates the locking of persistent objects. Persistent objects are automatically locked (with an exclusive lock) as they are updated within a transaction. The locks on these objects are released at the next commitTransaction instruction. For details about reading and writing transactions, see "Using Read and Write Transactions", earlier in this chapter.
-
It defers committing of updates to the database until the transaction is committed. Updates to persistent objects are not visible to other users until the next commitTransaction instruction is executed.
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
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;