4 Replies Latest reply on Aug 17, 2011 8:21 AM by calebwc

    How do I cast to a super class type in Teiid

    calebwc

      Hi again,

         I have a Teiid view model mapped from an XML schema and am running into an issue when I pull results out of the mapped Teiid XML document.  I am utilizing JAX-B to marshal and unmarshal objects in my application.  One of the objects that I created stores a list of a "base type" (kind of like a shopping cart.)  The base type is defined in the XSD as "abstract" which carries over to the generated Java class.  What I am doing is returning the objects from Teiid (the items in the cart) and adding them in the "cart" element XML.  Doing this does not work from a JAX-B perspective because the element returned is the implementation class (i.e. CompactDisc or T-Shirt, etc...) and not the abstract base "item" class which is what is needed.  This would force me to unmarshal each implementation object one-by-one returned from the Teiid call and then add it to the shopping cart Java object and marshal the shopping cart after adding all necessary items.  The resulting XML that is created is in essence the same as what comes from Teiid with one major difference, the element is declared as the base item with an "xsi:type" declaring the implementation class (as defined in the XML spec.)  The result looks something like "<item xsi:type="electronics:compactDisc" ...>". 

       

          O.k., so now for my question I can see where I am able to specify the XSD component after mapping a concrete/implementation type and it comes back as the base item, however, it does not include the very important "xsi:type" to identify its specific type.  Is there a way to properly handle casting to a super type which would include this "xsi:type" tag?

       

           I did see a JIRA relating to xsi:type, however, it indicated having a similar interface to "choice" which I don't think is necessary in this scenario since we already know the specific type we are just simply returning a super type and need it to follow the XML spec which would be to include the xsi:type tag.

           Thanks for your time any guidance would be greatly appreciated.  Take care.

       

      Regards,

          Caleb

        • 1. Re: How do I cast to a super class type in Teiid
          shawkins

          Hi Caleb,

           

          Did you try adding an xsi:type attribute to the document model? 

           

          I think what https://issues.jboss.org/browse/TEIIDDES-306 is getting at is that designer should at least be automatically adding the type attribute in this situation.  Using something like choice criteria is just one way of defining what concrete type value should be.  I think you should just as easily be able to set the value as fixed on the document model or even to a value from a mapping class.

           

          Steve

          • 2. Re: How do I cast to a super class type in Teiid
            calebwc

            Hi Steve,

                Thanks for your repsonse.  I have not tried to add xsi:type to the document model, and will do so some time today. 

                 One thing that I've noticed is that mapping the XML Schema to a model, the retrieval while iterating over the returned db cursors seems very slow even though the query executes very fast.  For example, pulling 1,000 records from the XML Mapped view/document takes on average 40 seconds, where as if I simply did a direct JDBC call to the data sources, retrieved all the information, populated my Java objects, then marshalled them to XML it took an average of 6 seconds.  I'm not sure what part is slowing it down (if it is the XML transformation, or other queries going on behind the scenes that are fired only when it gets to the cursor, etc...) but it is substantial performance hit.

                 The one thing that I absolutely love about the XML model mapping is that I can query on any part of the XML Schema element which simplifies things substantially for us since we have a lot of custom elements that may be lists within our primary (mapped) element.  Are you aware of any performance issues utilizing the XML mapped model?  Is there a way to utilize Teiid that will do the abstraction that currently occurrs with the XML model (i.e. determine the queries that need to occur first in order to then fulfil the primary queries that need to take place in order to populate the "primary" object) without utilizing the XML transformation?  I am not sure if this will make any difference, however, I would like to try it because we can't ask our customers to wait for more than 30 seconds in order to bring back only 1,000 rows of data.  Any assistance or guidance is GREATLY appreciated.  Thanks again for all your help and the outstanding work that you have put into Teiid!

             

              Caleb

            • 3. Re: How do I cast to a super class type in Teiid
              shawkins

              Caleb,

               

              What Teiid verion are you using?  How nested is your document model?  If you have several levels of mapping classes and/or sibling mapping classes, performance should improve with using 7.5 CR1.  If not, then I'd have to know more about the document structure, mapping class queries, and what is backing them to make better suggestions.

               

              Steve

              • 4. Re: How do I cast to a super class type in Teiid
                calebwc

                Hi Steve,

                   I'm currently using Teiid 7.4 (CR1.)  I will grab the 7.5 code base soon and try again to see how performant it is.

                 

                    As for the mappings, currently there are about 5 sibling mapping classes.  The primary mapping class maps to roughly 6 tables, the secondaries map to 1 or 2.  The secondaries utilize the primaries ID to filter to the correct data.  As a test, I thought I would remove all the secondary sibling mapping classes (not changing the XSD) and see how fast the response was.  Surprisingly it seemed to slow down the process.  I'm not sure if that was due to not changing the XSD?  Thanks again for your assistance.  I will let you know when I try out the 7.5 baseline.  Take care.

                    Caleb