(群 科技 松瀛)
J2EE has gradually become a standard application platform in the enterprise today, and
There are many programming designers, even web designers, using JSP / servlet
Interest, develop related applications on J2EE Server, or resources within the company
Connect.
There are also many people in J2EE in J2EE recently, and EJB is
A very worthwhile technology.
This document is not to teach you how to write EJB, but hope to make your ejb.
Interesting users can roughly understand what EJB can make you do.
EJB is different from the characteristics, and the current is divided into three types, which are session beans.
Entity Bean, and Message Driven Bean. Semion Bean
Entity Bean is an EJB's ancestor, these two EJBs are when EJB specification is 1.x
It has already existed, and Message Driven Bean appears in the specifications of EJB 2.0
. There are currently several manufacturers' J2EE Server support EJB 2.0 specifications.
Session bean
The main purpose of session bean is to let the program developers extract the logical layer, especially complex
Miscellaneous logic can be placed in Session Bean. Session Bean can also be subdivided
Stateful Session Bean with Stateless Session Bean, these two Session Beans
You can perform system logic in Method, and different is Stateful Session.
Bean can record the status of the caller, so in general, a user will have one
Entity of the corresponding Stateful session bean (INSTANCE Note), in other words,
When the user calls two Methods for a Stateful Session bean,
EJB Container will clearly know that an EJB entity belongs to a certain use
. Therefore, in general design, the two users will not use some STATEFUL at the same time.
Session bean (this is not to indicate that two users cannot use the same stateful session.
Bean).
Although the Stateless Session bean is also a logical component, he is not responsible for record
When the user states, that is, when the user calls the STATELESS SESSION bean,
EJB Container does not look for specific STATELESS SESSION beans entities
To perform this Method, in other words, it is likely that several users are executing a STATELESS.
When Methods of Session bean, it will be the same bean's instance in execution.
From the perspective of memory, stateful session beans and Stateless Session
BEAN compares the Stateful Session Bean consumes more J2EE Server,
However, the advantage of Stateful Session Bean is that he can maintain the status of the user.
Entity Bean
Entity Bean is mainly information components, and Entity Bean is the main purpose of providing
According to the program, the programming agent can use the Entity Bean as the program, as for Entity
Bean actually accesses the actual database, that is another thing.
Entity Bean is actually designed for RDBMS, that is, when other programs use Entity Beans, Entity Beans are mainly from rdbms.
However, if the programming is familiar with the operation of Entity Bean, it can also be easy to put
RDBMS replaces other databases, like LDAP.
Entity Bean mainly distinguishes bean-managed personistence and container-
Managed Persistence (BMP and CMP), these two Entity Beans
Different, but the purpose is the same, it is information! These two Entity Beans are mainly
The difference is the role of maintenance information, and BMP is consistent with the Bean self-maintenance information.
CMP is maintained by EJB Container. An Entity Bean often represents a piece
RDBMS's form, a piece of information in this form, is another one
Class Class is called Primary Key (Note 3).
Bean-managed personistence
When we say that BMP is consistent by the Bean's own maintenance information, some people will feel too much.
In abstract, simple, the original information is from the database, and when the information comes from
After the bin is taken, you need a self-declaration field in BMP to store these information.
Always write related program code, including related JDBC syntax, etc.
Container-managed personistence
CMP is a higher-order Entity Bean, which is higher than the meaning of writing CMP.
Program designers don't need to write most JDBC syntax, just need to define some definitions
It can generate CMP, and the actual EJB program code is EJB Container based on
Off Deployment Description (Note 4) is generated when deployed (Note).
BMP is different from CMP, and the applicable occasions are different. The main difference is if
We want to control all the actions yourself, then you should use BMP, BMP allowed procedures
The designer completely controls the data access behavior of BMP, and CMP is very suitable for rapid development.
But because J2EE Server to support CMP requires higher technology, each for each family
CMP has not supported the same support.
In addition, there is a very important relationship in the database to or mapping, which is often heard.
One-on-one, one-to-many, more, this relationship, in the specification of EJB 1.x, this one more
The corresponding relationship is only two ways to make, one is to access through the session bean
A plurality of Entity beans, the other is to control other BMPs through BMP or
CMP, but in the specifications of EJB 2.0, you can already cooperate through pure CMP.
EJB-QL (note 6) grammar to make this correspondence, which is also a major feature of EJB 2.0.
Message Driven Bean
Message Driven Bean is different from session beans or Entity Bean,
General session beans or Entity Beans allow users to trigger (can
When needed, call their Method to trigger them), but the MESSAGE DRIVENBEAN is the main purpose of reacting events in Message Queue.
That is, when there is a message in Message Queue, Message Driven Bean can
Take the initiative to trigger, make a corresponding reaction. So if you say session bean with entity
BEAN is the EJB of synchronous mode (the user calls a Method, only the EJB response can be
After that, you can follow the next step), then Message Driven Bean can be used as a special place
EJB in the format of the Becus, that is, the program designer throws a message to Message
After Queue, continue, on the other hand, Message Driven Bean will
Notified, knowing a message needs to be handled, this time he will work.
Therefore, the Message Driven Bean is not directly calling the user, but through Message
Queue to trigger.
If you are interested in EJB, you can refer to Sun's Education Training Course SL-351.
Note 1:
Bean instance represents an object that is actually generated in memory, a bean class
Multiple Bean Instance can be generated. Bean instance is really implementing EJB
Method objects, it is conceivable that the more instances, the more consuming memory
more.
Note:
EJB Container is responsible for performing EJB, all EJB production, or destroy
, Or equal, all handled through EJB Container. When the user calls one
When EJB, it is actually performed through the EJB Container.
Note three:
In RDBMS, a Table may have the relevant primary key field, and
There is also a corresponding Class in the Entity Bean to represent this Primary Key, such as
If in the database, a varchar field is its primary key, then
In the Entity Bean, you can use String to represent this varchar field.
Note 4:
Deployment Description is an XML format file (DD), this file
Used to describe the type, type, and related information of EJB. EjB's operation, also
The description in DD is mainly described.
Note 5:
The deployment is a move, a write good EJB cannot be implemented separately, he must be "placed"
After the EJB Container can be operated, this placement action is called deployment.
The deployment is quite complicated, but it is probably the user can be finished.
to make.
Note:
EJB-QL is a special syntax for querying EJB Instance, grammar format and ANSI SQL
Very like, it is easy to get started. This grammar is placed in DD, while EJB Container
The association of other CMP can be generated in accordance with the EJB-QL syntax from DD.