• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can (and should) an EJB's Data Access Object be a static class?

 
John Wetherbie
Rancher
Posts: 1449
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all!
I was discussing DAOs with a co-worker and he asked whether a DOA could be a static class, ie, containing all static methods like java.lang.Math. So instead of an EJB instantiating a DOA and reusing this instance it would just call static methods. We thought it could done technically but were fuzzy on what the implications might be to app server performance.
Any thoughts/comments on this?
Thanks,
 
Peter Reinhardt
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Having just static methods in a DAO doesn't allow you to use inheritance and exchanging DAO instances.
E.g. if I have an abstract DAO implementation class which my concrete subclasses inherit from. With static methods this wouldnt work (no inheritance on class side in java).
The static approach doesnt work if you have different DAO implementations (SybasePersonDAO, OraclePersonDAO).
Basically with your approach you loose the benefits of object oriented programming.
Peter
 
Paul Rhoades
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use a Singleton though if you are confident that all your methods are thread safe.
 
John Wetherbie
Rancher
Posts: 1449
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
I was thinking for the static approach that you could handle the loss of inheritance by passing a string indicating the DB (which would be an app variable). But it is probably easier to just go with the normal approach.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic