Development of an EJB-based business Reservation System

Source: Internet
Author: User

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 follows: The EJB structure is to develop and configure distributed business applications based on components. Program Is a component structure. 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.

Figure 2: 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 writeCodeThe EJB container only tells the bean instance when to safely 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. The specific architecture is shown in figure 2.
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.

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.