Traits for a class mapped with Wt::Dbo. More...
#include <Wt/Dbo/Dbo>
Public Types | |
typedef YourIdType | IdType |
Type of the primary key. More... | |
![]() | |
typedef long long | IdType |
Type of the primary key. More... | |
Static Public Member Functions | |
static IdType | invalidId () |
Returns the sentinel value for a null id. More... | |
static const char * | surrogateIdField () |
Configures the surrogate primary key field. More... | |
static const char * | versionField () |
Configures the optimistic concurrency version field. More... | |
![]() | |
static IdType | invalidId () |
Returns the sentinel value for a null id. More... | |
static const char * | surrogateIdField () |
Returns the database field name for the surrogate primary key. More... | |
static const char * | versionField () |
Configures the optimistic concurrency version field. More... | |
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 <tt>long long</tt> 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: - <i>default constructor</i> - <i>copy constructor</i> - serialization to a string (for formatting an error message in exceptions) : <tt>std::ostream << id</tt> - comparison operator (for use as a key in a std::map): <tt>id == id</tt> - less than operator (for use as a key in a std::map): <tt>id < id</tt> Only the default <tt>long long</tt> 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 0
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 0
instead.