Designing a CMP Entity Bean

Figure 11.2 shows the design of the Order component. The OrderEJB container-managed entity bean implements the javax.ejb.EntityBean interface. It implements the methods setEntityContext(), unsetEntityContext(), ejbActivate(), ejbPassivate(), ejbLoad(), ejbStore(), and ejbRemove() as defined in the javax.ejb.EntityBean interface. It also implements the ejbCreate() and ejbPostCreate() methods.

Figure 11.2. Order entity bean design.


An OrderEJB entity bean class consists of the persistent fields orderId, studentId, orderDate, status, and amount. You do not code them as instance variables in the entity bean class. Instead, the persistent fields are identified in the code by access methods (getters and setters). An Order entity bean is identified by its primary key, orderId.

The OrderEJB bean class also implements the ejbHomeGetTotalAmountOfAllOrders() method and defines the select method ejbSelectAllOrderAmounts() method. We'll discuss select methods later today.

We also provide remote interfaces to our entity bean. These include a remote home interface (OrderHome) and a remote interface (Order). The OrderHome home interface extends the javax.ejb.EJBHome interface and defines a single create() method, two finder methods, and one getTotalAmountOfAllOrders() home method. The Order remote interface extends the javax.ejb.EJBObject interface and defines the getters and setters for persistent fields. As you learned on Day 2, “Understanding EJB Types and Interfaces,” container tools generate the classes that correspond to the home and remote interfaces.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.114.28