You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/refguide/runtime/optimistic-locking.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,49 +14,49 @@ Optimistic locking is a strategy used in concurrent systems to prevent **lost up
14
14
15
15
If a conflict is detected—meaning someone else has modified the data since you last read it—your update is rejected, and you typically have to re-read the data and try again.
16
16
17
-
## Project with Optimistic locking disabled
17
+
## Project With Optimistic Locking Disabled
18
18
19
19
When two modifications are saved, they are applied in the order of processing. Only changed attributes are written to the database. This means that if two objects with disjoint sets of changed attributes are committed, the changes are not overwritten.
20
20
21
21
For example, if one user commits changes for `AttributeA` and `AttributeB` and another user commits changes for `AttributeB` and `AttributeC` for the same object, then both `AttributeA` and `AttributeC` are committed according to both users' changes. `AttributeB` is committed based on whichever change was committed last.
22
22
23
-
## Project with Optimistic locking enabled
23
+
## Project With Optimistic Locking Enabled
24
24
25
25
The Mendix runtime implements optimistic locking by introducing a new attribute named `MxObjectVersion` with type `Long` to all entities tracking their version. The `MxObjectVersion` attribute is not write-protected. However, setting this value will **not** result in it being saved to the database. Its current value will be compared with the value for the same record in the database.
26
26
27
-
### How to enable and use optimistic locking
27
+
### How to Enable and Use Optimistic Locking
28
28
29
29
Optimistic locking can be enabled per Mendix application using the `Runtime` tab in the App settings dialog:
After optimistic locking is enabled, whenever a commit is executed, the Mendix runtime will automatically ensure that the object that is committed was not already changed by another party after the committer read the object.
34
34
35
-
### New projects and migration
35
+
### New Projects and Migration
36
36
37
37
In case an existing app already had the `MxObjectVersion` attribute, when optimistic locking is enabled a duplicate attribute will be reported in the Modeler. This must be fixed by renaming the existing attribute to another name. The system attribute cannot be renamed.
38
38
39
39
### Behavior
40
40
41
41
Here we describe how various runtime actions are influenced by optimistic locking:
42
42
43
-
#### Create object
43
+
#### Create Object
44
44
45
45
Initialize the `MxObjectVersion` attribute to `0`.
46
46
47
-
#### Commit object
47
+
#### Commit Object
48
48
49
49
When the `MxObjectVersion` attribute in the object being committed is different from the value in the database, or the object was deleted from the database, throw a `ConcurrentModificationRuntimeException`. Otherwise, proceed with the commit while incrementing `MxObjectVersion` by one.
50
50
51
-
#### Delete object
51
+
#### Delete Object
52
52
53
53
When the `MxObjectVersion` attribute in the object being deleted is different from the value in the database, throw a `ConcurrentModificationRuntimeException`. Otherwise, proceed with the delete. If the object was already deleted, no error occurs, as is the case without optimistic locking.
54
54
55
-
## Performance impact
55
+
## Performance Impact
56
56
57
57
Because of the version check performed during commit and delete, optimistic locking incurs some minor performance impact.
58
58
59
-
## Handling optimistic locking errors in Microflows
59
+
## Handling Optimistic Locking Errors in Microflows
60
60
61
61
When an optimistic locking error occurs, the runtime log contains an entry similar to the following:
62
62
@@ -83,26 +83,26 @@ An example can be seen below. The change action has error handling `Custom witho
83
83
84
84
Check the [documentation](https://docs.mendix.com/refguide/error-handling-in-microflows/) about error handling to find more information about differences between `Custom with Rollback` and `Custom without Rollback`.
85
85
86
-
## Handling optimistic locking errors in Java actions
86
+
## Handling Optimistic Locking Errors in Java Actions
87
87
88
-
In Java actions an optimistic locking error can be handled by similar steps described in [Handling optimistic locking errors in Microflows]. However, the `com.mendix.systemwideinterfaces.connectionbus.data.ConcurrentModificationRuntimeException` exception will not be the top level exception thrown by the Mendix runtime. It will be wrapped in another exception, so the `cause` chain of caught exceptions should be inspected.
88
+
In Java actions an optimistic locking error can be handled by similar steps described in [Handling Optimistic Locking Errors in Microflows]. However, the `com.mendix.systemwideinterfaces.connectionbus.data.ConcurrentModificationRuntimeException` exception will not be the top level exception thrown by the Mendix runtime. It will be wrapped in another exception, so the `cause` chain of caught exceptions should be inspected.
89
89
90
-
## Handling optimistic locking errors in the client
90
+
## Handling Optimistic Locking Errors in the Client
91
91
92
92
If the optimistic locking error is propagated to the client, then an error dialog is shown as follows:
To handle the optimistic locking error one of the following strategies can be used:
97
97
98
-
### Single `Save`button
98
+
### Single `Save`Button
99
99
100
100
In this case user can refresh the whole page losing all changes.
101
101
102
-
### `Save`button with a separate`Refresh`button
102
+
### `Save`Button With a Separate`Refresh`Button
103
103
104
104
A separate `Refresh` button that retrieves the latest object state from the database and applies the original changes onto the retrieved object. After clicking the `Refresh` button, the user can inspect the latest state and can click the `Save` button again.
105
105
106
-
### Custom `Save`button
106
+
### Custom `Save`Button
107
107
108
-
A custom `Save` button that retries saving object using similar steps described in [Handling optimistic locking errors in Microflows], to retry until successful.
108
+
A custom `Save` button that retries saving object using similar steps described in [Handling Optimistic Locking Errors in Microflows], to retry until successful.
0 commit comments