Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

view - javabeans - dao

 
Samuel Cox
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First, let me apologize if this is the wrong forum.

Like many beginner J2EE - MVC programmers, I am trying to move business logic currently incorporated in the view and controller layer to the model layer. I am planning on implementing a Struts <-> JavaBean <-> DAO approach. However, I'm unsure as to how to uniquely represent my JavaBean objects that come from DAOs. I'm assuming that my DAO should contain the primary key values which allow easy database access. Should these values be carried through to the JavaBean in the middle? Similarly, should the view be requesting items by the primary keys taken from the database or is this considered bad design?

If anyone has any tips or links to websites with tips/examples for this type of solution, I would be very thankful if you'd share.
 
Dave Clark
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Samuel,

you'll save yourself a lot of coding and maintenance if you just write your Java objects to model your domain model, map these Java objects to your DB schema with JDO (Java Data Objects), and then simply store and retrieve these Java objects via the JDO PersistenceManager. That way you can write your queries in either JDOQL or SQL, and you **don't need to hand-code a set of DAO's**.

JDO also gives you the option of datastore identity (ID's generated by the JDO persistence impementation) or Application ID's which you can generate and access directly in your code. Which approach is right depends on your app.

Some good JDO implementations - open source and commercial - can be found at jdocentral.com

good luck,

Dave
 
Samuel Cox
Ranch Hand
Posts: 96
Scala Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tips.

I'll investigate JDO.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic