• 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

Practical way to write persistence methods / DAO

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic