Business Delegate+Session Facade+DAO

Discussions

EJB programming & troubleshooting: Business Delegate+Session Facade+DAO

  1. Business Delegate+Session Facade+DAO (1 messages)

    Hi, I'm new to EJB's n currently working on Business Delegate+Session Facade+DAO. Can anyone send me the links to code on the above? Or any sort of tutorial?
  2. Business Delegate+Session Facade+DAO[ Go to top ]

    http://java.sun.com/blueprints/corej2eepatterns/Patterns/index.html describes all the patterns you mentioned.

    Essentially they break down as follows:

    [Business Delegate]
    This can mean different things. I usually (maybe not correctly) use it to refer to a client side "facade" that is responsible for talking to a server side object.

    [Session Facade]
    This is usually a fine grained stateless session bean which talks about use cases. The implementation of this facade *may* delegate to one or more finer grained POJOs/EJBs. Another common use is to use a session facade to wrap all external access to entity beans.

    [DAO]
    Data Access Object is a layer behind which lives all your data access code. For example, you SF (Session Facade) might choose to use a DAO to load stuff from persistent storage.

    Examples:

    public final class ClientSideBusinessDelegate {
      public UserVO getUser(final String username) throws UserNotFoundException {
        try {
          return userStateLessSessionBean.getUser(username);
        } catch (RemoteException e) {
          throw new MySpecificRuntimeException(e);
        }
      }
    }

    public final class ServerSideStatelessSessionBean {
      public UserVO getUser(final String username) throws UserNotFoundException, RemoteException {
        UserVO user = dao.loadUser(username);
      }
    }

    public interface UserDAO {
      UserVO loadUser(username) throws UserNotFoundException;
    }

    public class EntityBeanBackedUserDAO implements UserDAO {
      public UserVO loadUser(username) throws UserNotFoundException {
        try {
          UserVO user = new UserVO();
          UserEntityBean userBean = userHome.findByPrimaryKey(username);
          user.setUsername(userBean.getUsername());

          
        } catch (ObjectNotFoundException e) {
          throw new UserNotFoundException(username);
        }
      }
    }

    Note: The DAO will typically be an interface with one or more implementations. Note also that the exceptions coming from a DAO should not be implementation specific :)

    Hope this helps.

    Comments + feedback welcome.

    Col

    P.S. Ask 10 people, get 12 different answers ;)