diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-01-14 11:13:18 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-01-14 11:13:18 +0200 |
commit | f443b90f0d3f47a3ca78fcf4ef5f8b95dd33a72e (patch) | |
tree | 8caea4f48d4caa3e66cb1f534f24d3862955bc81 /doc/manual.xhtml | |
parent | 762448ca92b948c1701d07a3403e93f1c27c19bd (diff) |
Document default ctor requirements, odb::access usage
Diffstat (limited to 'doc/manual.xhtml')
-rw-r--r-- | doc/manual.xhtml | 37 |
1 files 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 <a href="#5">Chapter 5, "ODB Pragma Language"</a>).</p> + <p>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 + (<a href="#3.5">Section 3.5, "Loading Persistent Objects"</a>, + <a href="#4.4">Section 4.4, "Query Result"</a>).</p> + + <p>If an object class has private or protected non-transient data + members or if its default constructor is not public, then the + <code>odb::access</code> class, defined in the + <code><odb/core.hxx></code> header, should be declared a + friend of this object type. For example:</p> + + <pre class="c++"> +#include <odb/core.hxx> + +#pragma db object +class person +{ + ... + +private: + friend class odb::access; + + person () {} + + #pragma db id + unsigned long id_; +}; + </pre> + + <p>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 <code>int</code> or <code>std::string</code> since the @@ -1652,7 +1686,6 @@ class name { ... -private: std::string first_; std::string last_; }; |