You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Florian Hopf <ho...@synyx.de> on 2006/05/24 10:38:41 UTC
Inheritance and additional attributes
Hi *,
I'm trying to get inheritance working and can't find a solution in the
archives and the inheritance guide.
What I want to achieve is something like this:
I have an abstract class Element which defines a lot of attributes. This
class is extended by a few other concrete classes that define additional
attributes. So I define the abstract class like this:
<table name="element" abstract="false" description="the abstract
document element">
<column
name="id"
required="true"
primaryKey="true"
type="INTEGER"
description="Id"/>
<column
name="document_id"
required="true"
type="INTEGER"
description="reference to the corresponding document"/>
[snip more attributes]
<column
name="class_type"
inheritance="single"
type="VARCHAR"
size="10">
<inheritance key="text" class="TextElement"/>
</column>
<foreign-key foreignTable="document" onDelete="cascade">
<reference local="document_id" foreign="id"/>
</foreign-key>
</table>
And the concrete subclass like this:
<table name="text_element" abstract="false" description="element to
represent text content">
<column
name="content"
required="true"
type="VARCHAR"
description="the text content"
/>
</table>
What happens is, as far as I can see, the generator generates classes
for TextElement/TextElementPeer and afterwards overwrites TextElement
with one that extends Element without the additional attribute. Is it
possible to make inheritance with additional attributes work? Do I have
to declare the attributes in Element and tag them as belonging to
TextElement somehow?
Any hint is appreciated,
kind regards
Florian
--
/**
* Florian Hopf
* Synyx GmbH & Co. KG
* phone +49(0)721 9118303
* eMail hopf@synyx.de
* www http://www.synyx.de
* irc irc.synyx.de
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
Re: Inheritance and additional attributes
Posted by Florian Hopf <ho...@synyx.de>.
Hi,
Thomas Fischer schrieb:
> It is not possible to define additional attributes in the subclasses, nor
> is it possible to use another table for this. You must declare all members
> in the one table where all the class hierarchy are saved to. What you can
> do is to declare the "additional" members als protected, and override the
> getters and setters with public methods in the subclass where you want to
> access them.
>
Thanks for the clarification. What I'll do is to use delegation and wrap
the classes with interfaces.
Kind regards
Florian
--
/**
* Florian Hopf
* Synyx GmbH & Co. KG
* phone +49(0)721 9118303
* eMail hopf@synyx.de
* www http://www.synyx.de
* irc irc.synyx.de
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org
RE: Inheritance and additional attributes
Posted by Thomas Fischer <fi...@seitenbau.net>.
Hi,
It is not possible to define additional attributes in the subclasses, nor
is it possible to use another table for this. You must declare all members
in the one table where all the class hierarchy are saved to. What you can
do is to declare the "additional" members als protected, and override the
getters and setters with public methods in the subclass where you want to
access them.
Thomas
Florian Hopf <ho...@synyx.de> schrieb am 24.05.2006 10:38:41:
> Hi *,
> I'm trying to get inheritance working and can't find a solution in the
> archives and the inheritance guide.
> What I want to achieve is something like this:
> I have an abstract class Element which defines a lot of attributes. This
> class is extended by a few other concrete classes that define additional
> attributes. So I define the abstract class like this:
>
> <table name="element" abstract="false" description="the abstract
> document element">
> <column
> name="id"
> required="true"
> primaryKey="true"
> type="INTEGER"
> description="Id"/>
> <column
> name="document_id"
> required="true"
> type="INTEGER"
> description="reference to the corresponding document"/>
>
> [snip more attributes]
>
> <column
> name="class_type"
> inheritance="single"
> type="VARCHAR"
> size="10">
> <inheritance key="text" class="TextElement"/>
> </column>
> <foreign-key foreignTable="document" onDelete="cascade">
> <reference local="document_id" foreign="id"/>
> </foreign-key>
> </table>
>
> And the concrete subclass like this:
>
> <table name="text_element" abstract="false" description="element to
> represent text content">
> <column
> name="content"
> required="true"
> type="VARCHAR"
> description="the text content"
> />
> </table>
>
> What happens is, as far as I can see, the generator generates classes
> for TextElement/TextElementPeer and afterwards overwrites TextElement
> with one that extends Element without the additional attribute. Is it
> possible to make inheritance with additional attributes work? Do I have
> to declare the attributes in Element and tag them as belonging to
> TextElement somehow?
>
> Any hint is appreciated,
> kind regards
> Florian
>
> --
> /**
> * Florian Hopf
> * Synyx GmbH & Co. KG
> * phone +49(0)721 9118303
> * eMail hopf@synyx.de
> * www http://www.synyx.de
> * irc irc.synyx.de
> */
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org