• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Combine Resultset

 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
better you apply filter in queries instead of java objects

shailesh
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • 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: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Hello,

could anyone please reply to my issue?

Anirudha
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic