Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2005

Tip: Looking for answers? Try searching our database.

Need EJB advice

Thread view: 
Rizwan - 15 Jun 2005 19:52 GMT
In our Stateless Session Beans, all logical-unit-of-work(s) or "business
method(s)" have to do some certain steps first before actually doing their
work. These common steps are put in a method "prepareConnection()" in that
Stateless Session Bean. Below are these common steps (3 of them):

// Instance variables for the Stateless Session Bean
ConnectionManager _connectionManager = null;
Connection _connection = null;
DAOFactory _daoFactory = null;

1) Get the ConnectionManager from ConnectionManagerFactory :
_connectionManager = ConnectionManagerFactory.getConnectionManager(); // use
default

2) Get the Connection from the ConnectionManager :
_connection = _connectionManager.getConnection();

3) Instantiate a DAO Factory and set it to use the "_connection" as its
connection :
_daoFactory = DAOFactory.getDAOFactory(); // use default
_daoFactory.setConnection( _connection );

Then whenever any DAO is created, it is created only through _daoFactory.

After work is done then close the Connection :
_connectionManager.closeConnection( _connection );

My concern is that I have 5 Stateless Session Beans and each of them has the
same method "prepareConnection()". I am thinking that I should have only one
suce method which will be called by the 5 Stateless Session Beans. Is it a
good practice? If yes then should it be inside an EJB or outside? Will I
loose something because of this?

Thanks

Rizwan
enrique - 15 Jun 2005 21:05 GMT
I guess you could have them all derive from a common (non-EJB) class
that implements prepareConnection.  Move the definition somewhere
higher up the inheritance graph.
Mr Moiz Rassiwala - 16 Jun 2005 00:30 GMT
the best bet would be to have a class outside the ejb with that method. make it
generic.

>In our Stateless Session Beans, all logical-unit-of-work(s) or "business
>method(s)" have to do some certain steps first before actually doing their
[quoted text clipped - 32 lines]
>
>Rizwan


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.