Discussions

General J2EE: Populate and filter objects from Java collection

  1. Hello,

    I am writing a Java application which fires multiple SQL queries and builds a data structure. All the attributes of data structure can not be fetched in single query. So I have to fire multiple queries and then combine all resultsets to get data for attributes.

    To achieve this, I am planning to keep a View object having all the attributes. I will populate this VO and add it in the collection.

    But I also have to filter the collection based on user defined filters (for ex: all employees whose name starts with 'A'). These filters can be set on any of the attribute.

    Is there any efficient way of doing this? Any suggestions? What type of collection I should use? How can I filter collection objects?

    - Ani
  2. You should look into the Jakarta Commons Collections API (http://jakarta.apache.org/commons/collections)
  3. This is one of those situations where developing with Hibernate would really pay off. Assuming that you didn't, I'd suggest applying the filter to the query string and let DB do the sorting and filtering for you. Then just run down your result set in order. Why make your life harder.