The main purpose of the EJB specification is to disclose the enterprise application system developers from application system-level programming work, which can focus on systematic analysis and code writing work in the application system.
According to the definition of EJB2.0 specification, the EJB component is composed of a Home interface, a Remote interface, a component class, and deployment description file. Application Developers When writing to the EJB component, the application must fully define the deployment description files of the components to provide services for the EJB container providing services.
Naming rules for EJB components
The session components and entity components defined in the EJB specification are composed of the Home interface, the Remote interface, and component classes. Therefore, in the creation process of component interface objects and component classes, a unified naming rule should be followed. For example, to write a stateful sessionBean type EJB component for calculating the allowance, you can name "Calcbonus" based on the component completed, which constitutes the naming rules of other elements of the EJB component are as follows:
EJB object
The EJB object represents the EJB component to be created, no code corresponding to it. The naming rule of the EJB object is the attachment string "EJB" after the string representing the component business meaning. According to the rules, the allowance can be used to calculate the EJB component object name "CalcbonuseJB".
HOME interface
The naming rule of the HOME interface is the attachment string "home" after the string representing the component business meaning. Therefore, the HOME interface of the allowance calculated EJB component can be named "CalcbonusHome".
REMOTE interface
The REMOTE interface object of the EJB component can be naming directly with a string that represents a business meaning of the component. For example, name the Remote interface of the allowance computing component is "Calcbonus".
Component class
The naming rule of the component class is to attach "bean" after a string representing the component business meaning. For example, the allowance calculation component class is named "CalcbonusBean".
HOME interface for EJB components
The HOME interface of the EJB component is used to define methods for creating, looking, and deleting component object instances. Take the stateful session type EJB component CALCBONUSEJB as an example, its HOME interface definition is shown in the following code:
Public Interface Calcbonushome Extends EJBHOUSHOME EXTENDS EJBHOME
{
Public Calcbonus Create () Throws createException, RemoteException;
Public Calcbonus Create (int nrate) throws createException,
RemoteException;
Public void remove () throw receexception;
}
In the above definition, the Home interface of the EJB component inherits the EJBHome interface, including the CREATE method of the creating component object instance of the two heterogeneous types, and two methods return the REMOTE interface object of the EJB component. The REMOVE method for deleting the component object instance in the component instance pool of the EJB container is also defined in the home interface. This method corresponds to the EJBRemove method defined in the EJB component class.
For entity type EJB components, the method of finding the component object instance should also be defined in the HOME interface of the component, which is used to find the specified entity type EJB component in the EJB container according to the primary key value of the physical component. The definition and implementation process of this method will explain in detail in the 6th.
In addition, the recraftException and CreateException types that are defined in the Home interface can thrown. Two types of exceptions are defined in the java.rmi package and the exception parameters and return value types are legal RMI-IIOP types. It can be seen from an exception's return value: The Home interface of the EJB component object is an interface for the Java RMI-IIOP protocol, and client applications can access the HOME interface deployed in the EJB container based on the RMI-IIOP protocol. The method defined in the Home interface In addition to the ability to throw the above system, the designer of the EJB component can define the user type exception and the method defined in the home interface.
REMOTE interface for EJB components
The REMOTE interface of the EJB component is used to define the component business methods that the client application can call. Similar to the Java interface, the business method defined in the Remote interface is just a frame without specific implementation code. The EJB component designer writes a real code in the component class in the component class based on the business method defined in the Remote Interface. There is a status session type EJB component CalcbonuseJB's REMOTE interface is defined as follows:
Public Interface Calcbonus Extends EJBOBJECT
{
Public float calculatebonus () throws remoteException;
Public Float Calculatax (Float Frate, Float Fbonus)
Throws RemoteException;
}
The EJB component's REMOTE interface inherits the EJBObject interface in the Javax.ejb package. Two names of CalculateBonus and CalculaTax are defined in the Remote interface. Both methods throw the RemoteException type exception. It can be seen that the exception type that can be thrown by the method defined in the Remote Interface: The Remote interface is also a remote interface for Java RMI-IIOP protocols.