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).
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.
Joined: Aug 06, 2003
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