Looking Under the Hood of a BMP Entity Bean

Figure 10.1 shows the interactions between the client, EJB container, bean-managed persistence bean, and the database.

Figure 10.1. Under the hood of a bean-managed persistence bean.


The following steps describe the sequence of interactions in detail:

1.
At startup, the EJB container registers all the deployed enterprise beans, including entity beans, with the JNDI service.

2.
The client looks up the home interface of the deployed enterprise bean via the Java Naming and Directory Interface (JNDI). For example, the remote home interface for the Student bean can be located using the following code segment:

Context initialContext = new InitialContext();
Object obj = initialContext.lookup("day10/Student");
StudentHome studentHome = (StudentHome)
 javax.rmi.PortableRemoteObject.narrow(obj, StudentHome.class);

3.
The client uses the remote home interface to create a remote Student object. For example, the client creates a new student as follows:

Student student=(Student)studentHome.create("1",  "Raghava",
             "Kothapalli", "1234, People Dr. Pleasonton, CA");

When a client invokes a create<method> method on the home interface, the EJB container invokes the corresponding ejbCreate<method> method, followed by the ejbPostCreate<method> method on the bean instance.

4.
The client calls a method on the remote object. For example, the client calls the getStudentId() method on the remote object as follows:

String studentId = student.getStudentId();

The container calls the appropriate method on the entity bean instance. For example, the EJB container calls the getStudentId() method on the entity bean instance.

5.
The client calls the remove() method of the remote object. For example, the client removes the order object as follows:

student.remove();

The container then calls the ejbRemove() method on the entity bean instance.

The EJB container synchronizes the state of the instance with the database using the ejbLoad() and ejbStore() methods. For example, to passivate the entity bean instance, the container first calls ejbStore() to allow the instance to synchronize the database state with the instance's state, and then calls the ejbPassivate() method.

The bean-managed persistence bean contains calls to access the database. The data access can be coded into the entity bean class or encapsulated in a data access object that is part of the entity bean.

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

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