Hello!
4) It is not mandatory to register/map class A.
If you want some code to be shared across several persistence classes,
you can also create a persistence field and use it in both classes:
namespace Wt {
namespace Dbo {
template <class Action>
void field(Action& action, Coordinate& coordinate, const std::string& name,
int size = -1)
{
field(action, coordinate.x, name + "_x");
field(action, coordinate.y, name + "_y");
}
}
}
(this example is taken from
http://www.webtoolkit.eu/wt/doc/git/tutorial/dbo/tutorial.html#_specifying_a_composite_natural_primary_key)
Then, you can use class Coordinate in your persistence classes:
class A {
public:
Coordinate c;
template<class Action>
void persist(Action& a) {
dbo::field(a, c, "c");
}
};
This should create two fields: c_x and c_y in database table.
2012/4/24 Tero Mäntyvaara <[email protected]>:
> Hi,
>
>
> thank you for your reply! 4) Is it mandatory to register/map class A in
> your example? This way it is possible to create base class that is
> abstract in persistence level.
>
>
> Tero
>
> On 23.4.2012 17:41, Nagaev Boris wrote:
>> Hello!
>>
>> 2,3) No. Abstract class can not be mapped to database. I think,
>> reading from database is implemented as follows: Wt::Dbo creates
>> instance of mapped C++ class using default constructor and then
>> applies .persist() method to set values from database to all fields of
>> this instance. Instance of abstract class can not be created, so we
>> get a compile error.
>>
>> 1) Possible (see example)
>> For each class (base and descendant), you should create a separate
>> table in database.
>> Add method .persist() to descendant class, which calls .persist()
>> method of its base class:
>>
>> class A {
>> public:
>> int x;
>>
>> template<class Action>
>> void persist(Action& a) {
>> dbo::field(a, x, "x");
>> }
>> };
>>
>> class B : public A {
>> public:
>> int y;
>>
>> template<class Action>
>> void persist(Action& a) {
>> A::persist(a);
>> dbo::field(a, y, "y");
>> }
>> };
>>
>> session.mapClass<A>("class_a");
>> session.mapClass<B>("class_b");
>>
>> Inheritance seems to work even if base class was inherited from
>> dbo::Dbo<A> template, but this is not documented.
>> http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Dbo_1_1Dbo.html
>>
>>
>> 2012/4/23 Tero Mäntyvaara <[email protected]>:
>>> Hi,
>>>
>>> I have three questions about inheritance and abstraction: is it possible...
>>> 1) ...to Wt::Dbo persistence class be inherited from another?
>>> 2) ...to make persistence class abstract?
>>> 3) ...inherit persistence class from abstract persistence class?
>>>
>>>
>>> Tero
>>>
>>> ------------------------------------------------------------------------------
>>> For Developers, A Lot Can Happen In A Second.
>>> Boundary is the first to Know...and Tell You.
>>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>>> http://p.sf.net/sfu/Boundary-d2dvs2
>>> _______________________________________________
>>> witty-interest mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/witty-interest
>>
>> ------------------------------------------------------------------------------
>> For Developers, A Lot Can Happen In A Second.
>> Boundary is the first to Know...and Tell You.
>> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
>> http://p.sf.net/sfu/Boundary-d2dvs2
>> _______________________________________________
>> witty-interest mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest