The technology has been applied to the development of large-scale network system more and more, the author will introduce the definition of EJB (Enterprise Java Beans), the structure model of application system based on EJB technology and the content and classification of EJB component. Finally, a business reservation system is developed with EJB based structure model and EJB component.
EJB is technically not a "product", but a technical specification. Sun's definition of EJB is that the EJB structure is a component structure for developing and configuring a distributed business application based on components. Applications developed with EJB architecture are scalable, transactional, and multi-user-safe. These applications may only be written once, but can be configured on a task server platform that supports the EJB specification. In general, EJB is a standard server-side component model for component transaction monitoring.
The system structure model based on EJB technology
The EJB structure is a service-side component structure, a hierarchical structure, and its structural model is shown in Figure 1. The structure model can be divided into the customer layer, the business logic layer and the data layer under normal circumstances, and the following author makes a brief introduction.
Figure 2: Architecture of the Business reservation system
Entity beans are models built for real-world objects that are typically persistent records of a database. The Entity Bean builds a model for business concepts that can be expressed as nouns, describing both the state of real-world objects and their behavior, while allowing developers to encapsulate data and business rules related to specific concepts. The session bean is a enterprise bean,session bean instance that is created through the home interface and is proprietary to the client connection and is not generally shared with other clients. The session bean is an extension of the client application and is responsible for managing the entire process or task. The session bean can manage the interactions between entity beans, describing how they work together to accomplish a special task.
Entity beans can be divided into container-managed beans and bean-managed beans, depending on how you manage persistence. Container-managed beans are automatically managed by the EJB container for their persistence, the container knows how the bean instance's fields are mapped to the database, and automatically manages to insert, UPDATE, and delete entity-related data in the database; the beans that manage persistence with beans need to do all of this explicitly. The bean's developer must write code to manipulate the database, and the EJB container will tell the bean instance when it is safe to insert, update, and delete data in the database, and in addition, it does not provide any other help. The bean instance completes all the persistence work itself.
The session bean can be divided into stateless beans and stateful beans based on whether they are stateful. Stateless session beans tend to be generic and reusable; A stateful session bean is an extension of the client application that represents the customer's completion of the task and maintains the customer's related status.
Development of Business Reservation system
The cabin reservation system is a commercial reservation system based on EJB component technology developed on the Java platform, the main process is that after the user login, will be led in turn through the Customer Selection page and navigation Selection page, And will select a available cabin for the customer (get a list of available cabins from Traveagentbean, Travelagentbean's Listavailablecabin () method is invoked by the servlet that generates this page. The cabin list will be used to mount the HTML list box on the Web page of the user's browser, and when the user selects a cabin and submits a selection, an HTTP request is sent to the EJB server (Websphere application Server), and the server receives the request Assign it to Reservationservlet, the servlet calls the Travelagent.bookpassage () method to make the actual subscription, and the label information returned by the Bookpassage () method is used to create another Web page that is sent back to the user's browser. If the reservation is successful, the payment method in Processpaymentbean is invoked by Processpaymentservlet to achieve the billing process for the customer. The specific framework is shown in Figure 2.
The EJB components in the scheduled system mainly include the following sections:
Cabinbean: Entity Bean, the primary key is CABINPK, an entity bean used to encapsulate the real-world ship cabin.
Customerbean: Entity beans, primary keys are CUSTOMERPK, an entity bean that encapsulates the real-world consumer who needs to book a ship's cabin.
Cruisebean: Entity Bean, the primary key is CRUISEPK, is an entity bean that encapsulates the shipping routes in the real world. Reservationbean: Entity Bean, the primary key is Cruiseid,cabinid, which represents the unchanging record in the database, a reservation, which records the historical events of the reservation system, mainly to prevent double bookings, that is, two customers booking the same flight in the same cabin, This problem arises because there is a period of time between when the customer chooses the cabin and the route and when the Bookpassage () method is invoked. Travelagentbean: Stateful session Bean, a session bean that is responsible for booking a sailing class workflow, encapsulates the process of completing a subscription operation for a route and is used in the client applications of travel agents around the world. Travelagentbean not only meets the needs of consumers to book tickets, but also provides information on the remaining cabins during the voyage. In order to complete this task, the bean needs to know which route, cabin, and customer make up the reservation, and after collecting this information, the Bookpassage () method is used to complete the processing of the booking process, which is responsible for billing the customer account, and booking the selected cabin on the correct vessel on the correct route. And through the ticket class to produce a ticket for the customer. Here, we need to use the CreditCard class to store information about the customer's credit card, and the Listavailablecabins () method is used to display the available cabins that are not yet booked.
Processpaymentbean: Stateless session bean, which is the process of charging consumers in a transaction system. It defines three transaction methods for checking, cash, and credit card payments, namely Bycheck (), Bycash (), and Bycredit ().
Program code examples for business reservation systems
The development of the entire business reservation system was developed under IBM VisualAge for Java, where entity beans are much easier to develop than session beans, and the following is a travelagentbean example of the development process for EJB components:
1. Travelagent Remote Interface
It provides a way to set up the routes and cabin IDs that customers want to book. In addition, the Boolpassage () method is set up to charge the customer's subscription and generate a ticket for the customer. The specific code is as follows:
Package com.titan.travelagent;
Import java.rmi.RemoteException;
Import javax.ejb.FinderException;
Import com.titan.cruise.Cruise;
Import Com.titan.customer.Customer;
Import Com.titan.processpayment.CreditCard;
Public interface Travelagent extends Javax.ejb.EJBObject
{
public void Setcruiseid (int cruise) throws RemoteException, finderexception;
public int Getcruiseid () throws RemoteException, Incompleteconversationalstate;
public void Setcabinid (int cabin) throws RemoteException, finderexception;
public int Getcabinid () throws RemoteException, Incompleteconversationalstate;
public int Getcustomerid () throws RemoteException, Incompleteconversationalstate;
Public Ticket boolpassage (CreditCard card,double price) throws RemoteException, Incompleteconversationalstate;
}
2. Travelagent Home Interface
The Travelagent Home Interface code is as follows:
3. Travelagent Bean Class
It needs to implement the Travelagent remote interface and all the behavior in the home interface, limited to space, this article will no longer introduce its implementation code, interested readers can do it themselves.
With the above steps, we have completed the development of an EJB component for a business reservation system.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.