Flexible design for web-app to access EJB or JDO


EJB design: Flexible design for web-app to access EJB or JDO

  1. Flexible design for web-app to access EJB or JDO (3 messages)

    Hi, I wonder if there is a pattern or proven design if you want to access data (from a web-app for instance) in a way such that you can easily switch from JDO to EJB (and vice versa). I can think of two ways now.

    1. Have 4 layers: Web-app (Struts, JSP/Servlets) --> Business logic (JavaBeans, compute things etc.) --> Persistence (how to get data, here you could switch between EJB and JDO via factory pattern) --> Data (enhanced classes or entity beans)

    2. Similar but with session beans: Web-app --> Business logic --> Session Beans --> Entity Beans or JDO classes
    I leave the business logic in here (and not replace it with session beans) because this are mostly JavaBeans I can easily access from JSPs. I am not sure if one can do the same with session beans.

    I would prefer the first one, because then I do not have to deal with the EJB stuff while using JDO. But maybe there are reasons I don't see now why the second (or any other approach) would be better.

    Thanks for your comments
  2. I like the second method better. You can implement session bean layer as session facade design pattern and business logic layer as business delegate design pattern. Take a look at Sun's J2EE Pattern center for more information on this.

    With session facade, you don't have to access entity bean directly. Business delegate is the layer between session bean and servlet.
  3. A very good example for these design pattern can be found at http://www.myhtg.com/product.html
  4. I had a look at the sun site. Thanks for the tip. No doubt that I will use Business delegate. As delegate I think I will use either a session bean or a "normal" class (both implementing the same interface), depending on whether I want to work with EJB or JDO. Since JDO is what I want to use in the first place (and EJB for comparison, or fallback when JDO doesn't work as expected), I really want to avoid having the added hazzle of an EJB environment when using JDOs. But when using Entity-Beans anyway, I can also use Session Beans thus having Session Facade pattern.