From f443b90f0d3f47a3ca78fcf4ef5f8b95dd33a72e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 14 Jan 2011 11:13:18 +0200 Subject: Document default ctor requirements, odb::access usage --- doc/manual.xhtml | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/doc/manual.xhtml b/doc/manual.xhtml index bdfb6fd..64d873a 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -1622,7 +1622,6 @@ class person { ... -private: #pragma db id unsigned long id_; }; @@ -1633,6 +1632,41 @@ private: the database-related properties of a class and its members (see Chapter 5, "ODB Pragma Language").

+

Normally, an object class should define the default constructor. The + generated database support code uses this constructor when + instantiating an object from the persistent state. If you add the + default constructor only for the database support code, then you + can make it private. It is also possible to have an object type + without the default constructor. However, in this case, the database + operations can only load the persistent state into an existing instance + (Section 3.5, "Loading Persistent Objects", + Section 4.4, "Query Result").

+ +

If an object class has private or protected non-transient data + members or if its default constructor is not public, then the + odb::access class, defined in the + <odb/core.hxx> header, should be declared a + friend of this object type. For example:

+ +
+#include <odb/core.hxx>
+
+#pragma db object
+class person
+{
+  ...
+
+private:
+  friend class odb::access;
+
+  person () {}
+
+  #pragma db id
+  unsigned long id_;
+};
+  
+ +

You may be wondering whether we also have to declare value types as persistent. We don't need to do anything special for simple value types such as int or std::string since the @@ -1652,7 +1686,6 @@ class name { ... -private: std::string first_; std::string last_; }; -- cgit v1.1