Need EJB advice

R

Rizwan

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
 
E

enrique

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.
 
M

Mr Moiz Rassiwala

the best bet would be to have a class outside the ejb with that method. make it
generic.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top