IT tutorials
 
Technology
 

Microsoft Dynamic AX 2009 : The Database Layer - Transaction Semantics (part 4) - Concurrency Models - Using Relative Updates to Prevent Update Conflicts

8/19/2013 9:29:21 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
3.3 Using Relative Updates to Prevent Update Conflicts

Dynamics AX has always included built-in support for relative updates. But it is in combination with optimistic concurrency that this support is truly useful. Relative updates can be applied only to fields of type integer and real. You apply them by changing the FieldUpdate property from the default value of Absolute to Relative, as shown in Figure 7.

Figure 7. FieldUpdate table field property


The difference between an absolute update and a relative update is that an absolute update submits FIELD = <new value> in the UPDATE statement sent to the database, and a relative update submits FIELD = FIELD + <delta value>. The delta value is the difference between the originally selected value and the newly applied value. So if you change the SalesQty field on the SalesLine table from 2 to 5, the update statement contains either SALESQTY = 5 or SALESQTY = SALESQTY + 3, depending on whether you set the FieldUpdate property on the SalesQty field to Absolute or Relative.

When you use relative updates, neither the previous value in the database nor the value it becomes is important to the updating of the application logic. The only important thing is that the difference is added to the value in the database. If all fields being updated in an update statement use relative updates and the record is selected using optimistic concurrency, the RecVersion check isn’t added to the update statement. The previous value isn’t added because it isn’t important, regardless of whether any other process changes the value between the select and the update.

Using relative updates on tables combined with pessimistic concurrency has no benefit because an update lock is acquired when the application logic selects the record, so no other processes can update the same record between the select and the update.

Warning

You shouldn’t use relative updates for fields on which the application logic is making decisions if the select is made using optimistic concurrency. You can’t guarantee that any decision made is based on the actual value of the field. For example, a Boolean field shouldn’t be set to true or false based on whether a relative updated field is equal to zero because another process could update the relative field at the same time. The Boolean field would be set based on the value in memory, which might not be the value that is eventually written to the database.


3.4 Choosing a Concurrency Model During Development

When developing applications in Dynamics AX, you can control the use of a concurrency model on two levels. The first is at a table level, by setting a property on the table definition in the Application Object Tree (AOT), and the second is by enforcing a specific model in X++ code.

Figure 8 shows the table-level setting, in which the OccEnabled property can be set to either Yes (the default value) or No.

Figure 8. Optimistic concurrency control table property


When the runtime has to execute a statement such as select forupdate custTable where custTable.AccountNum == ‘4000’, it consults the OccEnabled property on the table and translates the statement into an SQL statement with either no hint or an UPDLOCK hint added to the SELECT statement.

The concurrency model setting on the tables in Dynamics AX is based on an assessment of whether the risk of update conflict is minimal for the majority of the daily business scenarios in the application in which the specific table is updated or deleted. The scenarios can be found by using the cross-reference system in Dynamics AX or by searching for places in the X++ code where the table is either updated or deleted. If a table is never updated or deleted in the X++ code, the execution of the code isn’t influenced by whether the table is OCC enabled because the table is manipulated only from a rich client form or a Web client form. Because the form application runtime doesn’t use the table-level setting when updating records, the OccEnabled property is set to Yes by default on these tables.

Note

Only about 40 of the approximately 2100 tables in the SYS layer don’t use optimistic concurrency.


If you encounter business scenarios that require the use of a different concurrency model, you should handle them individually by applying statement-level concurrency code.

You can apply statement-level concurrency control by exchanging the forupdate keyword with either optimisticlock or pessimisticlock. This enforces the use of either optimistic or pessimistic concurrency in a scenario in which the keyword is used and overrules the table-level setting. In case of enforced pessimistic concurrency, the select statement would be written as follows: select pessimisticlock custTable where custTable.AccountNum == ‘4000’.

Note

You can also control the concurrency model with the use of a variable by calling the concurrencyModel(ConcurrencyModel concurrencyModel) method on a cursor and passing the concurrency model as the parameter. The ConcurrencyModel type is an enumeration type. A similar method is available on the QueryBuildDataSource class, and you can even specify the concurrency model in metadata when defining a query element in the AOT.


You should enforce pessimistic concurrency when serialization is necessary; serialization is implemented by requiring an update lock on a record in the database. The lock prevents two processes from entering the same scenario because entering requires an update lock. Only the process holding the update lock can enter the scenario, and the other process is blocked until the lock is released. The serializing select statement should therefore include the pessimisticlock keyword.

Best Practices

Enforcing pessimistic concurrency by using the pessimisticlock keyword is a best practice for developing serialization logic, although you can implement the same pessimistic concurrency behavior by using the forupdate keyword on a table where pessimistic concurrency is chosen at the table level. The X++ code explicitly states that an update lock is required; more important, the scenario doesn’t fail if the table property is changed. You can change the OccEnabled property through customization in higher layers.


You should enforce optimistic concurrency in situations in which it is apparent that the optimistic model would improve concurrency and throughput compared to the pessimistic model, especially when use of the pessimistic model would cause major blocking because of update locks that are never converted into exclusive locks. For example, optimistic concurrency is enforced in the Dynamics AX consistency check classes, where you can assume that only a few records are in an inconsistent state and therefore need to be corrected and updated.

Best Practices

You should explicitly state the use of optimistic concurrency in the X++ code if the scenario always qualifies for the use of this model.

 
Others
 
- Microsoft Dynamic AX 2009 : The Database Layer - Transaction Semantics (part 3) - Concurrency Models - Concurrent Scenarios
- Microsoft Dynamic AX 2009 : The Database Layer - Transaction Semantics (part 2) - Isolation Levels, Concurrency Models
- Microsoft Dynamic AX 2009 : The Database Layer - Transaction Semantics (part 1)
- SQL Server 2008 R2 : SQL Server Index Maintenance (part 2) - Setting the Fill Factor, Reapplying the Fill Factor, Disabling Indexes, Managing Indexes with SSMS
- SQL Server 2008 R2 : SQL Server Index Maintenance (part 1)
- SQL Server 2008 R2 : Index Statistics (part 2) - Estimating Rows Using Index Statistics, Generating and Maintaining Index and Column Statistics
- SQL Server 2008 R2 : Index Statistics (part 1) - The Statistics Histogram, How the Statistics Histogram Is Used, Index Densities
- Keeping Windows 7 and Other Software Up to Date : Installing and Removing Software (part 2)
- Keeping Windows 7 and Other Software Up to Date : Installing and Removing Software (part 1)
- Keeping Windows 7 and Other Software Up to Date : Service Packs
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us