• 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

Dynamic attribute selection for Excel export

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

I'm to refactor a web application that makes heavy use of good(?) old JDBC calls to persist and retrieve data from an Oracle DB. The application features something called "Excel export" where users can select attributes to be exported. The generated Excel sheet has very simple looks, it's really nothing more than a table.

The mechanism I'm worried about is not the Excel sheet at first hand but the way how selecting wanted or unwanted attributes works: the user selects more or less directly column names from a DB view that contains all the data in question, his selections are concatenated to plain SQL and executed. The user doesn't know what really happens in the background, of course. Apart from the attributes/colums themselves the user can choose to order the exported data, this translates into an additional GROUP BY clause in SQL.

If the exported data was more static I'd usually do this with something like an export bean holding all the data and handing the bean to an Excel export service. Now it's getting more tricky with an unknown number of user-selected attributes, my first shot was to design a "mega bean" having all possible attributes and setting values where they exist, but his is ugly if only a few attributes are selected because I have to do a null-check whenever accessing a member.

So my question is: are there any design patterns out there for a problem like this?
 
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
Mike,
Can you use a generic object for data transfer? For example an array of strings (or "Excel types" allowing Strings/Dates/Numbers.) If all you are doing is displaying the data in Excel, you may not need it in a "real" business object.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic