• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Generic DAO Pattern - Subclass Entities

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any suggestions?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you ever get an answer on this? Thanks
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic