Development and _jsp programming of business reservation system based on EJB technology

Source: Internet
Author: User
Tags ticket websphere application server
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.

图1:基于EJB的应用结构模型

客户层 主要是用来满足对整个系统的各种访问需求并处理以下工作:
接收用户的输入,还可以对用户的输入进行分析检查并作相应的处理;
显示由服务器端高层传来的运行结果。
客户层通常是由客户进程组成,这些进程由浏览器动态地创建和撤销。

业务逻辑层 这是整个系统最关键的部分。业务逻辑层在通常情况下会分为两层,其高层是请求接收层(一般称之为Web层),用于接收从浏览器传来的请求并将请求交给底层进行处理,同时将请求处理结果发送给浏览器。这些过程主要由JSP页面、基于Web的Applets以及显示 HTML页面的Servlets组成。底层是请求处理层(一般称之为EJB层),包括监听进程、处理进程和数据库操作进程,负责处理请求接收层传来的客户请求并对它进行处理,同时将请求结果传递给请求接收层,如果需要的话还需要将处理结果交给数据层进行存储。
数据层 主要是为业务逻辑层提供数据服务,如存储业务逻辑层处理结果、返回业务逻辑层检索的数据结果,同时也是为了实现屏蔽数据源的变化,从而实现当数据库发生变化时我们只需修改连接数据源的语句就可以。

EJB组件的分类
通常情况下,服务端的EJB组件有两种基本类型:Entity Bean(实体Bean)和Session Bean(会话Bean)。

图1:基于EJB的应用结构模型

客户层 主要是用来满足对整个系统的各种访问需求并处理以下工作:
接收用户的输入,还可以对用户的输入进行分析检查并作相应的处理;
显示由服务器端高层传来的运行结果。
客户层通常是由客户进程组成,这些进程由浏览器动态地创建和撤销。

业务逻辑层 这是整个系统最关键的部分。业务逻辑层在通常情况下会分为两层,其高层是请求接收层(一般称之为Web层),用于接收从浏览器传来的请求并将请求交给底层进行处理,同时将请求处理结果发送给浏览器。这些过程主要由JSP页面、基于Web的Applets以及显示 HTML页面的Servlets组成。底层是请求处理层(一般称之为EJB层),包括监听进程、处理进程和数据库操作进程,负责处理请求接收层传来的客户请求并对它进行处理,同时将请求结果传递给请求接收层,如果需要的话还需要将处理结果交给数据层进行存储。
数据层 主要是为业务逻辑层提供数据服务,如存储业务逻辑层处理结果、返回业务逻辑层检索的数据结果,同时也是为了实现屏蔽数据源的变化,从而实现当数据库发生变化时我们只需修改连接数据源的语句就可以。

EJB组件的分类
通常情况下,服务端的EJB组件有两种基本类型:Entity Bean(实体Bean)和Session Bean(会话Bean)。


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:

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 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.
Related Article

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.