Loading ...
Sorry, an error occurred while loading the content.

Using ToPropertyTable with an ElementType

Expand Messages
  • Gary Lawrence Murphy
    I haven t found any example in the archives where ToPropertyTable is used with an ElementType that is a class, and since the only option to specify what
    Message 1 of 2 , Feb 11, 2002
    • 0 Attachment
      I haven't found any example in the archives where ToPropertyTable is
      used with an ElementType that is a class, and since the only option to
      specify what happens to the ElementType is to specify a target
      "column" (this "column" isn't described in the DTD; <PCDATA/> examples
      in the product description example show 'column' as containing the
      PropertyMap'd PCDATA, but that's the only reference I can find).

      Perhaps this is not possible with 1.0

      Here's the scenario:

      <match game="23">
      <referees>
      <person id="1" name="joe"/>
      <person id="2" name="mary"/>
      </referees>
      </match>

      and I'd like this to create tupples

      REFEREES ( MATCHID = 23, PERSONID = 1 )

      or even

      REFEREES ( MATCHID = 23, PERSONID = 1, NAME = joe )

      but this did not seem possible because PropertyMap can only take
      the PCDATA of a nested element; there's no syntax to map
      child attributes to parent columns.

      I had originally tried

      <RelatedClass KeyInParentTable="Foreign">
      <ElementType Name="person"/>
      <CandidateKey Generate="No">
      <Column Name="id"/>
      </CandidateKey>
      <ForeignKey>
      <Column Name="personid"/>
      </ForeignKey>
      </RelatedClass>

      but, while the table looked promising (matchid, personid) for
      reasons I don't quite understand this only records the last
      person listed for the referees element.

      So I thought PropertyMap's ToPropertyTable might let me indirect:

      REFEREES ( MATCHID = 23, REFEREEFK = K1 )
      REFEREES ( MATCHID = 23, REFEREEFK = K2 )

      REFEREE ( REFEREEPK = K1, PERSONID = "1" )
      REFEREE ( REFEREEPK = K2, PERSONID = "2" )

      but here the examples showing ToPropertyTable only deal with <PCDATA/>
      and do not define what happens if the PropertyMap is an ElementType

      Is there someplace where this case of ToPropertyTable is described?
      Am I even headed in the right direction? ;)

      --
      Gary Lawrence Murphy <garym@...> TeleDynamics Communications Inc
      Business Innovations Through Open Source Systems: http://www.teledyn.com
      "Computers are useless. They can only give you answers."(Pablo Picasso)
    • Ronald Bourret
      Your initial impulse (to use a related class with a foreign key in the parent table) was the correct one. In fact, I tried it and was surprised when it didn t
      Message 2 of 2 , Feb 14, 2002
      • 0 Attachment
        Your initial impulse (to use a related class with a foreign key in the
        parent table) was the correct one. In fact, I tried it and was surprised
        when it didn't work. The reason is a design bug. In particular, XML-DBMS
        cannot handle multiple occurences of the same child class element type
        when the foreign key is in the parent. It can only handle one
        occurrence.

        WORKAROUND
        ==========

        As a workaround, you need to convert your XML to/from the following XML,
        which can be mapped with the RelatedClass element you show:

        <match game="23">
        <referees>
        <person id="1" name="joe"/>
        </referees>
        <referees>
        <person id="2" name="mary"/>
        </referees>
        </match>

        Note that this is not a complete solution. In particular, you wouldn't
        be able to handle XML of the following form:

        <match game="23">
        <referees>
        <person id="1" name="joe"/>
        <person id="3" name="john"/>
        </referees>
        <referees>
        <person id="2" name="mary"/>
        <person id="4" name="marianne"/>
        </referees>
        </match>

        This is because you would get four <referees> elements on retrieval and
        it would be impossible to tell how these were originally grouped
        together. However, since I'm assuming you have a single <referees>
        element inside a given <match> element, this won't be a problem.

        Furthermore, it won't work if the primary key in the relationship
        between matches and referees is in the referees table, as I would have
        expected. This is because the same situation will occur -- multiple
        children of the same class element type with the foreign key in the
        parent.

        THE DESIGN BUG
        ==============

        The XML you show is equivalent to the following classes:

        match referees person
        { { {
        int game; person[] persons; int id;
        referees refs; } String name;
        } }

        The problem comes in mapping the referees class to the database. If the
        PK is in the referees table, this is easy:

        referees (refereesPK)
        persons (id, name, refereesFK)

        If the FK is in the referees table, it's not so easy. There are two
        possibilities:

        referees(refereesPK, personID)
        persons(id, name)

        or:

        referees(refereesPK)
        referee_people(refereesPK, personID)
        persons(id, name)

        The first is probably what you want, but is non-normal in the general
        case. For example, imagine that <referees> had an attribute, such as
        skill_level. This would be repeated in each row of the referees table.

        I'm going to have to think about what the best solution is -- comments
        welcome.

        -- Ron


        Gary Lawrence Murphy wrote:
        >
        > I haven't found any example in the archives where ToPropertyTable is
        > used with an ElementType that is a class, and since the only option to
        > specify what happens to the ElementType is to specify a target
        > "column" (this "column" isn't described in the DTD; <PCDATA/> examples
        > in the product description example show 'column' as containing the
        > PropertyMap'd PCDATA, but that's the only reference I can find).
        >
        > Perhaps this is not possible with 1.0
        >
        > Here's the scenario:
        >
        > <match game="23">
        > <referees>
        > <person id="1" name="joe"/>
        > <person id="2" name="mary"/>
        > </referees>
        > </match>
        >
        > and I'd like this to create tupples
        >
        > REFEREES ( MATCHID = 23, PERSONID = 1 )
        >
        > or even
        >
        > REFEREES ( MATCHID = 23, PERSONID = 1, NAME = joe )
        >
        > but this did not seem possible because PropertyMap can only take
        > the PCDATA of a nested element; there's no syntax to map
        > child attributes to parent columns.
        >
        > I had originally tried
        >
        > <RelatedClass KeyInParentTable="Foreign">
        > <ElementType Name="person"/>
        > <CandidateKey Generate="No">
        > <Column Name="id"/>
        > </CandidateKey>
        > <ForeignKey>
        > <Column Name="personid"/>
        > </ForeignKey>
        > </RelatedClass>
        >
        > but, while the table looked promising (matchid, personid) for
        > reasons I don't quite understand this only records the last
        > person listed for the referees element.
        >
        > So I thought PropertyMap's ToPropertyTable might let me indirect:
        >
        > REFEREES ( MATCHID = 23, REFEREEFK = K1 )
        > REFEREES ( MATCHID = 23, REFEREEFK = K2 )
        >
        > REFEREE ( REFEREEPK = K1, PERSONID = "1" )
        > REFEREE ( REFEREEPK = K2, PERSONID = "2" )
        >
        > but here the examples showing ToPropertyTable only deal with <PCDATA/>
        > and do not define what happens if the PropertyMap is an ElementType
        >
        > Is there someplace where this case of ToPropertyTable is described?
        > Am I even headed in the right direction? ;)
        >
        > --
        > Gary Lawrence Murphy <garym@...> TeleDynamics Communications Inc
        > Business Innovations Through Open Source Systems: http://www.teledyn.com
        > "Computers are useless. They can only give you answers."(Pablo Picasso)
        >
        >
        > To post a message, send it to: xml-dbms@yahoogroups.com
        > To unsubscribe, send a blank message to: xml-dbms-unsubscribe@yahoogroups.com
        > Or join the newsgroup at: news://news.barkto.com/homeless.xml.xml-dbms
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

        --
        Ronald Bourret
        Programming, Writing, and Research
        XML, Databases, and Schemas
        http://www.rpbourret.com
      Your message has been successfully submitted and would be delivered to recipients shortly.