This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Can (and should) an EJB's Data Access Object be a static class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Can (and should) an EJB Watch "Can (and should) an EJB New topic
Author

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

John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1441
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,


The only reason for time is so that everything doesn't happen all at once.
- Buckaroo Banzai
Peter Reinhardt
Ranch Hand

Joined: Aug 02, 2002
Posts: 57
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


SCJP 1.2, SCJD, SCEA, IBM 484, Weblogic 7
Paul Rhoades
Greenhorn

Joined: Aug 01, 2002
Posts: 20
You could use a Singleton though if you are confident that all your methods are thread safe.
John Wetherbie
Rancher

Joined: Apr 05, 2000
Posts: 1441
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can (and should) an EJB's Data Access Object be a static class?
 
Similar Threads
Anynomous
Lock an object concept que
Method-Inner class
Creating and throw(ing) my own exception compile problem
Session Utility class