Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Suggestion on J2EE design - looking for DataSource.  RSS feed

 
Claude Moore
Ranch Hand
Posts: 891
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning guys,

I need your needful suggestions about a software design question.
With EJB 3.1, it's now possible to use inheritance even with EJBs, so one may reuse code as used to do with POJO classes. Great.
Now, I'm wondering if I may safely use inheritance even to centralize the task of looking for resources in a single base EJB class,
or if I have to beware of race conditions or similar issues in which I may occour.

For example, I need to lookup a specific datasource basing lookup on user's membership to a specific group,since each group's
database runs on a separate machine. To avoid duplicating datasources lookup method and datasources injections, I thought to
develop a BaseService bean:



My business EJBs will extend BaseService, and they will be provided with methods to lookup and release connections quickly.
For example, in a method i may write



What do you think about this approach ? I think it may be useful, expecially to centralize lookup methods and monitoring connections usage, but I don't know if I'm breaking down some Java EE rule on datasource usage and / or EJB specifications...

Thank you for your support !
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it could make sense to have such a class if your application is working with multiple datasources and your business services determine based on runtime condition
which datasource they need.
But if you know upfront which datasource you need in each business service I dont really see the benefit of it...
 
Claude Moore
Ranch Hand
Posts: 891
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it could make sense to have such a class if your application is working with multiple datasources and your business services determine based on runtime condition
which datasource they need.


That's just my case. So, as far as you know, there should not be drawbacks in such scenario, right ?

Thank you for your answer.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's a valid design.

The only thing I would say is that if by any chance you use Spring in your application you dont have to make this BaseService an EJB (it has not business logic after all) but a simple POJO
that gets injected the datasources by the Spring container.
If you do not use Spring, well you have no choice but make it an EJB to benefit DI.
 
Claude Moore
Ranch Hand
Posts: 891
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your reply and for your time.
Best regards.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!