From 8d82c02a90cd7cc3f161828624db5b973585c34c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2011 15:16:49 +0200 Subject: Add support for persistent classes without object ids New pragma id (object). New test: common/no-id. --- doc/manual.xhtml | 86 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 69 insertions(+), 17 deletions(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 6c1c57c..f14febd 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -438,7 +438,8 @@ for consistency. 11.1.2pointer 11.1.3abstract 11.1.4readonly - 11.1.5callback + 11.1.5id + 11.1.6callback @@ -1925,10 +1926,10 @@ max age: 33

An object is an independent entity. It can be stored, updated, and deleted in the database independent of other objects. - An object has an identifier, called object id, that is - unique among all instances of an object type within a database. In - contrast, a value can only be stored in the database as part of an - object and doesn't have its own unique identifier.

+ Normally, an object has an identifier, called object id, + that is unique among all instances of an object type within a + database. In contrast, a value can only be stored in the database + as part of an object and doesn't have its own unique identifier.

An object consists of data members which are either values (Chapter 7, "Value Types"), pointers @@ -2030,9 +2031,13 @@ class person }; -

These two pragmas are the minimum required to declare a - persistent class. Other pragmas can be used to fine-tune - the database-related properties of a class and its +

While it is possible to declare a persistent class without an + object id, such a class will have limited functionality + (Section 11.1.5, "id"). + +

The above two pragmas are the minimum required to declare a + persistent class with an object id. Other pragmas can be used to + fine-tune the database-related properties of a class and its members (Chapter 11, "ODB Pragma Language").

Normally, an object class should define the default constructor. The @@ -7496,9 +7501,15 @@ class person + id + persistent class has no object id + 11.1.5 + + + callback database operations callback - 11.1.5 + 11.1.6 @@ -7631,7 +7642,46 @@ class person as well as composite value types (Section 11.3.6, "readonly") as read-only.

-

11.1.5 callback

+

11.1.5 id

+ +

The id specifier specifies that the persistent class + has no object id. It should be followed by opening and closing + parenthesis. For example:

+ +
+#pragma db object id()
+class person
+{
+  ...
+};
+  
+ +

A persistent class without an object id has limited functionality. + Such a class cannot be loaded with the database::load() + or database::find() functions (Section 3.8, + "Loading Persistent Objects"), updated with the + database::update() function (Section 3.9, + "Updating Persistent Objects"), or deleted with the + database::erase() function (Section 3.10, + "Deleting Persistent Objects"). To load and delete + objects without ids you can use the database::query() + (Chapter 4, "Querying the Database") and + database::erase_query() (Section 3.10, + "Deleting Persistent Objects") functions, respectively. + There is no way to update such objects except by using native SQL + statements (Section 3.11, "Executing Native SQL + Statements").

+ +

Furthermore, persistent classes without object ids cannot have container + data members nor can they be used in object relationships. Such objects + are not entered into the session object cache + (Section 10.1, "Object Cache") either.

+ +

To declare a persistent class with an object id, use the data member + id specifier (Section 11.4.1, + "id").

+ +

11.1.6 callback

The callback specifier specifies the persist class member function that should be called before and after a @@ -7840,7 +7890,7 @@ private: result iteration. The semantics of the callback specifier for a view are similar to those of the callback specifier for an object - (Section 11.1.5, "callback") + (Section 11.1.6, "callback") except that the only events that can trigger a callback call in the case of a view are pre_load and post_load.

@@ -8616,8 +8666,8 @@ typedef std::map<unsigned short, float> age_weight_map;

11.4.1 id

The id specifier specifies that a data member contains - the object id. Every persistent class must have a member designated - as an object's identifier. For example:

+ the object id. In a relational database, an identifier member is + mapped to a primary key. For example:

 #pragma db object
@@ -8630,11 +8680,13 @@ class person
 };
   
-

In a relational database, an identifier member is mapped to a - primary key.

+

Normally, every persistent class has a data member designated as an + object's identifier. However, it is possible to declare a + persistent class without an id using the object id + specifier (Section 11.1.5, "id").

-

Note also that the id specifier cannot be specified - for data members of composite value types or views.

+

Note also that the id specifier cannot be used for data + members of composite value types or views.

11.4.2 auto

-- cgit v1.1