Java Reference
In-Depth Information
status.setMake(yacht.getMake());
status.setModel(yacht.getModel());
status.setCapacity(yacht.getCapacity());
// Update the passenger list
Passenger[] list = new Passenger[passengers.size()];
int counter = 0;
Enumeration enum = passengers.elements();
while (enum.hasMoreElements()) {
list[counter++] = (Member)enum.nextElement();
}
status.setPassengers(list);
return status;
}
}
You can see that a YachtSessionEJB instance is associated with a specific yacht, which is
represented by an entity-bean instance. The business rules encapsulated by this entity bean include the
following:
 
If there are any passengers on board, the yacht can be started.
 
If the speed has dropped to below a threshold (for example, 2 miles/hour), the yacht can be
stopped.
 
The yacht can be accelerat ed or decelerated between zero and maximum speed.
 
The status of the yacht can be checked by calling the getCurrentStatus method.
 
The session bean maintains a passenger list.
 
Only club members can board the yacht.
 
Whenever a new passenger is picked up, or a passenger leaves board, the passenger list is
updated.
The YachtSessionEJB uses other helper or utility classes such as YachtStatus , YachtException ,
and so on. YachtException is the application exception that wraps the exceptions related to business
rules. Do not be distracted by these utility classes at this time. They are discussed in subsequent
chapters when we build the other parts of the example . Although the cruise process is implemented as
a session bean, the business entities such as Yacht and Club Member would be better implemented as
entity beans, as discussed next.
Entity Beans
An entity bean represents a business-entity object that exists in persistent storage mechanisms such as
relational databases, object stores, or file systems. In practice, the persistent storage mechanism is
usually a relational database. Typically, each entity bean has an underlying table in a relational
database, and each instance of the bean corresponds to a row in that table. In a more complex situation,
an entity bean may represent several related database tables, and each instance may correspond to a
record in the table join. Some examples of business objects are customers, purchase orders, and
products.
The syntax of the session bean and entity bean client-view API is almost identical. However, the two
types of EJBs have different life cycles, different persistent management, and provide different
programming styles to their clients.
Entity beans are normally used under the following conditions:
 
The bean represents a business entity, not a procedure. For example, MemberEJB is be an entity
bean, but MemberRegistrationEJB is likely a session bean.
 
The state of the bean is required to be persistent. If the bean instance terminates or if the server is
shut down, the bean's state still exists in persistent storage (for example, a database).
Search WWH ::




Custom Search