4 Replies Latest reply on May 11, 2002 8:20 PM by shs96c

    Listing Records in Order

    david_cohoon

      My web application pulls a collection of value objects from stateless session beans. I need to sort these objects by different values.

      Should I create different finder methods in the ejb tier, or should I sort them within the presentation (jsp) tier.

      Has anyone had to do something like this?

        • 1. Re: Listing Records in Order
          shs96c

          Why not create the value objects using JDBC? You can then use normal SQL and order things appropriately using the database.

          Assuming that you're in the situation where you have lots of reads, and few writes this should be pretty fast, and when you need to write, use a finder to get the EJB that you'll be modifying.

          • 2. Re: Listing Records in Order
            sgturner

            If you are using 3.0, you can use JbossQL which is an extension of Ejb-QL. JBossQL lets you have order by clauses in the expected way. "select object(o) from blah order o.foo". If you are working in 2.4.x, the question becomes one of scalability. If there are only a few different order by clauses, put in finder methods. If there are a lot of order by possibilities, I would manually sort them, but not in the presentation layer, sort them in the session bean layer.

            • 3. Re: Listing Records in Order
              timdeboer

              If you're planning to sort on the client side just remember that there may come a time when you want to chunk your returned collections. There is no elegant way of doing this that i have found to date without first ordering on the database (at least with oracle there is not.. If anybody would like to challenge this i look forward to your contributions!)

              As a result, you'll end up querying the following data:

              0,1,2,3,4,5,6,7,8,9

              and getting back the following 2 pages:

              page 1: 1,3,4,5,7
              page 2: 0,2,6,8,9

              Tears well up just thinking about it ;)




              • 4. Re: Listing Records in Order
                crackers

                You can also make your objects implement the Comparable interface and put them into a TreeSet - viola! Instant sort.