J2EE Design Mode: CMP to BMP mode (1)

Source: Internet
Author: User
Tags abstract
EJB2.0 finally gave us an operable CMP model. As long as possible, I will use CMP beans in my EJB project; however, due to this strange thing, I need to turn my entities into bean management (BMP. I use the following mode to smoothly switch from the CMP model to the persistent model of bean management.
In this article, we will discuss:
1. CMP 2.0: What changes have taken place?
2. Inventory (Goods List) EJB application
3. Develop a CMP bean
4. Port CMP bean to BMP
CMP 2.0: What changes have taken place?
When EJB came out, CMP caused a lot of repercussions. When EJB2.0 came out, it revised the CMP model and gave us the desired features: such as relationship and query language standardization.
Compared with EJB1.1, when we use EJB2.0 to write a CMP bean, our writing method is quite different. We create an abstract class instead of creating the public domain of the variable managed by the container. We create abstract attributes (getters and setters) like JavaBean ). This allows the persistence manager of a specific vendor to implement the data accessors in their own way ).
This will help them (vendors) propose logic like this:
● Since they do not call any set method, no action is performed in ejbStore ().
● They only change one domain, so we only set that domain in the UPDATE query statement.
● We delayed loading some data, so we read the data only when the user requests the data using the GET method.
By the way, why do we have to create abstract methods in abstract classes? Why can't persistent manager create a method in a derived class?
A: You must access these methods in the abstract class. For example, in ejbCreate (), we SET them by passing in parameters.
Inventory EJB application
To illustrate this entity model, we will see a simple application that uses this entity to model the Inventory system. Our applications include the following components:
Inventory Entity Bean: this is our focus. It maps to the database table Inventory, which records the name (primary keyword), price, and number of items in the warehouse.
Price stateless session Bean: this Bean uses the Inventory Entity Bean to get the price of the entry. It uses the local interface to access the object.
Price customer: this command line application runs this method on Sessions to test that all jobs run well.
The key point is that when we Port this Inventory object from CMP to BMP implementation, nothing should be changed.
Let's take a look at using CMP to implement Inventory entities.
Develop a CMP bean
Inventory CMP wants us to create an abstract class (according to entity description). The XML description file tells the framework what to picture. Figure 1 shows what our entries look like.

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.