Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DAO Design Question

 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1952
7
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Riaan Nel
Ranch Hand
Posts: 160
IntelliJ IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic