Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this good design

 
satish pune
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a previous project where we were using struts the action classes were making calls to methods defined in stateless session beans .

These bean methods were then making calls to static methods defined in a separate class - which we termed as our Business classes

These Business classes would interact with the database .

My question was - in case of retrieving data from the database - ( using select queries ) is it still necessary to make calls through the EJB Layer ?

In case of simply retrieving data is this not an overhead ?
What advantages/disadvantages does this approach incurr ?

Regards ,
-satish
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frankly that sounds like an awful idea: calling static methods on *business* objects to interact with the databse. Where do I begin in describing what's wrong with this approach.

Firstly: static methods are effectively global so you've made you're entire app dependent on those classes.

Second: You've hard coded your dependency on those classes: you couldn't for example use another object that implements the same interface to substitue: how do you test? How do you migrate to another environment?

Third: Well third you're using EJBs but then let's just say EJB CMP is an abomination and BMP is worse...

Have look at Hibernate which is a brilliant ORM library: and in case you're desperate to stick with EJB (some kind of masochist huh?) then a) you can use Hibernate from Stateless Session beans and b) Gavin King, the lead dev for Hibernate, is also on the EJB 3.0 CMP committe and reports EJB 3.0 CMP will look an awful lot like Hibernate.

Edward

If JavaRanch had sigs mine would say: Burn EJB and their creators!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satish,
The decision of whether to go through the session bean layer depends on whether you need transactions/security/scalability.

I second that you should avoid the static calls. Even if you are stuck with them, create a wrapper to abstract it away.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward,
JavaRanch actually does have sigs. If you edit your profile, it's the last item in the first section.
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeanne Boyarsky:
Edward,
JavaRanch actually does have sigs. If you edit your profile, it's the last item in the first section.


Yeah I know: I just thought my comment would be funnier if I pretended they didn't. Kind of like when Roger rabbit escapes from the handcuffs and Bob Hoskyns asks him why he didn't do it earlier: "because it wasn't funny then.". Oh well maybe not
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward,
Oh! I get it now. Sometimes it takes a while for a joke to sink in
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic