This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Performance and the fly likes Generic Value Object for data returned by Multiple resultsets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Performance
Bookmark "Generic Value Object for data returned by Multiple resultsets" Watch "Generic Value Object for data returned by Multiple resultsets" New topic

Generic Value Object for data returned by Multiple resultsets

Talib Jockey

Joined: Aug 06, 2003
Posts: 22
I plan to store the multiple resultsets returned by a DB2 stored procedure in a generic structure. I am planning to store the column name/values as a Map, which are stored inside a List i.e. each record is one element of the list. Is this an effiecent design pattern. I wish to make it as generic as possible.

Can anyone suggest a better startergy to store data returned from multiple resultsets in a generic way (i.e. without creating custom VOs or ResultSet wrappers).

Any inputs are appreciated.


SCJP 1.4 - 97%<br />SCWCD 1.4 - In Progress
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3028
First, I recommend you avoid the term "Value Object" for this sort of thing. This term was used by some early J2EE documentation written by people who didn't realize that "Value Object" was already being used as the name of a completely different pattern - see Value Object. So the J2EE folks changed their terminology, and now what you're talking about is usually called a Transfer Object, Data Transfer Object, or DTO.

As for your questions: is it efficient? Well, it will take a little more time and memory than custom DTOs would. In most cases this really doesn't matter much. Perhaps more significantly, you are also losing compile-time type safety, which is unfortunate, in my opinion. But that's likely to happen anyway if you want this to be "as generic as possible". For the goals you've stated, this is a pretty good approach, I think. You just need to be aware that there are trade-offs involved. If genericity is important to you, then go for it.
Talib Jockey

Joined: Aug 06, 2003
Posts: 22
Thanks so much for your inputs. Also, I will be careful and use DTO going forward.

I have another related question, we have an application where some results from the datatbase are simply transformed to XML and returned to the client, while a few get enriched with data from other data-sources and then are returned to the client. In such an application would you advise using a ResultSet Wrapper for processing i.e. keeping the resultsets open while transforming data?

I have some very strong disagreements over using a DTO to handle such simple read operations. With my limited knowledge of Java and performance, I think even using DTOs for this simple scenario is useful to avoid holding on to DB Connections.

Is it a good idea to have two types of data-structures, one which will hold a Results Map (as described above) and another which holds a ResultSet (Resultset Wrapper). The usage of these data structures will depend on the processing involved

Can you please give your thoughts on this?

Have you checked out Aspose?
subject: Generic Value Object for data returned by Multiple resultsets
jQuery in Action, 3rd edition