5 Replies Latest reply: Oct 22, 2010 4:57 AM by 802829 RSS

    Tree representation of objects

    802829
      Hello

      I need to return back a collection of objects from the database to my jsp, to be represented in a tree structure. I need to represent my objects in a tree structure so that it can be passed back from my server to the client.

      Any idea how to represent this? I thought of using LinkedList, but I understand that it cannot be used since a node in the tree can have many childs directly under it.

      I am thinking of representing this using a TreeMap, but not sure whether it is the best approach. Can you please help me out?

      Best Regards
      peduser
        • 1. Re: Tree representation of objects
          796262
          peduser wrote:
          Any idea how to represent this? I thought of using LinkedList, but I understand that it cannot be used since a node in the tree can have many childs directly under it.
          Why is that a problem?
          I am thinking of representing this using a TreeMap, but not sure whether it is the best approach. Can you please help me out?
          What happened when you tried it that way? Did you experience any problems?

          See the API for TreeMap and TreeSet, try one out, and see if you experience any problems.

          Link to the API because the link tag seems to be horribly broken: http://download-llnw.oracle.com/javase/6/docs/api/
          • 2. Re: Tree representation of objects
            791266
            peduser wrote:
            Hello

            I need to return back a collection of objects from the database to my jsp, to be represented in a tree structure. I need to represent my objects in a tree structure so that it can be passed back from my server to the client.

            Any idea how to represent this? I thought of using LinkedList, but I understand that it cannot be used since a node in the tree can have many childs directly under it.
            I don't know what database you have, and what support it has for trees and xml. Some databases can represent trees in the database, and you should then be able to return that as xml, and just transform it into e.g. html using xslt.
            • 3. Re: Tree representation of objects
              802829
              Hi Kaj

              THanks for the information. I am using Oracle DB and i can directly store an xml file as a Blob in the DB. I am afraid whether it will create any performance issues.

              Edited by: peduser on Oct 7, 2010 2:42 AM
              • 4. Re: Tree representation of objects
                DrClap
                Then that's not a question about Java collections any more. It's a question about your Oracle database and your performance requirements. You probably don't know anything about the latter so your best approach would be to try it and see. Use data of the same size you expect to have in real life.
                • 5. Re: Tree representation of objects
                  802829
                  Thank you very much Kaj. I did exactly the same thing and it worked.

                  I have represented the tree data as flat records in the DB, retrieved it as an xml using the Oracle XML package APIs and rendered it on the html.

                  Best Regards
                  peduser