• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Practical way to write persistence methods / DAO

 
William Fernandes
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys!
How are you?

I am currently studying/using JDBC and I had a LOT of job with the last project (a lot of typing )

Is there any pattern that promotes ease of writing the persistence metods? I've read about DAO, but it doesn't like what I want (I guess DAO is more when you need to change your database and you won't have [many] problems).

I know that is a good thing to separate all the persistence code from the business.

Here's some code, a simple example of a bean that I want to save in a table.
Should I create another class that works with Student objects and save, select and update them?



Thanks very much.
Kathy & Bert you guys rule!
 
Scott Selikoff
author
Saloon Keeper
Posts: 4007
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you should look into the Object Relational forum, since it sounds like you may be interested in methods such as Hibernate and JDO. Also, keep in mind large enough systems may still require some knowledge of JDBC for certain queries.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there any pattern that promotes ease of writing the persistence metods? I've read about DAO, but it doesn't like what I want (I guess DAO is more when you need to change your database and you won't have [many] problems).

Avioding typing code is not a normal driver for choosing a pattern (though I share your pain ).

DAOs are good because they seperate the persistance implementation from your application. As you have already noted they are good if you want to change databases. They are also good if you decide you don't want to use a database at all, for example if you want to run unit tests on your code with a hard coded data set. Or if you decide you want to replace JDBC with something else (such as Hibernate). It might not be immediately apparent that you will need to do this, but for the little extra effort you make you gain yourself a lot of freedom to rework your app.

If you are looking for ways to reduce the amount of code you have to personally write you might look at some of the modelling tools out there that have forward generation capabilities. With this you model your DAO, hit a button and the tool generates your code for you.
[ July 22, 2008: Message edited by: Paul Sturrock ]
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sometimes do something like this:



So there are 3 classes - domain object, abstract DAO and DAO implementation in JDBC
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic