Concurrency Handling - Additive Attributes

Unofficial Content

Additive attribute is an attribute inferred from the Extended Table that is updated by transaction rules.

GeneXus doesn't do an optimistic concurrency check on Additive Attributes1. This improves the concurrency of the generated application in some cases.

Examples of additive attributes are Item inventory, Customer balance.

Description

GeneXus uses optimistic concurrency to deal with concurrency issues, and it's a reasonable solution for most of the cases, but in some scenarios, it's not.

Suppose you have the Invoice Transaction:


And this rules:

subtract(InvoiceLineQty,ItemInventory);
error("Out of Inventory") if ItemInventory<0;

In this case, when you save an Invoice instance, the application will decrease the Item inventory, which is stored in the Item table, and if it's less than zero, it will throw the error message.

When using optimistic concurrency (Pseudo Conversational Dialog), it should also throw an exception if the Item inventory is not the same as it was when loading the Invoice. This has some drawbacks:

  1. If you are selling a product that is sold very frequently, it's very likely that you will get an optimistic concurrency error most of the time. This is definitely not a good thing.
  2. It looks that what we really want is to decrease the current inventory, regardless if it has the same value than when we read it, so it actually does not make sense to do an optimistic lock in that column.

GeneXus detects this kind of attributes, which we call "Additive attributes", and when saving the Invoice, it will perform the following steps:

  1. It will read the Item record with a lock, retrieving the current Item inventory
  2. It will decrease the value (in memory)
  3. It will check if the new Item inventory value is less than zero, and throw an exception if that's the case
  4. It will update the Item inventory with the new value

This means that the generated application will not perform an optimistic lock in the column, and that it will guarantee that the inventory check it's done over the stored value of the column. This way, it will prevent throwing optimistic concurrency exceptions for columns that are frequently changed, while keeping the data consistency.

GeneXus determines that an attribute is additive if the old value of the attribute is assigned in a rule to the new value of the attribute and the attribute does not belong to a base table of the transaction. In the invoice example, Item inventary belongs to the Item table and the subtract rule triggers this rules on Item inventary in specification time:

ItemInventory=ItemInventory.getoldvalue() InvoiceLineQty IF delete;
ItemInventory.getoldvalue()-InvoiceLineQty InvoiceLineQty.getoldvalue() IF ( insert or update or delete);

So, Item inventory is considered additive.


Notes:

  • To see if there is an assignment of the form att = att.getoldvalue(), look at the detailed navigation of the transaction.
  • In the above example, even if the Invoice Total was a redundant formula it would not be considered additive because it belongs to Invoice Base Table.

 

Scope

Languages: Java, .NET, .NET Mobile, Visual FoxPro , Visual Basic, RPG, Cobol, C/SQL
Objects: Transactions
Interfaces: Win, Web, Text

Availability

From version GeneXus 9.0.