Sets the successful end of a set of database changes.
Commit
Objects: Procedure, Web Panel
Generators: .NET, .NET Framework, Java, RPG, Cobol, Ruby (up to GeneXus X Evolution 3)
The Commit command sets the successful end of a set of database changes. The set of database changes between Commit (or Rollback) commands is treated as a single unit (called Logical Unit of Work (LUW)).
This command assures that the set of changes are all (or none, if any error arises) applied to the Database.
If the KB has multiple Data Stores, the Commit command executes a Commit on every one of them that is active (i.e. where database changes have been performed) at the time the command is executed.
Issuing this command also releases any database locks that have been acquired.
Unless the Commitment property has been disabled, GeneXus activates Commitment Control for all Procedure and Transaction objects. If the Commit on Exit property is set to Yes, it also generates a Commit at the end of each object that updates the database.
The Commit command can be specified anywhere in the program source of Procedure objects. This will force GeneXus to generate a Commit in the source.
When the Commit command is included within a For Each command, it is always executed just before the EndFor (regardless of where it was included within the For Each sentence).
Notes:
Take this into account when designing batch processes that work with a large number of rows. You may need to "break" a big LUW into smaller ones by issuing Commit commands as appropriate.
- Many DBMSs close all open cursors when a Commit is executed.
This is a very important portability issue. You may face this problem in a For Each group that has (or calls an object that has) a Commit command.
- A Commit command in a For Each is always executed just before the EndFor.
No matter where you wrote the Commit command inside a For Each group. If it is executed, an internal flag is set so as to actually perform a Commit to the database just before the EndFor and after performing any Database changes that the For Each may have had.
Given the Invoice Transaction object:
Invoice
{
InvoiceId*
InvoiceDate
InvoiceAmount
}
from which the following table is created in the application database:
InvoiceID*
InvoiceDate
InvoiceAmount
suppose you need to perform a Commit each time 10 invoices are deleted.
This could be solved as follows:
&i = 0
For each Invoice
&i = &i + 1
delete
If &i = 10
commit
&i = 0
EndIf
EndFor
Rollback command
Commitment property
Commit on Exit property
Confirm Transactions property