From 9aab700d7fa01d0e6d2614ec22450241807b81be Mon Sep 17 00:00:00 2001
From: Boris Kolpackov A pragma with the 5.2 Object Type Pragmas
@@ -347,6 +348,14 @@ for consistency.
+ 5.2.1 table
5.2.2 pointer
5.3 Value Type Pragmas
@@ -358,6 +367,16 @@ for consistency.
+ 5.3.1 type
+ 5.3.2 unordered
+ 5.3.3 index_type
+ 5.3.4 key_type
+ 5.3.5 value_type
+ 5.3.6 id_column
+ 5.3.7 index_column
+ 5.3.8 key_column
5.3.9 value_column
5.4.3 type
5.4.4 column
+ 5.4.5 transient
+ 5.4.6 inverse
+ 5.4.7 unordered
+ 5.4.8 table
+ 5.4.9 index_type
+ 5.4.10 key_type
+ 5.4.11 value_type
+ 5.4.12 id_column
+ 5.4.13 index_column
+ 5.4.14 key_column
@@ -3067,13 +3086,36 @@ xlC -qsuppress=1540-1401 ...
5.4.15 value_column
5.2 Object Type Pragmas
object
qualifier declares a C++ class
- as a persistent object type. The qualifier can be optionally followed
- by the table
specifier.
Specifier | +Summary | +Section | +
---|---|---|
table |
+ the table name for the persistent class | +5.2.1 | +
pointer |
+ the pointer type for the persistent class | +5.2.2 | +
table
The table
specifier specifies the table name that should
- be used to store objects of this class in a relational database. For
+ be used to store objects of the class in a relational database. For
example:
@@ -3087,11 +3129,135 @@ class personIf the table name is not specified, the class name is used as the table name.
+5.2.2
+ +pointer
The
+ +pointer
specifier specifies the pointer type for + the persistent class. The pointer type is used to return and pass + dynamically allocated instances of the persistent class in the + database operations. For example:+#pragma db object pointer(std::tr1::shared_ptr<person>) +class person +{ + ... +}; ++ +There are several ways to specify an object pointer with the +
+ +pointer
specifier. You can use a complete pointer + type as shown in the example above. Alternatively, you can + specify only the template name of a smart pointer in which + case the ODB compiler will automatically append the class + name as a template argument. The following example is + equivalent to the one above:+#pragma db object pointer(std::tr1::shared_ptr) +class person +{ + ... +}; ++ +If you would like to use a naked pointer as an object pointer, + you can use
+ +*
as a shortcut:+#pragma db object pointer(*) // Same as pointer(person*) +class person +{ + ... +}; ++ +If a pointer type is not explicitly specified, the default + pointer, specified with the
+ +--default-pointer
+ ODB compiler option, is used. If this option is not specified + either, then the naked pointer is used by default.For additional information on object pointers, refer to + Section @@, "".
+5.3 Value Type Pragmas
A pragma with the
+ type. It can be optionally followed, in any order, by one or more + specifiers summarized in the table below: + + +value
qualifier describes a value - type and can be optionally followed by thetype
- specifier.
Specifier | +Summary | +Section | +
---|---|---|
type |
+ the database type for the value type | +5.3.1 | +
unordered |
+ ordered container should be stored unordered | +5.3.2 | +
index_type |
+ the database type for the container's index type | +5.3.3 | +
key_type |
+ the database type for the container's key type | +5.3.4 | +
value_type |
+ the database type for the container's value type | +5.3.5 | +
id_column |
+ the column name for the container's table object id | +5.3.6 | +
index_column |
+ the column name for the container's table index | +5.3.7 | +
key_column |
+ the column name for the container's table key | +5.3.8 | +
value_column |
+ the column name for the container's table value | +5.3.9 | +
Many of the value type specifiers have corresponding member type + specifiers with the same names (see Section 5.4, + "Data Member Pragmas"). The behavior of such specifiers + for members is similar to that for value types. The only difference + is the scope. A particular value type specifier applies to all + members of this value type that don't have a pre-member version + of the specifier. While the member specifier always applies only + to a single member. In other words, member specifiers take precedence + over values specified with value specifiers.
type
mapping
example in the odb-examples
package shows how to do this for all the supported database systems.
- It is also possible to change the database type mapping for individual - members, as described in Section 5.4, "Data Member - Pragmas".
+unordered
The unordered
specifier specifies that the ordered
+ container should be stored in the database unordered. The database
+ table for such a container will not contain the index column
+ and the order in which elements are retrieved from the database may
+ not be the same as the order in which they were stored. For example:
+typedef std::vector<std::string> names; +#pragma db value(names) unordered ++ +
index_type
The index_type
specifier specifies the native
+ database type that should be used for the ordered container's
+ index column. The semantics of index_type
+ are similar to that of the type
specifier (see
+ Section 5.3.1, "type
"). The native
+ database type is expected to be an integer type. For example:
+typedef std::vector<std::string> names; +#pragma db value(names) index_type("SMALLINT UNSIGNED NOT NULL") ++ +
key_type
The key_type
specifier specifies the native
+ database type that should be used for the map container's
+ key column. The semantics of key_type
+ are similar to that of the type
specifier (see
+ Section 5.3.1, "type
"). For
+ example:
+typedef std::map<unsigned short, double> age_weight_map; +#pragma db value(age_weight_map) key_type("INT UNSIGNED NOT NULL") ++ +
value_type
The value_type
specifier specifies the native
+ database type that should be used for the container's
+ value column. The semantics of value_type
+ are similar to that of the type
specifier (see
+ Section 5.3.1, "type
"). For
+ example:
+typedef std::vector<std::string> names; +#pragma db value(names) value_type("VARCHAR(255) NOT NULL") ++ +
id_column
The id_column
specifier specifies the column
+ name that should be used to store the object id in the
+ container's table. For example:
+typedef std::vector<std::string> names; +#pragma db value(names) id_column("id") ++ +
If the column name is not specified, then object_id
+ is used by default.
index_column
The index_column
specifier specifies the column
+ name that should be used to store the element index in the
+ ordered container's table. For example:
+typedef std::vector<std::string> names; +#pragma db value(names) index_column("name_number") ++ +
If the column name is not specified, then index
+ is used by default.
key_column
The key_column
specifier specifies the column
+ name that should be used to store the key in the map
+ container's table. For example:
+typedef std::map<unsigned short, double> age_weight_map; +#pragma db value(age_weight_map) key_column("age") ++ +
If the column name is not specified, then key
+ is used by default.
value_column
The value_column
specifier specifies the column
+ name that should be used to store the element value in the
+ container's table. For example:
+typedef std::map<unsigned short, double> age_weight_map; +#pragma db value(age_weight_map) value_column("weight") ++ +
If the column name is not specified, then value
+ is used by default.
Specifier | Summary | @@ -3190,8 +3466,79 @@ private:5.4.5 |
---|---|---|
inverse |
+ the member is an inverse side of a bidirectional relationship | +5.4.6 | +
unordered |
+ ordered container should be stored unordered | +5.4.7 | +
table |
+ the table name for the container | +5.4.8 | +
index_type |
+ the database type for the container's index type | +5.4.9 | +
key_type |
+ the database type for the container's key type | +5.4.10 | +
value_type |
+ the database type for the container's value type | +5.4.11 | +
id_column |
+ the column name for the container's table object id | +5.4.12 | +
index_column |
+ the column name for the container's table index | +5.4.13 | +
key_column |
+ the column name for the container's table key | +5.4.14 | +
value_column |
+ the column name for the container's table value | +5.4.15 | +
Many of the member specifiers have corresponding value type + specifiers with the same names (see Section 5.3, + "Value Type Pragmas"). The behavior of such specifiers + for members is similar to that for value types. The only difference + is the scope. A particular value type specifier applies to all + members of this value type that don't have a pre-member version + of the specifier. While the member specifier always applies only + to a single member. In other words, member specifiers take precedence + over values specified with value specifiers.
+id
The id
specifier specifies that the data member contains
@@ -3244,7 +3591,7 @@ private:
type
The type
specifier specifies the native database type
- that should be used for this data member. For example:
#pragma db object @@ -3258,18 +3605,10 @@ private: };-
The behavior of this specifier for members is similar to that
- for value types. The only difference is the scope. The value
- type pragma applies to all members with this value type that
- don't have their own type
specifiers, while the
- member pragma applies only to a single member. For more
- information on the semantics of this specifier, refer to
- Section 5.3, "Value Type Pragmas".
column
The column
specifier specifies the column name
- that should be used to store this member in a relational database.
+ that should be used to store the member in a relational database.
For example:
@@ -3311,6 +3650,255 @@ private: references that are only meaningful in the application's memory, as well as utility members such as mutexes, etc. +5.4.6
+ +inverse
The
+ +inverse
specifier specifies that the member of + a pointer or a container of pointers type is an inverse side of + a bidirectional object relationship. The single required argument + to this specifier is the data member name in the referenced object. + For example:+using std::tr1::shared_ptr; +using std::tr1::weak_ptr; + +class person; + +#pragma db object pointer(shared_ptr) +class employer +{ + ... +private: + std::vector<shared_ptr<person> > employees_; + ... +}; + +#pragma db object pointer(shared_ptr) +class person +{ + ... +private: + #pragma db inverse(employee_) + weak_ptr<employer> employer_; + ... +}; ++ +An inverse member does not have a corresponding column or table in + the resulting database schema. Instead, the column or table from + the referenced object is used to retrieve the relationship + information. Only ordered and set containers can be used for + inverse members. If an inverse member is of an ordered container + type, it is automatically marked as unordered (see + Section 5.4.7, "
+ +unordered
").5.4.7
+ +unordered
The
+ +unordered
specifier specifies that the member of + an ordered container type should be stored in the database unordered. + The database table for such a member will not contain the index column + and the order in which elements are retrieved from the database may + not be the same as the order in which they were stored. For example:+#pragma db object +class person +{ + ... +private: + #pragma db unordered + std::vector<std::string> nicknames_; + ... +}; ++ +5.4.8
+ +table
The
+ +table
specifier specifies the table name that should + be used to store the contents of the container member. For example:+#pragma db object +class person +{ + ... +private: + #pragma db table("nicknames") + std::vector<std::string> nicknames_; + ... +}; ++ +If the table name is not specified, then the container table name + is constructed by concatenating the object's table name, underscore, + and the sanitized member name. The sanitized member name is obtained + by removing the common member name decorations, such as leading and + trailing underscores, the
+ +m_
prefix, etc. In the example + above, without thetable
specifier, the container's + table name would have beenperson_nicknames
.5.4.9
+ +index_type
The
+ +index_type
specifier specifies the native + database type that should be used for the ordered container's + index column of the data member. The semantics ofindex_type
+ are similar to that of thetype
specifier (see + Section 5.4.3, "type
"). The native + database type is expected to be an integer type. For example:+#pragma db object +class person +{ + ... +private: + #pragma db index_type("SMALLINT UNSIGNED NOT NULL") + std::vector<std::string> nicknames_; + ... +}; ++ +5.4.10
+ +key_type
The
+ +key_type
specifier specifies the native + database type that should be used for the map container's + key column of the data member. The semantics ofkey_type
+ are similar to that of thetype
specifier (see + Section 5.4.3, "type
"). For + example:+#pragma db object +class person +{ + ... +private: + #pragma db key_type("INT UNSIGNED NOT NULL") + std::map<unsigned short, double> age_weight_map_; + ... +}; ++ +5.4.11
+ +value_type
The
+ +value_type
specifier specifies the native + database type that should be used for the container's + value column of the data member. The semantics ofvalue_type
+ are similar to that of thetype
specifier (see + Section 5.4.3, "type
"). For + example:+#pragma db object +class person +{ + ... +private: + #pragma db value_type("VARCHAR(255) NOT NULL") + std::vector<std::string> nicknames_; + ... +}; ++ +5.4.12
+ +id_column
The
+ +id_column
specifier specifies the column + name that should be used to store the object id in the + container's table for the member. The semantics of +id_column
are similar to that of the +column
specifier (see + Section 5.4.4, "column
"). + For example:+#pragma db object +class person +{ + ... +private: + #pragma db id_column("person_id") + std::vector<std::string> nicknames_; + ... +}; ++ +If the column name is not specified, then
+ +object_id
+ is used by default.5.4.13
+ +index_column
The
+ +index_column
specifier specifies the column + name that should be used to store the element index in the + ordered container's table for the member. The semantics of +index_column
are similar to that of the +column
specifier (see + Section 5.4.4, "column
"). + For example:+#pragma db object +class person +{ + ... +private: + #pragma db index_column("nickname_number") + std::vector<std::string> nicknames_; + ... +}; ++ +If the column name is not specified, then
+ +index
+ is used by default.5.4.14
+ +key_column
The
+ +key_column
specifier specifies the column + name that should be used to store the key in the map + container's table for the member. The semantics of +key_column
are similar to that of the +column
specifier (see + Section 5.4.4, "column
"). + For example:+#pragma db object +class person +{ + ... +private: + #pragma db key_column("age") + std::map<unsigned short, double> age_weight_map_; + ... +}; ++ +If the column name is not specified, then
+ +key
+ is used by default.5.4.15
+ +value_column
The
+ +value_column
specifier specifies the column + name that should be used to store the element value in the + container's table for the member. The semantics of +value_column
are similar to that of the +column
specifier (see + Section 5.4.4, "column
"). + For example:+#pragma db object +class person +{ + ... +private: + #pragma db value_column("weight") + std::map<unsigned short, double> age_weight_map_; + ... +}; ++ +If the column name is not specified, then
-- cgit v1.1value
+ is used by default.