• 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

Generic Value Object for data returned by Multiple resultsets

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Regards,
Talib
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

Thanks,
Talib
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic