• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Combine Resultset

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am writing a Java application which returns XML having data for n attributes. Data for all the attributes can not be retrieved by firing a single SELECT query. so I have to fire multiple queries and then combine all resultsets to get data for attributes.

I am not sure how can I combine the results? Any suggestions?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Anirudha J ",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use VO(value Object)/DTO (Data transfer Object)

search on google for same you will get lot of example
 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once the value object is created by combining the data from multiple resultsets, I have to apply user defined filters on it. User can set data filters like empname starts with A OR birthdate greater than 31st march.

How do I apply these filters on the value object collection?
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
better you apply filter in queries instead of java objects

shailesh
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Shailesh Chandra:
better you apply filter in queries instead of java objects



Cent percent agreement. But you can also do that too. Where is the problem?
 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah thats correct. but not all data is coming from database.

value objects is populated by firing multiple queries and doing some API calls. so if filter is set on a attribute which is coming from SQL I can always use WHERE clause to filter the data, but for other attributes whose data is retrieved by an API call,,I can not add filter clause.

So I thought of making VO collection first and then filter objects of this collection based on the filter.

But I am not sure how to filter a collecction?

Anirudha
 
Shailesh Chandra
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in that case you can play with hashmap and dto

put some code with explanation so we can suggest how

shailesh
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anirudha Joshi:
But I am not sure how to filter a collecction?



You can just loop through the collection and use an if statement to check the criteria.
 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looping through collection and then removing objects will be expensive...... The way I am planning to do it
1. Define a value object class having all the attributes
2. Fire queries and populate value object attributes and put it in the collection
3. get the user defined filters and loop through collection to filter.

I think this will be expensive. is there any alternate way?
 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

could anyone please reply to my issue?

Anirudha
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a sql ability on Arrays using a class I created called ArraySQL that is part of the open source formatteddataset api. The api also has the abilility to turn a ResultSet into an Object[][].

http://www.fdsapi.com

As far as speed goes it is quite fast.



Also, you can use JOSQL to query Collections, using a sql like syntax. http://josql.sourceforge.net/

Both, are useful utilities to have in your arsenal.
 
reply
    Bookmark Topic Watch Topic
  • New Topic