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

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

 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic