From 8e046e3ea7e88f872205c2b65cb7f9b86aaabd93 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 26 Apr 2012 11:29:05 +0200 Subject: Make session optional --- doc/manual.xhtml | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 132 insertions(+), 4 deletions(-) (limited to 'doc/manual.xhtml') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index cad568c..766844f 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -457,6 +457,7 @@ for consistency. 12.1.7callback 12.1.8schema 12.1.9polymorphic + 12.1.10session @@ -535,6 +536,7 @@ for consistency. 12.5.1pointer 12.5.2table 12.5.3schema + 12.5.4session @@ -6090,8 +6092,10 @@ class person

However, a value type that can be used as an object id has a number of restrictions. Such a value type cannot have container, object pointer, or read-only data members. It also must be - default-constructible and implement the less-than comparison operator - (operator<).

+ default-constructible. Furthermore, if the persistent class in which + this composite value type is used as object id has session support + enabled (Chapter 10, "Session"), then it must also + implement the less-than comparison operator (operator<).

7.2.2 Composite Value Column and Table Names

@@ -6848,6 +6852,11 @@ class contractor: public person }; +

Similarly, if we enable or disable session support + (Chapter 10, "Session") for the root class, then + the ODB compiler will automatically enable or disable it for all + the derived classes.

+

For polymorphic persistent classes, all the database operations can be performed on objects with different static and dynamic types. Similarly, operations that load persistent objects from the @@ -8258,6 +8267,50 @@ struct employee_name object cache. In future versions it will provide additional functionality, such as automatic object state change tracking.

+

Session support is optional and can be enabled or disabled on the + per object basis using the db session pragma, for + example:

+ +
+#pragma db object session
+class person
+{
+  ...
+};
+  
+ +

We can also enable or disable session support for a group of + objects at the namespace level:

+ +
+#pragma db namespace session
+namespace accounting
+{
+  #pragma db object                // Session support is enabled.
+  class employee
+  {
+    ...
+  };
+
+  #pragma db object session(false) // Session support is disabled.
+  class employer
+  {
+    ...
+  };
+}
+  
+ +

Finally, we can pass the --generate-session ODB compiler + option to enable session support by default. With this option session + support will be enabled for all the persistent classes except those + for which it was explicitly disabled using the + db session. An alternative to this method with the + same effect is to enable session support for the global namespace:

+ +
+#pragma db namespace() session
+  
+

Each thread of execution in an application can have only one active session at a time. A session is started by creating an instance of the odb::session class and is automatically terminated @@ -8374,8 +8427,8 @@ namespace odb

10.1 Object Cache

-

A session is an object cache. Every time an object is made persistent - by calling the database::persist() function +

A session is an object cache. Every time a session-enabled object is + made persistent by calling the database::persist() function (Section 3.7, "Making Objects Persistent"), loaded by calling the database::load() or database::find() function (Section 3.8, "Loading Persistent Objects"), @@ -8991,6 +9044,12 @@ class person 12.1.9 + + session + enable/disable session support for a persistent class + 12.1.10 + +

12.1.1 table

@@ -9549,6 +9608,38 @@ class employee class is polymorphic. For more information on polymorphism support, refer to Chapter 8, "Inheritance".

+

12.1.10 session

+ +

The session specifier specifies whether to enable + session support for a persistent class. For example:

+ +
+#pragma db object session        // Enable.
+class person
+{
+  ...
+};
+
+#pragma db object session(true)  // Enable.
+class employee
+{
+  ...
+};
+
+#pragma db object session(false) // Disable.
+class employer
+{
+  ...
+};
+  
+ +

Session support is disabled by default unless the + --generate-session ODB compiler option is specified + or session support is enabled at the namespace level + (Section 12.5.4, "session"). + For more information on sessions, refer to Chapter + 10, "Session".

+

12.2 View Type Pragmas

A pragma with the view qualifier declares a C++ class @@ -11380,6 +11471,12 @@ namespace test 12.5.3 + + session + enable/disable session support for persistent classes inside a namespace + 12.5.4 + +

12.5.1 pointer

@@ -11507,6 +11604,37 @@ class employer For more information on specifying a database schema refer to Section 12.1.8, "schema".

+

12.5.4 session

+ +

The session specifier specifies whether to enable + session support for persistent classes inside a namespace. For + example:

+ +
+#pragma db namespace session
+namespace hr
+{
+  #pragma db object                // Enabled.
+  class employee
+  {
+    ...
+  };
+
+  #pragma db object session(false) // Disabled.
+  class employer
+  {
+    ...
+  };
+}
+  
+ +

Session support is disabled by default unless the + --generate-session ODB compiler option is specified. + Session support specified at the namespace level can be overridden + on the per object basis (Section 12.1.10, + "session"). For more information on sessions, + refer to Chapter 10, "Session".

+

12.6 C++ Compiler Warnings

When a C++ header file defining persistent classes and containing -- cgit v1.1