• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Object Run time typecasting

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I'm working on a Sample DAO pattern, where in my pattern should be able to insert any record into any table. My basic interface is as below



I have a very vague idea about the implementation. My job would have been easier if I want to insert a specific data into a specific table. But I want a generalized solution so that I can use this utility across different applications. My idea is when a caller calls the methods of this interface say for example, he wants to insert a record in to PERSON table with fields PID,FNAME,LNAME,ADDR. Caller would create a Data Transfer Object called "Product" and could call the method like

(Assuming that we have an implementation of our DAO already existing)

This call should be able to insert the record Person object in PERSON table.

similarly another call to insert a Customer object in CUSTOMER table should also be successful.

But the question is, how do determine that incoming object is of typer Person or Customer. I tried to work on implementation like below
(One comprimise here assuming the class name is same as table name)
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you aware of the existence of, e.g., Hibernate, and many other object-relational mapping frameworks for data persistence? Basically what you're asking is how to reimplement something like Hibernate.
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

Right, what I'm trying to do is a prototype version of ORM. Basically, I'm trying to learn how ORM would have been implemented. You are right, I could use already available ORM frameworks, but wanted to implement using core JDBC. I mean I would get the confidence, If I see how things are implemented at the minute level,rather than using high level API.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi Ravi,

I am also having a simillar requirement. I am restricted to use any ORM tool. Please share if you have developed this.


Thanks.
Arvind
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Schandha Ravi wrote:I'm working on a Sample DAO pattern, where in my pattern should be able to insert any record into any table.


As soon as I hear words like "anything into anything" I always suspect that someone hasn't sufficiently defined their requirements.
And if, indeed, you do mean "insert any record into any table" (including, presumably, ones you haven't dreamt up yet), then I'd suggest that Java is probably not the language you want to use.

However, if there is some "syntax" (ie, restrictions or rules) on what you want to be able to do, there are a few patterns that you might be able to use, just a couple of which might be Abstract Factory or Bridge.

However, if this really is an "anything to anything" scenario, then I fear you're into the realms of reflection; and the solution is likely to be complex, slow, difficult to understand, and even more difficult to test properly.

Winston
 
Arvind Choudhary
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Winston ,

Thanks for your reply.
Two things : a. This indeed is a "anything into anything" requirement meaning the caller will pass the query for CRUD operation and the rest will be taken care of by respective CRUD implemented method in the utility class.

b. The requirement itself starts with a pattern i.e. DAO. What I want is to build a generic DAO so that once it is developed developer will save time in coding and will readability of the code will be improved.


Thanks.
Arvind
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arvind Choudhary wrote:The requirement itself starts with a pattern i.e. DAO. What I want is to build a generic DAO so that once it is developed developer will save time in coding and will readability of the code will be improved.


OK, well the only other thing I can suggest of the top of my head is that you type your DAO rather than passing classes around, viz:however, I'm not quite sure what all this gets you beyond templating basic CRUD operations. As Ernest said, Hibernate provides a lot more than just that; and I certainly wouldn't consider trying to emulate it (at least not on my own; or without a year or so of solid free time).

I'm also not sure what all these boolean returns are for (except possibly for create()). Either the task works or it throws an SQLException (ugh), surely?

Winston
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic