Wt
4.11.1
|
A base class for database objects. More...
Public Member Functions | |
Dbo () | |
Constructor. | |
Dbo (const Dbo< C > &other) | |
Copy constructor. | |
dbo_traits< C >::IdType | id () const |
Returns the database id. More... | |
Session * | session () const |
Returns the session. More... | |
void | setDirty () |
Marks the object as modified. More... | |
bool | isDirty () const |
Returns whether this object is dirty. More... | |
ptr< C > | self () const |
Returns a dbo::ptr to this object. More... | |
A base class for database objects.
The only requirement for a class to be be persisted is to have a persist()
method. In some cases however, it may be convenient to be able to access database information of an object, such as its database id and its session, from the object itself.
By deriving your database class directly or indirectly from this class, you can have access to its id() and session(). This will increase the size of your object with one pointer.
The following example shows a skeleton for a database object which has access to its own id and session information:
Compare this to the skeleton for a minimum valid database class:
dbo_traits< C >::IdType Wt::Dbo::Dbo< C >::id |
Returns the database id.
Returns the database id of this object, or Wt::Dbo::dbo_traits<C>::invalidId() if the object is associated with a session or not yet stored in the database.
bool Wt::Dbo::Dbo< C >::isDirty |
Returns whether this object is dirty.
ptr< C > Wt::Dbo::Dbo< C >::self |
Returns a dbo::ptr to this object.
The returned pointer points to the current object only if there exists at least one other pointer to the object. Otherwise it returns a null
ptr.
This means that in practice you should adopt the habit of wrapping a newly created database object directly in a ptr (and perhaps also add it to a session):
Session * Wt::Dbo::Dbo< C >::session |
Returns the session.
Returns the session to which this object belongs, or nullptr
if the object is not associated with a session.
void Wt::Dbo::Dbo< C >::setDirty |
Marks the object as modified.
When accessing a database object using ptr.modify(), the object is marked as dirty. Any intermediate query will however flush the current transaction and other changes within a member method will not be recorded.
You can call this method to achieve the same as ptr.modify() but from within member methods.