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

Object Relational Mapping

Expand Messages
  • Tai Tran
    Hi, I am having some problems understanding the concept of Object Relational Mapping, could you please clarify my understanding? Here are my problems: I don t
    Message 1 of 6 , Aug 1 6:23 AM
    • 0 Attachment
      Hi,

      I am having some problems understanding the concept of
      Object Relational Mapping, could you please clarify my
      understanding?

      Here are my problems:

      I don't understand why you need the DTD to
      interchanging data between DBMS using XML (using the
      Object Relational Mapping concept)?

      How does the DTD involve and what is it purpose when
      transfering the XML?

      How can a program grab the information from the DB by
      querying the DTD? Does the program need to go into the
      DTD file and get all the element names, attributes,
      etc... then the program start querying the DB and
      append the results to the XML file? If this is the
      case, why do we need to do all the troubles by
      creating the DTD, create the classes and so on? Why
      don't we just query the DB and append the results
      straight into the XMl file?

      Please help me to understand these issues as I am
      currently doing a project about XML and DB.

      Thank you for all the useful information that you
      provided.

      Regards,
      Tai
      txtran2001@...

      __________________________________________________
      Do You Yahoo!?
      Make international calls for as low as $.04/minute with Yahoo! Messenger
      http://phonecard.yahoo.com/
    • Ronald Bourret
      ... You don t need a DTD when you actually transfer data. You effectively need a DTD when you map an XML document to the database. This is because the mapping
      Message 2 of 6 , Aug 1 5:37 PM
      • 0 Attachment
        Tai Tran wrote:
        > I don't understand why you need the DTD to
        > interchanging data between DBMS using XML (using the
        > Object Relational Mapping concept)?

        You don't need a DTD when you actually transfer data.

        You effectively need a DTD when you map an XML document to the database.
        This is because the mapping is done at the meta-data level. For example,
        element type <foo> is mapped to table Foo and the attributes of <foo>
        are mapped to columns of that table.

        For this mapping to work, an XML document must have a predictable
        structure. That is, a given element type or attribute must always follow
        a specific content model. Otherwise, it would be impossible to define a
        mapping. Thus, it must be possible to define a DTD (schema) for the
        document, even if one doesn't exist.

        In XML-DBMS, there is no requirement that you have a DTD. That is, you
        can define a mapping from the elements and attributes in an XML document
        to the tables and columns in the database without a DTD ever existing.
        However, it is always possible to infer a DTD from the mapping.

        XML-DBMS also offers a tool to automatically generate a mapping from a
        DTD. You are not required to use this tool -- you can also write your
        mapping by hand.

        > How does the DTD involve and what is it purpose when
        > transfering the XML?

        It isn't used.

        > How can a program grab the information from the DB by
        > querying the DTD?

        In the general case, it can't. The only time this would be possible
        would be when the names and structures in the DTD happened to correspond
        to the names and structures in the database.

        In other words, starting from a DTD, you can predict a set of database
        structures and a mapping from the DTD to those structures. The reverse
        is also true: starting from a set of database structures, you can
        predict a DTD and a mapping from the database structures to that DTD.
        However, given both a DTD and a set of database structures, you can't
        predict a mapping between the two.

        > Does the program need to go into the
        > DTD file and get all the element names, attributes,
        > etc... then the program start querying the DB and
        > append the results to the XML file?

        XML-DBMS doesn't use the DTD in this way. Instead, it uses a mapping
        file, which maps a DTD to a database (and vice versa). When it transfers
        data from the database to XML, the process is roughly:

        1) Create a result set over a table.

        2) Get the element type corresponding to the table from the map.

        3) Process the rows in the table. For each row in the table:

        a) Create a element for the row.
        b) Create child elements/attributes/PCDATA for each column in the row
        according to the map.
        c) Look at the map and find if there are any child tables. If so, go
        back to step 1 for each child table.

        To transfer data from XML to the database, starting with the root
        element:

        1) Find the table corresponding to the element from the map. Create a
        row buffer for the table.

        2) Look at the child elements, attributes, and PCDATA. For elements,
        attributes, and PCDATA mapped to columns, place their data in the
        buffer, then insert the row. For child elements mapped to child tables,
        repeat step 1.

        > If this is the
        > case, why do we need to do all the troubles by
        > creating the DTD, create the classes and so on? Why
        > don't we just query the DB and append the results
        > straight into the XMl file?

        I think this is answered by the above. You need to create a mapping from
        the DTD to the database.

        -- Ron
      • Tai Tran
        If possible, could you please explain in details how does XML-DBMS maps a DTD to a database and vice versa? To be more specific, how does XML-DBMS get the
        Message 3 of 6 , Aug 2 5:45 AM
        • 0 Attachment
          If possible, could you please explain in details how
          does XML-DBMS maps a DTD to a database and vice versa?
          To be more specific, how does XML-DBMS get the element
          type corresponding to the table from the map? And how
          does it look at the map and find if there are any
          child tables? Could you please indicate which file of
          XML-DBMS does the mapping?

          Does XML-DBMS ever go into the DTD file?

          So the purpose of a DTD is for developer to understand
          the database structures, is this right? Please correct
          me if I am wrong.

          Tai

          --- Ronald Bourret <rpbourret@...> wrote:
          > Tai Tran wrote:
          > > I don't understand why you need the DTD to
          > > interchanging data between DBMS using XML (using
          > the
          > > Object Relational Mapping concept)?
          >
          > You don't need a DTD when you actually transfer
          > data.
          >
          > You effectively need a DTD when you map an XML
          > document to the database.
          > This is because the mapping is done at the meta-data
          > level. For example,
          > element type <foo> is mapped to table Foo and the
          > attributes of <foo>
          > are mapped to columns of that table.
          >
          > For this mapping to work, an XML document must have
          > a predictable
          > structure. That is, a given element type or
          > attribute must always follow
          > a specific content model. Otherwise, it would be
          > impossible to define a
          > mapping. Thus, it must be possible to define a DTD
          > (schema) for the
          > document, even if one doesn't exist.
          >
          > In XML-DBMS, there is no requirement that you have a
          > DTD. That is, you
          > can define a mapping from the elements and
          > attributes in an XML document
          > to the tables and columns in the database without a
          > DTD ever existing.
          > However, it is always possible to infer a DTD from
          > the mapping.
          >
          > XML-DBMS also offers a tool to automatically
          > generate a mapping from a
          > DTD. You are not required to use this tool -- you
          > can also write your
          > mapping by hand.
          >
          > > How does the DTD involve and what is it purpose
          > when
          > > transfering the XML?
          >
          > It isn't used.
          >
          > > How can a program grab the information from the DB
          > by
          > > querying the DTD?
          >
          > In the general case, it can't. The only time this
          > would be possible
          > would be when the names and structures in the DTD
          > happened to correspond
          > to the names and structures in the database.
          >
          > In other words, starting from a DTD, you can predict
          > a set of database
          > structures and a mapping from the DTD to those
          > structures. The reverse
          > is also true: starting from a set of database
          > structures, you can
          > predict a DTD and a mapping from the database
          > structures to that DTD.
          > However, given both a DTD and a set of database
          > structures, you can't
          > predict a mapping between the two.
          >
          > > Does the program need to go into the
          > > DTD file and get all the element names,
          > attributes,
          > > etc... then the program start querying the DB and
          > > append the results to the XML file?
          >
          > XML-DBMS doesn't use the DTD in this way. Instead,
          > it uses a mapping
          > file, which maps a DTD to a database (and vice
          > versa). When it transfers
          > data from the database to XML, the process is
          > roughly:
          >
          > 1) Create a result set over a table.
          >
          > 2) Get the element type corresponding to the table
          > from the map.
          >
          > 3) Process the rows in the table. For each row in
          > the table:
          >
          > a) Create a element for the row.
          > b) Create child elements/attributes/PCDATA for each
          > column in the row
          > according to the map.
          > c) Look at the map and find if there are any child
          > tables. If so, go
          > back to step 1 for each child table.
          >
          > To transfer data from XML to the database, starting
          > with the root
          > element:
          >
          > 1) Find the table corresponding to the element from
          > the map. Create a
          > row buffer for the table.
          >
          > 2) Look at the child elements, attributes, and
          > PCDATA. For elements,
          > attributes, and PCDATA mapped to columns, place
          > their data in the
          > buffer, then insert the row. For child elements
          > mapped to child tables,
          > repeat step 1.
          >
          > > If this is the
          > > case, why do we need to do all the troubles by
          > > creating the DTD, create the classes and so on?
          > Why
          > > don't we just query the DB and append the results
          > > straight into the XMl file?
          >
          > I think this is answered by the above. You need to
          > create a mapping from
          > the DTD to the database.
          >
          > -- Ron
          >


          __________________________________________________
          Do You Yahoo!?
          Make international calls for as low as $.04/minute with Yahoo! Messenger
          http://phonecard.yahoo.com/
        • Ronald Bourret
          ... There are really three questions here. Q1) How does XML-DBMS generate a map from a DTD? A1) See the algorithm in section 4.1 of
          Message 4 of 6 , Aug 3 12:57 AM
          • 0 Attachment
            Tai Tran wrote:
            >
            > If possible, could you please explain in details how
            > does XML-DBMS maps a DTD to a database and vice versa?

            There are really three questions here.

            Q1) How does XML-DBMS generate a map from a DTD?
            A1) See the algorithm in section 4.1 of
            http://www.xml.com/pub/a/2001/05/09/dtdtodbs.html. Since the algorithm
            generates a relational schema from a DTD, it can also generate a map at
            the same time. This is implemented in MapFactory_DTD, which is called by
            the GenerateMap sample.

            Q2) How does XML-DBMS generate a map from a relational schema?
            A2) This is not implemented in XML-DBMS v.1.01. It will probably be
            implemented in version 2.0. You can find the algorithm in section 4.2 of
            the above paper.

            Q3) What does an XML-DBMS map look like?
            A3) Internally, it is a set of map objects. For a list of these objects,
            see section 6.5 of the readme file. These classes are essentially a set
            of objects created from a map document, so the easiest way to understand
            them is to read the mapping language DTD (xmldbms.dtd).

            > To be more specific, how does XML-DBMS get the element
            > type corresponding to the table from the map?

            The application creates a Map object. Usually, it does this by passing a
            map document to MapFactory_MapDocument. It passes the Map object to a
            transfer class (DOMToDBMS or DBMSToDOM). The transfer class calls a
            method on the Map object or one of its child objects to get the map. The
            most commonly used methods are:

            Map.getRootClassMap(elementName)
            Map.getRootTableMap(tableName)
            ClassMap.attributeMaps.get(name)
            ClassMap.subElementTypeMaps.get(name)
            TableMap.columnMaps (an array)

            > And how
            > does it look at the map and find if there are any
            > child tables?

            It gets the TableMap for the root table, then looks at the following
            fields (parallel arrays) in TableMap:

            relatedTables
            parentKeys
            childKeys
            parentKeyIsCandidate
            orderColumns

            > Could you please indicate which file of
            > XML-DBMS does the mapping?

            Mappings are usually built by hand. MapFactory_MapDocument compiles a
            map document into map objects. MapFactory_DTD creates a map document
            from a DTD. the map objects are listed in section 6.5 of the readme
            file.

            > Does XML-DBMS ever go into the DTD file?

            Not when transferring data. Only if you choose to create a map document
            from a DTD. You are not required to do this.

            > So the purpose of a DTD is for developer to understand
            > the database structures, is this right?

            Close. The purpose of a DTD is for the developer to understand the XML
            structures. These must correspond to the database structures, so the DTD
            does help the developer understand the database structures.

            -- Ron
          • Tai Tran
            Hi, If I would like to query the DTD to grab data from the database, how would this be possible? Note that the names and structures in the DTD correspond to
            Message 5 of 6 , Aug 5 5:41 PM
            • 0 Attachment
              Hi,

              If I would like to query the DTD to grab data from the
              database, how would this be possible? Note that the
              names and structures in the DTD correspond to the
              names and structures in the database.

              Is there any interface that allow me to access the DTD
              just like DOM/SAX for XML?

              Do you have any algorithm for this concept?

              Regards,
              Tai

              --- Ronald Bourret <rpbourret@...> wrote:
              > Tai Tran wrote:
              > >
              > > If possible, could you please explain in details
              > how
              > > does XML-DBMS maps a DTD to a database and vice
              > versa?
              >
              > There are really three questions here.
              >
              > Q1) How does XML-DBMS generate a map from a DTD?
              > A1) See the algorithm in section 4.1 of
              > http://www.xml.com/pub/a/2001/05/09/dtdtodbs.html.
              > Since the algorithm
              > generates a relational schema from a DTD, it can
              > also generate a map at
              > the same time. This is implemented in
              > MapFactory_DTD, which is called by
              > the GenerateMap sample.
              >
              > Q2) How does XML-DBMS generate a map from a
              > relational schema?
              > A2) This is not implemented in XML-DBMS v.1.01. It
              > will probably be
              > implemented in version 2.0. You can find the
              > algorithm in section 4.2 of
              > the above paper.
              >
              > Q3) What does an XML-DBMS map look like?
              > A3) Internally, it is a set of map objects. For a
              > list of these objects,
              > see section 6.5 of the readme file. These classes
              > are essentially a set
              > of objects created from a map document, so the
              > easiest way to understand
              > them is to read the mapping language DTD
              > (xmldbms.dtd).
              >
              > > To be more specific, how does XML-DBMS get the
              > element
              > > type corresponding to the table from the map?
              >
              > The application creates a Map object. Usually, it
              > does this by passing a
              > map document to MapFactory_MapDocument. It passes
              > the Map object to a
              > transfer class (DOMToDBMS or DBMSToDOM). The
              > transfer class calls a
              > method on the Map object or one of its child objects
              > to get the map. The
              > most commonly used methods are:
              >
              > Map.getRootClassMap(elementName)
              > Map.getRootTableMap(tableName)
              > ClassMap.attributeMaps.get(name)
              > ClassMap.subElementTypeMaps.get(name)
              > TableMap.columnMaps (an array)
              >
              > > And how
              > > does it look at the map and find if there are any
              > > child tables?
              >
              > It gets the TableMap for the root table, then looks
              > at the following
              > fields (parallel arrays) in TableMap:
              >
              > relatedTables
              > parentKeys
              > childKeys
              > parentKeyIsCandidate
              > orderColumns
              >
              > > Could you please indicate which file of
              > > XML-DBMS does the mapping?
              >
              > Mappings are usually built by hand.
              > MapFactory_MapDocument compiles a
              > map document into map objects. MapFactory_DTD
              > creates a map document
              > from a DTD. the map objects are listed in section
              > 6.5 of the readme
              > file.
              >
              > > Does XML-DBMS ever go into the DTD file?
              >
              > Not when transferring data. Only if you choose to
              > create a map document
              > from a DTD. You are not required to do this.
              >
              > > So the purpose of a DTD is for developer to
              > understand
              > > the database structures, is this right?
              >
              > Close. The purpose of a DTD is for the developer to
              > understand the XML
              > structures. These must correspond to the database
              > structures, so the DTD
              > does help the developer understand the database
              > structures.
              >
              > -- Ron
              >


              __________________________________________________
              Do You Yahoo!?
              Make international calls for as low as $.04/minute with Yahoo! Messenger
              http://phonecard.yahoo.com/
            • Ronald Bourret
              ... I assume what you mean is that you want to look at the DTD, then build a query based on the DTD. Is that correct? If so, XML-DBMS does not support this.
              Message 6 of 6 , Aug 6 11:15 PM
              • 0 Attachment
                Tai Tran wrote:
                >
                > If I would like to query the DTD to grab data from the
                > database, how would this be possible? Note that the
                > names and structures in the DTD correspond to the
                > names and structures in the database.
                >
                > Is there any interface that allow me to access the DTD
                > just like DOM/SAX for XML?
                >
                > Do you have any algorithm for this concept?

                I assume what you mean is that you want to look at the DTD, then build a
                query based on the DTD. Is that correct? If so, XML-DBMS does not
                support this.

                However, if you want to build this functionality on top of XML-DBMS, you
                can probably do so as follows:

                1) Use de.tudarmstadt.ito.schemas.converters.SubsetToDTD to parse a DTD
                and return a de.tudarmstadt.ito.schemas.dtd.DTD object.

                2) Explore the DTD object to find what you want to query on.

                3) If you are querying on key fields (you won't be able to determine
                which fields are key fields from the DTD), call
                DBMSToDOM.retrieveDocument(tableName, key). If you are not querying on
                key fields, build a SELECT statement, execute it, and pass the result
                set to DBMSToDOM.retrieveDocument(resultSet).

                If you use DBMSToDOM.retrieveDocument(resultSet), you need to use a
                special map that maps the result set to XML. For more information, see
                section 7.2 of the readme file. If you are doing all of this at run
                time, this would probably require you build the map at run time, which
                would be a non-trivial thing to do, although you might be able to modify
                MapFactory_DTD to do this.

                I suspect what you really want is an XPath implementation in XML-DBMS,
                so you can explore the DTD and build XPath queries at run time.
                Unfortunately, XML-DBMS does not support XPath and isn't likely to do so
                any time soon.

                -- Ron
              Your message has been successfully submitted and would be delivered to recipients shortly.