A base class for database objects. More...
#include <Wt/Dbo/Dbo>
Public Member Functions | |
Dbo () | |
Constructor. | |
dbo_traits< C >::IdType | id () const |
Returns the database id. | |
Session * | session () const |
Returns the session. |
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:
class Cat { public: template <class Action> void persist(Action& a) { } };
dbo_traits< C >::IdType Wt::Dbo::Dbo< C >::id | ( | ) | const |
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.
Session * Wt::Dbo::Dbo< C >::session | ( | ) | const |
Returns the session.
Returns the session to which this object belongs, or 0 if the object is not associated with a session.