EJB classification and their respective functions and applications
Three different categories of EJB: Session beans, Entity Beans, and Message-Driven Beans are defined in EJB 2.0 [2]. 1 session bean
Session beans are business process objects, perform business logic, rules, and workflows. The session bean is called a session bean because it represents an action, a process, its survival is the process of calling its client to sessions. The session bean is divided into status session bean and stateless session bean based on whether it saves the status of the customer. Status Session Bean is a service that keeps a session state, and each instance is associated with a particular client, maintaining a dialog state between the client's method call. In contrast, stateless session beans do not save a dialog state with a particular customer. Therefore, the status session bean has more features than stateless session beans, and the stateless session bean instance can be excluded between the client through the EJB container, so a small number of session beans can serve a large number of clients. 2 entity bean
Entity Bean represents business entities, such as business data, should include logic related to data. The entity bean is a view corresponding to the database, an entity bean instance and the underlying database are all in all things [2]. Therefore, a simple entity bean instance represents a special record. More complex entity beans can represent the database table related view [3].
The entity bean has two types of operation: BMP (bean management persistence) and CMP (container management persistence). BMP refers to the persistence of entity beans by bean, which implements database operations in the bean. The CMP is a persistence of beans by the container, so that we do not need to write the code of the database operation in the Bean.
3 message driver bean
The message driver bean is a bacan type introduced by EJB2.0. Its main purpose is to provide concurrent processing of incoming JMS messages by allowing containers to polymerize and manage messaging bean instances.
4 Differences and contacts between session beans and entity beans
Session beans perform application logic, which implies the use of entity beans as the data they operate. In the EJB distributed object architecture, session beans are used to shield the underlying entity bean subsystem with high-level interfaces representing the actual business process. The entity bean is a model of actual constant business entities, so it is usually more reused than the session bean.
5 EJB application
Next, various EJBs in the business logic layer are analyzed by analyzing the object model of the business logic layer of the electronic shopping link.
The business logic layer contains a series of EJB components. First we abstract it into a number of object models, as shown in the figure:
Figure: Object Model
This figure first reflects the static relationship between EJB components in e-commerce.
A shopping basket (CART) composed of multiple shopping baskets (CART) is a temporary selection of a customer storage product; a order (Order) composed of multiple order entry (Order Line Item) is one Customer storage product permanent choice. Shopping baskets can convert themselves into orders.
A shopping basket represents a temporary choice of a product, an order entry represents a permanent choice of a product.
Valuation (Price) Check the price of the shopping basket when visiting the shopping basket, and calculates the price of the order when the customer finally generates an order.
Order Processor For the order verification credit card, send E-mail confirmation, and identify as permanent. At the same time, it can also understand the process of electronic shopping: First, when shopping, customers put themselves in the shopping basket while shopping, while the valuer is valued. Then, the customer can automatically generate orders after confirming the purchase. The price of the order is calculated from the appler. Next, the legitimacy of the customer credit card is then verified by the order processor. After the transaction is completed, the transaction is sent to the customer to confirm the transaction, and the logo is identified as permanent.
Customers, orders, products, and order entry These objects are permanent, persistent objects, such as customer information, product information requires depositing into the database, and is read from the database when appropriate. Therefore, these items need to be implemented with entity beans.
Shopping baskets and shopping baskets work only in the process of customer shopping, so it is not permanent, and each shopping basket corresponds to a specific customer, corresponding to a specific shopping car entry, so shopping baskets and shopping Basketball Status Session Bean is acting as the most appropriate.
The role of the appler is to calculate the price of the shopping basket and orders, which does not bind a specific customer, can act on any shopping basket, and is not a permanent object, so the appler can use a stateless session bean to act as a stateless session bean. .
The order processor is a special object that produces different orders through the different payment methods required by the customer, that is, it is driven by different payment methods. So this is the most appropriate use of a message-driven bean here.
Through the above analysis, we understand how different types of EJB play its own role in practical applications.