|
Wt
4.10.0
|
Traits for a class mapped with Wt::Dbo. More...
Public Types | |
| typedef YourIdType | IdType |
| Type of the primary key. | |
Public Types inherited from Wt::Dbo::dbo_default_traits | |
| typedef long long | IdType |
| Type of the primary key. | |
Static Public Member Functions | |
| static IdType | invalidId () |
Returns the sentinel value for a null id. | |
| static const char * | surrogateIdField () |
| Configures the surrogate primary key field. | |
| static const char * | versionField () |
| Configures the optimistic concurrency version field. | |
Static Public Member Functions inherited from Wt::Dbo::dbo_default_traits | |
| static IdType | invalidId () |
Returns the sentinel value for a null id. | |
| static const char * | surrogateIdField () |
| Returns the database field name for the surrogate primary key. | |
| static const char * | versionField () |
| Configures the optimistic concurrency version field. | |
Traits for a class mapped with Wt::Dbo.
The traits class provides some of the mapping properties related to the primary key and optimistic concurrency locking using a version field.
See dbo_default_traits for default values.
The following example changes the surrogate id field name for a class Foo from the default "id" to "foo_id":
| typedef YourIdType Wt::Dbo::dbo_traits< C >::IdType |
Type of the primary key.
This indicates the type of the primary key, which needs to be long long for a surrogate id, but can be any type supported by Wt::Dbo::field() (including composite types) for a natural primary key.
The following operations need to be supported for an id value:
std::ostream << idid == idid < idOnly the default long long is supported for an auto-incrementing surrogate primary key. You need to change the default key type typically in conjuction with specifying a natural id, see Wt::Dbo::id().
The following example illustrates how to prepare a type to be usable as a composite id type:
|
static |
Returns the sentinel value for a null id.
When used as a foreign key, this value is used to represent a null value.
|
static |
Configures the surrogate primary key field.
Returns the field name which is the surrogate primary key, corresponding to the object's id.
You can disable this auto-incrementing surrogate id by returning nullptr instead. In that case you will need to define a natural id for your class using Wt::Dbo::id().
|
static |
Configures the optimistic concurrency version field.
Optimistic concurrency locking is used to detect concurrent updates by an object from multiple sessions. On each update, the version of a record is at the same time checked (to see if it matches the version of the record that was read), and incremented. A StaleObjectException is thrown if a record was modified by another session since it was read.
This method must return the database field name used for this version field.
You can disable optimistic locking using a version field all together for your class by returning nullptr instead.