From 27c4eddafa46061b50bd3f46effea4975a344ac6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 8 Nov 2011 17:32:58 +0200 Subject: Minor improvements to Optimistic Concurrency chapter --- doc/manual.xhtml | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 032a04e..05da67e 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -7450,6 +7450,7 @@ person p; t.commit (); } +cerr << "enter age for " << p.first () << " " << p.last () << endl; unsigned short age; cin >> age; p.age (age); @@ -7512,7 +7513,20 @@ class person for optimistic concurrency to function properly, the application should not modify the version member after making the object persistent or loading it from the database and until deleting the state of this - object from the database.

+ object from the database. To avoid any accidental modifications + to the version member, we can declare it const, for + example:

+ +
+#pragma db object optimistic
+class person
+{
+  ...
+
+  #pragma db version
+  const unsigned long version_;
+};
+  

When we call the database::update() function (Section 3.9, "Updating Persistent Objects") and pass @@ -7542,6 +7556,7 @@ person p; t.commit (); } +cerr << "enter age for " << p.first () << " " << p.last () << endl; unsigned short age; cin >> age; p.age (age); @@ -7574,7 +7589,8 @@ p.age (age); more expensive than a successful one. As a result, optimistic concurrency works best for situations with low to medium contention levels where the majority of the application transactions complete - without update conflicts.

+ without update conflicts. This is also the reason why this concurrency + model is called optimistic.

In addition to updates, ODB also performs state mismatch detection when we are deleting an object from the database -- cgit v1.1