This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes DAO Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "DAO Design Question" Watch "DAO Design Question" New topic
Author

DAO Design Question

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Hi Guys

I'm busy working on a simple two-tier app - Swing on the front-end and a JavaDB database on the back-end. I have designed it to use DTO and DAO classes for each table in the database. Since the app isn't designed to work with thousands of records at a time, I want to load all data in a table when the view for that table is opened in the UI instead of using a cache. What I'm unsure about is where the data should be kept after being selected. I can think of two approaches:
1.) Store the data in a List on the UI classes.
2.) Store the data in a List on the DAO classes and request the next record from this List whenever the user changes the selected row on the UI.

Which approach do you think would be best?

Thanks for your help!

Regards,
Riaan


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2046
Riaan Nel wrote:Hi Guys

I'm busy working on a simple two-tier app - Swing on the front-end and a JavaDB database on the back-end. I have designed it to use DTO and DAO classes for each table in the database. Since the app isn't designed to work with thousands of records at a time, I want to load all data in a table when the view for that table is opened in the UI instead of using a cache. What I'm unsure about is where the data should be kept after being selected. I can think of two approaches:
1.) Store the data in a List on the UI classes.
2.) Store the data in a List on the DAO classes and request the next record from this List whenever the user changes the selected row on the UI.

Which approach do you think would be best?

Thanks for your help!

Regards,
Riaan


Definitely NOT on the dao.

Dao should not know anything about its client, and definitely not the latest data requested by the client.

Since it is a 2-tier system, the only place you must put it is in the layer other than the DAO layer - your UI layer.

You can maintain e.g. create a new class, e.g. name it MyStateObject, and store there, whatever you need, to know about the state of the system, e.g. your latest data.
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1666
    
    7

Are you by any chance using an ORM framework like Eclipselink or Hibernate? I think most ORM frameworks support a 2nd level caching strategy.
So if you are using such a framework, simply plug-in a cache provider (if needed) and let the framework deal with it.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Thanks for your advice. I'm going to stick with storing the records in the UI layer, keeping the DAO clean.

Jelle, I'm not using any ORM frameworks, it's pure JDBC.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DAO Design Question
 
Similar Threads
partII: stateful session bean is necessary to serve as a booking cart?
passed SCJD with 360/400
Converting an application to Java (new to Java)
Class design
Passed SCEA 95