• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how should the optimized DAOs used in Stateless Session Bean look like?

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, I recently studied a sample J2EE applications from Oracle, where DAO is used to provide persistence, and stateless session bean used for business logic. But I'm a little bit confused about whether this is an optimized DAO design.

in DAOFactory and getDAO() method is like below:

public class TradeManagementDAOFactory {
private static TradeManagementDAO dao = null;
public static TradeManagementDAO getDAO() throws Exception {
if( dao == null) {
dao = (TradeManagementDAO) Class.forName(implClassName).newInstance();
}
return dao;
}
}
So, only one DAO instance would be created, all requests to DAO would actually share the same DAO instance.


the DAO class use an instance variable to keep track of DataSource, and in each instance method of DAO class, a connection is acquired and then released.


In Stateless Session Bean like below, an instance variable is used to keep track of the DAO instance, which is initialized in ejbCreate():

public class TradeManagementSessionFacadeBean implements javax.ejb.SessionBean {
private TradeManagementDAO tradeManagementDAO;
....
}

So, in a multi-user environment, where there're multiple transactions and multiple Stateless Session Bean instances, multiple SLSB instances or transactions would share the same DAO instance? is this a good, optimized DAO desgin pattern?
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's optimized. Since states are maintained within the method, it is fine for multithreading/multitransaction. DAO instance is somewhat like servlet--there is a single instance of servlet.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic