What's the best way to sort query results?

Hello All,
I have a standard CRUD UI that now needs the results sorted, based on input from the UI. What's the best way to sort results by entity fields?
I'm familiar with the conventional Java methodology using a TreeSet and comparator. Is this the best route, does BDB JE offer more convenient or performant alternatives?
I looked through the documentation and saw how to change the indexes, but I'm just looking to change the order in the scope of the query.
If my application were an address book, the UI would be sortable, ascending and descending, by date added, first name, last name, etc. based on which column the user clicked on.
Thanks in advance,
Steven
Harvard Children's Hospital Informatics Program

Hi Steven,
Using standard Java collections is probably the best approach.
One thing that may be useful is to get a SortedMap (Primary or SecondaryIndex.sortedMap) for the case where you have an index sorted the way you want, and then copy the primary index into a TreeMap (with a comparator) for other cases. That way, you always have a SortedMap to work with, whether you're copying the index or not.
I haven't tried this myself, just a thought.
--mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • What is the best way to output query result in jsp page?

    I have several pages with 2-3 queries on each one.
    My jsp pages call a class that I've created, the class will create a connection with the db, execute the query and returns the ResultSet to the jsp page. Then I iterate the RS on the jsp page.
    Is there a better way of sending the data back to the jsp? I was thinking of .xml.

    Send it back as a java.util.List, or some other Collection. Then iterate through the collection. My preference is to make a Bean of the date that represents a Row on the ResultSet and put those in the List. Then when we get to the JSP, iterate the List to get the beans, and call get methods to get the values...
      /* In a method that traverses ResultSet and fills a List of  beans... */
      List data = new ArrayList();
      while(results.next())
        MyBean mb = new MyBean();
        mb.setProperty1(rs.getString(1)); //But give properties good names
        mb.setProperty2(rs.getString(2)); //Not 'Property1 and Property2
        data.add(mb);
      return data;If you are using JSTL you can do something like this:
      <c:set var="myBeans" value="${theDbObject.results}"/> //Assuming the above method was called 'getResults()'
      <table>
      <c:forEach var="mb" items="${myBeans}">
        <tr><td>${mb.property1}</td><td>${mb.property2}</td>...</tr>
      </c:forEach>
      </table>

  • What is the best way to sort an XML document in WLI 8.1?

    I have the schema for the XML and I want to sort the data. What is the best way to do this?

    I'm not sure if you want the result of the sorting to be a sorted XML document or a sorted object tree but anyway both XSLT and XQuery support sorting so you could use a Transformation control to execute an XQuery or XSLT transformation to sort the data. Another option (if you are not comfortable writing XQuery or XSLT) would be to use XmlBeans and programmatically sort the data. A word of warning though, these processes are quite memory intensive and if the XML document you are sorting is large (say over 10 MB) your server might run out of memory. In this case you might be better of just parsing the document with SAX and then sorting the result objects.

  • What is the best way for sorting?

    Hi i have 1000 customers in the database. I need to display them in the combo box. combox is editable. As the user types the letters i need to filter and display the customer names. for example if the user types 'a' in the combox i have to display all the customer names that starts with 'a'. if the customer types 'as' then i have to display only names that start with 'as' in the combo box popup. for every key stroke i have to filter and display the customer names.
    for this there are two approaches:-
    1. for every key stroke go to database and retrieve the sorted results and display them. In this way sorting happens in the database.
    2. pull all the customers into java once, cash them and sort them accordingly based on the key strokes. In this sorting happens in our java code.
    few friends said that going to databse for every key stroke is expensive. I feel pulling all the customers at once and cashing them in java is not a good idea.
    I am really confused. I need an expert suggestion. which way is best? why is it the best way? what are the pros and cons in both the ways. please help me.
    Thanks in advance.

    Thanks ejp but initially if the combo box is not empty. that means if he did not typed any letter i will be displaying all the names.No. That's the mistake. Don't do that. A combobox with 1000 or 5000 items is completely useless.Do it the way I said.
    My problem is if there are 5000 customers then what? will it not create a performance issue.Of course it will. It will also create a major performance issue for the user.
    However you seem to have missed something else. By populating the combobox with anything, you are already running a cache. No two ways about it, and no way to avoid it. So whatever you populate it with, and whenever you do it, all you have to do when the user types another keystroke is filter the combobox model to exclude everything that doesn't match the prefix he has typed. The issue of going back to the database doesn't even arise.

  • What's the easiest way to show query results?

    I have a button on the Business Partner form, and I want to show the results of a query when you push it.  What's the easiest way to show this data to the user?
    Am I going to have to create a new form and add a matrix to it?  There has to be an easier way.

    Hi Bryan,
    If the query is without parameter, you can activate the menu for this query, else I think the best way is a new form with a grid (much faster than matrix).
    Regards
    Ad

  • What is the best way to sort and separate tv show episodes

    Hi Everyone,
    I have some tv shows converted for my apple tv but they go over a period of several  seasons, how can I merge and separate them by season year  and  have them in itunes as each season  with  only those shows for that season ..  any tips and hints   all help is appreciated thanks

    Use -> MetaZ to tag the files by title, season and episode (and other info).

  • What is the best way to scan and sort old photos in iPhoto

    What is the best way to scan and sort old photos in iPhoto?  They do not have digital dates.

    Hey Chicago Sue,
    Once you scan them and have them on your desktop. You should use Automator and assign the common IPTC tags to the images, so that when you do import them into iPhoto, they get recorded.
    Here is an example of an action in Automator:

  • What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

    What is the best way to query planned orders or work orders for make items and identify the buy component that is short for supply and vice versa?

  • What is the best way to Optimize a SQL query : call a function or do a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement or do a simple join?

    Hi,
    If you're even considering a join, then it will probably be faster.  As Justin said, it depends on lots of factors.
    A user-defined function is only necessary when you can't figure out how to do something in pure SQL, using joins and built-in functions.
    You might choose to have a user-defined function even though you could get the same result with a join.  That is, you realize that the function is slow, but you believe that the convenience of using a function is more important than better performance in that particular case.

  • I am trying to rebuild my iPhoto library and noticed my backup contains aliases (pointers?) and not the actual file. What's the best way to rebuild my library?

    I am trying to rebuild my iPhoto library and noticed my backup contains aliases (pointers?) and not the actual file. What's the best way to rebuild my library?
    Facts:
    In moving to a new iMac, I copied the iPhoto library to an external HDD assuming that I would point the new iMac to the backed up iPhoto Library
    All worked fine when I pointed the new library but noticed that some folders contained aliases and not the original file. So when I attempt to open that photo it can't find it because the alias is pointing to another drive.
    I do have all original photos from a couple of external HDDs. In the folders titled, "Originals" (from older versions of iPhoto) and "Masters" (from current iPhoto)
    I'm thinking I can create a new folder and drop the original files and make that my new iPhoto library. Is there a better way to rebuild my library? I do not want to create any future aliases.
    Thanks in advance for any help!

    do you have a strongly recommended default "managed" library (the iPhoto preference to "copy imported items to the iPhoto library is in its checked state) or a referenced library - you have unchecked that option?
    It sounds like you have a referenced library and are now experiancing one of the very siginificant drawbacks of a referenced library and one of the many reasons they are strongly not recommended
    Also note that iPhoto '11 may use alises in the originals folder as part of the upgrade
    It is important that we understand exactly what you have and what is not sorking - what error messages you are getting
    You must NEVER make any changes of any sort to the structure of content of the iPhoto library - there are no user servicable parts in it  --  and you can not rebuild yoru librtary - only iPhoto ir iPhoto Library Manager - http://www.fatcatsoftware.com/iplm/ -  can rebuild a library unless you are a SQL programmer and understand the structure that iPhoto uses
    LN

  • What is the best way to share a iTunes library between 5 users on the same computer?

    What is the best way to share a iTunes library between 5 users on the same computer?
    Currently I have a common itunes library in a shared folder that each user is linked to.  The problem is that when one user adds music to the shared file, it does not automaticaly appear to other users when they open their iTunes.  They have to go to the shared library and select the new music in order to make it visable in their iTunes.
    Would iTunes file shareing fix this problem?
    Thanks

    aapl.up wrote:
    Rick, are you saying that if you try to share a folder outside of home and use sharepoints, then the other mac wont prompt you to log in? Have you tried that? It is hard to believe that is the case
    I am sort of saying that. Have you tried it? I know it's hard to believe, but you really need to help us out by trying some steps that you don't believe.
    We can't see what your exact situation is. We sort of know what's worked for us out here. Just trying to help you get this going in less than 24 hours!
    Sharepoints manages the samba configuration file. It's free software that puts a pretty face on an otherwise cumbersome config file.
    Give it a shot.
    windows will not prompt for passwords, I have tried this with multiple computer at home for both vista and xp
    As I stated. You will not get prompted on windows, if you have set up sharing in an insecure fashion. You are not using a secured sharing situation.
    No argument with your statement.

  • What is the best way to protect it?

    I HATE getting scratches or any sort of cosmetical damage on my devices, I am getting my first MBP on Friday, and want to know what the best way to keep it like new is?
    It won't be leaving the house regularly for a while, but I do have a neoprene case which I think it will fit for travelling anyway.
    I have seen many people with cases on their Macs, I don't know what the proper name is for them, but they are like hard shells attached to the back of the lid, are these recommended? I have read about some heat issues with it.
    What is the best way to protect the screen? I don't ever touch it, so I don't think that will be a problem, but cleaning dust off etc.?
    Lastly, will the trackpad wear away? My laptop's trackpad has slightly faded from it being used a lot, are MBP's prone to this too? I will try to use a mouse as much as possible.
    Are there any other things I should know about? I read that the bottom can get scratched easily too? I would only use it on a flat surface, so something like my lap, so depending on how soft the metal is... It can't be that bad can it?
    Thanks!

    Wouldnt buy that, nope
    Hard cases protect the finish of your macbook, but they trap in heat, ....many here have spoken on same.
    A major part of a macbook pro, especially a RETINA PRO is dissipating heat from the alloy case, which this case prevents from happening.
    Yes, youre stopping all the scratch,.....and likewise keeping the Macbook from dissipating a lot of heat.
    When I said INCASE, I meant this:
    http://www.amazon.com/Incase-CL57482-Nylon-Sleeve-13-Inch/dp/B0043NTOKC/ref=sr_1 _1?ie=UTF8&qid=1382551803&sr=8-1&keywords=incase+carry

  • What is the best way to use a SSD for Photoshop/photo editing?

    Computer hardware newbie here: I do a significant amount of photo editing work and for a very long time I've experienced Photoshop, Bridge and Photomatix crashing constantly (usually due to insufficient RAM) or just generally taking forever (Bridge took forever to load the thumbnail/preview extractions in a folder full of images, Photoshop took forever to save images and Photomatix took ages to load/merge a set of bracketed photos).  Here are the typical error messages I'd get: http://pastebin.com/J9byczse
    As a professional photographer, constantly running into that sort of thing is quite aggravating, so to hopefully avoid ever having to deal with that again I invested in a new custom built computer.  It's Windows 7 Professional 64 bit with 32GB of RAM and a 240GB SSD; I'm using the 240GB SSD as my boot drive/OS, all of my programs are installed there, and the page file.  My photos and data are stored on several HDDs.  I have yet to install any of my photo editing software (Photoshop CS6 Extended, Lightroom, Photomatix etc) to the new computer yet since I'd like some advice first.
    My basic question is this: what is the best way to take advantage of the SSD (and the computer in general) when it comes to my photo editing software?
    Specifically...
    1. If I have a folder of photos I'm working on, should I move it to the SSD and then work on them from there in order to take advantage of the speed of the SSD?  Would this make any difference in terms of speed if the photos are located on the SSD vs. an internal/external HDD?
    2. Most of what I've read online seems to recommend two separate SSDs, one for installing/booting the apps and one for cache/scratch.  Does it matter if I use my 240GB SSD for both?
    3. This is a fairly new computer and the SSD is already almost half full (102GB used, 120GB free) *WITHOUT* any of my photo editing software installed yet.  I'm concerned about how fast that remaining 120 GB may fill up.  As it fills up will I lose the speed advantage of the SSD vs. a regular HDD?
    4. Sort of similar to #3, but should I bother moving any of my other non-photo editing programs/caches off of the SSD to a HDD and would there be any major difference in the speed/lifespan of the SSD if I did so?  It's mostly Firefox and Chrome and their caches that I'm concerned may be a problem if they remain on the SSD.
    Thanks for any help!

    If you have an SSD you can run the cache and programs on the same drive.  However, many recommend a scratch disk size of 100-200 gigs so that will not work here unless you opt for a larger SSD.  Otherwise an internal spinner is recommended that does not contain the program files, or idealy any other files that may want to get acessed at same time (only one read/write head per drive).
    With 32 gig of RAM you may not need the constant use of the scratch drive unless working on large images with lots of layers.  So see no advantage to moving folder to SSD for temp work environment.
    From what I read the new crop of SSD do not have the wear problems of the older versions.

  • What is the best way to set up my new Mac Pro?

    Not wanting to screw up in a process I've not done with a brand new machine before, I'm looking for feedback on my plan for setting my new Mac Pro next week...
    The physical plan is this:
    For RAM, I have four 2GB SDRAM's plus the supplied six 1GB modules. My plan here is to install the 2GB rams into the first four slots and install four of the 1GB modules into the remaining four slots for a total of 12GB's.
    When the cost for 4GB modules gets down to reasonable, I'll buy four of them and bump the current rams down the line which will then give me a total of 24 gigs where I'll stay.
    For my hard drives, I'm installing a 160GB Intel X25-M into the first drive bay
    http://www.intel.com/design/flash/nand/mainstream/index.htm
    using one of MaxUpgrades' 'MaxConnects' kits. I will use this drive for the operating system software and my applications and their libraries.
    Next, into the remaining three drive bays, I am installing three 300GB WD Velociraptors. Mine are the pre-'backplane ready' versions:
    http://www.wdc.com/en/products/products.asp?DriveID=459
    so I have bought these sleds for them...
    http://www.maxupgrades.com/istore/index.cfm?fuseaction=product.display&product_i d=180
    I own one of Sonnet's Tempo SATA E4P cards
    http://www.sonnettech.com/product/temposatae4p.html
    which, thanks to this forum, I now understand, with the correct firmware installed, function well so I will install it and be able to establish hardware RAID. I will create a RAID 0 set with the three Velociraptors and use it to store all of my data files.
    Backup will happen on a 1TB WD 'Caviar Black' external drive connected through one of the Sonnet card's external eSATA ports and using the OS 'Time Machine' software.
    And that's the physical plan. My question is about setting things up. The physical installation part is straight forward and I don't expect any difficulties but I'm wondering what is the best way to install the operating system.
    Do I take a first step keeping the supplied hard drive installed, install the solid state drive into the next drive bay and then transfer the contents from the supplied drive onto the SSD or do I do the complete physical installation process and do a 'C' drive start up and install the OS that way?
    And, do you have any tips/suggestions on setting up the RAID 0 set?
    thanks for the help. I want to do this right.
    JQ

    oh mighty Hatter, I knew you'd have helpful guidance to offer! And thank you. You've confirmed my anxieties about the Sonnet card; kind of a 'too much, too quickly' sort of thing. And it's not that Sonnet's not a good company. Just everything to do with new technologies and the growth curve we all, manufacturers and users, go through when they come out. And, for sure, the new Mac Pro's are new technology; the single biggest forward leap in Apple's top-of-the-line machines for some time far as I can tell. Just reading at Intel's website about the Nehalem's is a joy!
    So, I will proceed now with everything except for the controller card, leaving that 'til later. In the meantime, I think I'll just happily run with the four hard drives all running independently. No software RAID. I know just those, the SSD boot drive plus Velociraptor trio's going inside of a 2.66ghz 8-core Nehalem Mac Pro is going to be a working pleasure. Heck, this way, I'll get settled in and used to the machine's speed, have a great time doing so and then, in however many months, I can jump into spending another chunk of money on an excellent RAID card, RAID card's dear Barefeats will have tested and reviewed for us, set up my RAID 0 set and head of to those new races watching my computer leap for joy! Could be that, by then, the cost of Intel 160GB X25-M's will have dropped enough that I can afford to go for a second and have a two SSD RAID 0 boot drive... Yummy!
    Thanks for the help. Like I say, I knew there was useful guidance hanging on some limb within your personal kit, (otherwise referred to as your mind)!
    Interesting to read about the problems people have had with Sonnet's 2.17 update in PPC's... In this computer, my PowerMac G5 dual 2.7ghz, I have a Sonnet 'Tempo Sata X4P' controller card. I downloaded and installed 2.17 and got the same troubles; no cut, no paste, no 'drag and drop' etc. It was miserable.
    Mine, fortunately, magically corrected after running the 'permissions verify and correct' process in Disc Utility and, after a restart, all was back to almost normal but for one exception; the Sonnet card was no longer present or functioning including the four eSATA ports out the back. (I ran Tech Tools Pro 5's repair suites first but, and who knows why, it didn't correct the problem...) This one was absolutely in the 'who knows what the f_'s going on and why it disappeared but did' class.
    Oh, the other remnant is that, when the computer goes into sleep, after about five minutes, the fans rev up, and up, and the computer's frozen; only access is to do a forced shutdown pressing and holding the power button, so I've had to adopt a 'shut down whenever leaving it for more than fifteen minutes' approach to this dear friend. Once I've fully moved into and established my new one (which should arrive today, by the way... Yippeee!!! Can't wait!), I'll do a complete restoration on this one including taking out the Sonnet card. Usually, I sell my old Pro's but, this time, I'm going to keep this one as a back up and just general second computer for times I might need it. It has been such a great and dependable machine. Keeping it seems the right thing to do.
    thanks Hatter. I'll let you know how things go, including what happens with the SSD. I don't have speed test software so I won't be able to track it's performance like that guy in the post you gave me did...
    JQ
    ps- Gotta love that ILLogic fellow eh? Talk about not getting the essence!

  • What is the best way of returning group-by sql results in Toplink?

    I have many-to-many relationship between Employee and Project; so,
    a Employee can have many Projects, and a Project can be owned by many Employees.
    I have three tables in the database:
    Employee(id int, name varchar(32)),
    Project(id int, name varchar(32)), and
    Employee_Project(employee_id int, project_id int), which is the join-table between Employee and Project.
    Now, I want to find out for each employee, how many projects does the employee has.
    The sql query that achieves what I want would look like this:
    select e.id, count(*) as numProjects
    from employee e, employee_project ep
    where e.id = ep.employee_id
    group by e.id
    Just for information, currently I am using a named ReadAllQuery and I write my own sql in
    the Workbench rather than using the ExpressionBuilder.
    Now, my two questions are :
    1. Since there is a "group by e.id" on the query, only e.id can appear in the select clause.
    This prevent me from returning the full Employee pojo using ReadAllQuery.
    I can change the query to a nested query like this
    select e.eid, e.name, emp.cnt as numProjects
    from employee e,
    (select e_inner.id, count(*) as cnt
    from employee e_inner, employee_project ep_inner
    where e_inner.id = ep_inner.employee_id
    group by e_inner.id) emp
    where e.id = emp.id
    but, I don't like the complication of having extra join because of the nested query. Is there a
    better way of doing something like this?
    2. The second question is what is the best way of returning the count(*) or the numProjects.
    What I did right now is that I have a ReadAllQuery that returns a List<Employee>; then for
    each returned Employee pojo, I call a method getNumProjects() to get the count(*) information.
    I had an extra column "numProjects" in the Employee table and in the Employee descriptor, and
    I set this attribute to be "ReadOnly" on the Workbench; (the value for this dummy "numProjects"
    column in the database is always 0). So far this works ok. However, since the numProjects is
    transient, I need to set the query to refreshIdentityMapResult() or otherwise the Employee object
    in the cache could contain stale numProjects information. What I worry is that refreshIdentityMapResult()
    will cause the query to always hit the database and beat the purpose of having a cache. Also, if
    there are multiple concurrent queries to the database, I worry that there will be a race condition
    of updating this transient "numProjects" attribute. What are the better way of returning this kind
    of transient information such as count(*)? Can I have the query to return something like a tuple
    containing the Employee pojo and an int for the count(*), rather than just a Employee pojo with the
    transient int inside the pojo? Please advise.
    I greatly appreciate any help.
    Thanks,
    Frans

    No I don't want to modify the set of attributes after TopLink returns it to me. But I don't
    quite understand why this matters?
    I understand that I can use ReportQuery to return all the Employee's attributes plus the int count(*)
    and then I can iterate through the list of ReportQueryResult to construct the Employee pojo myself.
    I was hesitant of doing this because I think there will be a performance cost of not being able to
    use lazy fetching. For example, in the case of large result sets and the client only needs a few of them,
    if we use the above aproach, we need to iterate through all of them and wastefully create all the Employee
    pojos. On the other hand, if we let Toplink directly return a list of Employee pojo, then we can tell
    Toplink to use ScrollableCursor and to fetch only the first several rows. Please advise.
    Thanks.

Maybe you are looking for