Development of an EJB-based business reservation system _ MySQL

Source: Internet
Author: User
Tags websphere application server
More and more technologies have been applied to large-scale network system development. in this article, I will introduce EJB (EnterpriseJavaBeans) definition, application system structure model based on EJB technology, and content and classification of EJB components. finally, a business reservation system is developed based on the EJB-based structure model and EJB component. In terms of technology, EJB is not a "product", but an EJB

More and more technologies have been applied to large-scale network system development. in this article, I will introduce the Enterprise Java Beans (EJB) definition, application system structure model based on EJB technology, and content and classification of EJB components. finally, a business reservation system is developed based on the EJB-based structure model and EJB component.
In terms of technology, EJB is not a "product", but a technical specification. SUN defines EJB as a component structure for developing and configuring distributed business applications based on components. Applications developed using the EJB structure are scalable, transactional, and secure for multiple users. These applications may only need to be compiled once, but can be configured on the task server platform that supports EJB specifications. In general, EJB is a standard server-side component model for component transaction monitoring.

System structure model based on EJB technology
The EJB structure is a server component structure and a hierarchical structure, as shown in schema 1. This structure model can be divided into the customer layer, business logic layer, and data layer. The following is a brief introduction to this model.

: EJB-based application structure model

The customer layer is mainly used to meet various access requirements for the entire system and handle the following tasks:
Receives user input, analyzes and checks user input, and processes the input accordingly;
Displays the running results from the server's top management.
The customer layer is usually composed of customer processes, which are dynamically created and revoked by the browser.

The business logic layer is the most critical part of the entire system. The business logic layer is usually divided into two layers. its top layer is the request receiving layer (generally called the Web layer), which is used to receive requests sent from the browser and send the requests to the underlying layer for processing, send the request processing result to the browser. These processes mainly consist of JSP pages, Web-based Applets, and Servlets displaying HTML pages. The underlying layer is the request processing layer (generally called the EJB layer), including the listening process, processing process, and database operation process. it is responsible for processing and processing customer requests sent from the request receiving layer, at the same time, the request results are passed to the request receiving layer. if necessary, the processing results must be handed over to the data layer for storage.
The data layer provides data services for the business logic layer, such as storing the processing results of the business logic layer and returning the data results retrieved by the business logic layer. it is also designed to shield data source changes, in this way, when the database changes, we only need to modify the statements for connecting to the data source.

EJB component classification
Generally, the server-side EJB component has two basic types: Entity Bean (Entity Bean) and Session Bean (Session Bean ).


: Architecture of the business reservation system

Entity Bean is a model built for objects in the real world. these objects are usually some persistent records of the database. Entity Bean builds a model for business concepts that can form nouns. it describes both the status of objects in the real world and their behavior, it also allows developers to encapsulate data and business rules related to specific concepts. Session Bean is a dedicated Enterprise Bean created through the Home Interface and connected to the client. Session bean instances are generally not shared with other clients. Session Bean is an extension of the client application and is responsible for managing the entire process or task. Session Beans can manage the interaction between Entity beans and describe how they work together to complete a special task.
Entity Bean can be divided into Bean managed by container and Bean managed by Bean based on the management persistence method. Containers automatically manage the persistence of beans managed by the EJB container. the container knows how the Bean instance fields are mapped to the database, it also automatically manages the insertion, update, and deletion of entity-related data in the database. using Bean to manage persistent beans requires explicit completion of all these tasks. Bean developers must write code to operate on the database. the EJB container only tells the Bean instance when to securely insert, update, and delete data in the database. In addition, it does not provide any help. The Bean instance completes all the persistence work by itself.
Session beans can be divided into stateless beans and stateful beans based on whether they are stateful. Stateless Session beans tend to be common and can be used repeatedly. stateful Session beans are extensions of the customer's applications. they represent the customer's completion of the task and maintenance of the customer's related status.

Development of business reservation system
The cabin reservation system is a business reservation system developed on the J2EE platform based on the EJB component technology. its main process is that after a user logs on to the system, the customer selection page and navigation selection page will be led in turn, and a available cabin will be selected for the customer (the available cabin list will be obtained from the TraveAgentBean, the listAvailableCabin () method of TravelAgentBean is called by the Servlet that generates this webpage. the cabin list will be used to load it to the webpage of the user's browser to create an HTML listbox ), when you select a passenger room and submit the selection, an HTTP request will be sent to the EJB Server (Websphere Application Server). after receiving this request, the Server will assign it to ReservationServlet, this Servlet calls TravelAgent. when the BookPassage () method is used to make a reservation, the tag information returned by the BookPassage () method is used to create a web page that is sent back to the user's browser. If the reservation is successful, ProcessPaymentServlet calls the payment method in ProcessPaymentBean to charge the customer. For detailed architecture, see.
The EJB components in the predefined system mainly include the following parts:
CabinBean: Entity Bean. the primary key is CabinPK. it is an entity Bean used to encapsulate the real-world ship cabins.
CustomerBean: The Entity Bean. the primary key is CustomerPK, which is an entity Bean used to encapsulate consumers in the real world who need to reserve the aircraft and ship cabins.
CruiseBean: The Entity Bean with the primary key being CruisePK. it is an entity Bean used to encapsulate the real-world air route. ReservationBean: Entity Bean. the primary key is CruiseID and CabinID. it represents a record that remains unchanged in the database, that is, a reservation. it records historical events of the reservation system, it is mainly used to prevent double booking, that is, two customers reserve the same cabin for the same route. the reason for this problem is that the customer selects the cabin and Route time and calls bookPassage () there is an interval between the time of the method. TravelAgentBean: stateful session Bean, a session Bean that is responsible for booking the workflow of a sailing class, it encapsulates the process of completing a booking operation for a route and is used in client applications of travel agents around the world. TravelAgentBean not only meets the needs of consumers to book tickets, but also provides messages for the remaining cabins while sailing. To complete this task, Bean needs to know which route, cabin, and customer the reservation is composed of. after the information is collected, the bookPassage () method is used to complete the reservation process, it is responsible for the billing of the customer account, booking the selected cabin on the right ship of the correct route, and generating a Ticket for the customer through the Ticket class. Here, we need to use the CreditCard class to store information about the customer's credit card. at the same time, the ListAvailableCabins () method is used to display available non-reserved cabins.
ProcessPaymentBean: stateless session Bean, which charges consumers in the transaction system. It defines three transaction methods, namely, ByCheck (), ByCash (), and ByCredit (), for checking, cash, and credit card payment methods ().

Sample Code of the business reservation system
The entire business reservation system is developed under IBM VisualAge for Java. in This IDE development environment, entity beans are much easier to develop than Session Beans. the following uses TravelAgentBean as an example, this section describes the development process of EJB components:

1. TravelAgent remote interface
It provides methods to set the route and cabin ID that the customer wants to book. In addition, the boolPassage () method is set to charge the customer's reservation and generate a ticket for the customer. The 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:

Puckage com. titan. tracelagent;
Import java. rmi. RemoteException;
Import javax. ejb. CreateException;
Import com. titan. customer. Customer;
Public interface TravelAgentHome extends javax. ejb. EJBHome {
Public TravelAgent create (Customer cust) throws RemoteException, CreateException ;}

3. TravelAgent Bean class
It needs to implement all the actions in the remote interface and Home interface of TravelAgent. This article will not introduce its implementation code, but interested readers can do it by themselves.

Through the above steps, we have completed the development of the EJB component of a business booking system.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.