This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic DAO Pattern - Subclass Entities

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I use the Generic DAO pattern to model my DAO layer. I have a domain object (application level) termed as Content. A Content may be an Article, Question, Answer or any other object which is persistable in the database. All these persistable entities extent the Content which is just a marker object. Now in my persistence layer, I would like to have a method that returns a Question entity based on the id passed to it. The DAO (for the Content domain) looks like:



But here when I call the getRandomQuestion by passing the technologyId, I should get a Question object in return. I'm thinking of using the JDK dynamic proxy in this scenario. Any suggestions?



 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want to acheive is that, get a ContentDAOImpl which has Question as the entity type at run time instead of having Content as defined above. What I'm literrally doing here is clubbing Content related entities to a single DAO class.

Any ideas?
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaking in terms of design patterns, I'm working out on an alternative to the Anemic DAO pattern. I really do not want to have one DAO for each entity that I have. But rather one DAO per Domain. One Domain in my application consists of many Entities and my application has many such Domains. I want to club this idea together with the Generic DAO pattern.
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:Guys,

I use the Generic DAO pattern to model my DAO layer. I have a domain object (application level) termed as Content. A Content may be an Article, Question, Answer or any other object which is persistable in the database. All these persistable entities extent the Content which is just a marker object. Now in my persistence layer, I would like to have a method that returns a Question entity based on the id passed to it. The DAO (for the Content domain) looks like:



But here when I call the getRandomQuestion by passing the technologyId, I should get a Question object in return. I'm thinking of using the JDK dynamic proxy in this scenario. Any suggestions?



I want to make this part dynamic. I should be able to pass Question, or rather anything that extends Content.

 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions?
 
Joe Harry
Ranch Hand
Posts: 10045
3
Eclipse IDE Mac PPC Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my complete source:

The Generic DAO interface (has methods to define the basic CRUD operations):



The abstract class that implements the above interface: Each DAO will then extend this abstract class by specifying the actual Entity type on which it intends to operate.



The DAO implementation:



I want to experiment the getRandomQuestion method which actually should return a Question which extends from Content. I do not want to have new DAO's for Question. I also have some other Entity which IS-A Content (for example., Answer, SearchableContent and so on) which are logically grouped under Content. I really do not want to clog my persistence layer with a bunch of DAO's but rather one chic DAO (on the Content domain) which gives me what I need for all Content types and which I can instantiate based on the method that I'm going to call. Hope my question is much clear now for any suggestions from you guys.
 
Michele Cozart
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you ever get an answer on this? Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic