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