EJB development process
Generally, a complete EJB-based distributed computing structure consists of 6 roles.
1.EJB component provider (Enterprise JavaBean Provider)
Provide the Remote and Home interface responsible for defining the EJB, write EJB Class, performing business logic, providing EJB deployment style
2. Application Assembler
For example, JSP, servlet
3. Deployers (deployer)
4. EJB Server Provider (EJB Server Provider)
5. EJB container provider
6. System administrator
Define and write Enterprise Javabean classes: This is the implementation of Enterprise JavaBean internal application logic
Remote Remote interface written in Enterprise Javabean
Write the local home interface of Enterprise Javabean
Description Primary key (just for Entity Java Beans). The name of the primary key is required in the Configuration Descriptor of Enterprise JavaBean.
One.
Enterprise JavaBean provides a remote interface and a local (HOME) interface that implements the Enterprise Javabean class.
The Remote interface defines the interface of the application logic function that the client call Enterprise JavaBean implemented.
Inside the implementation of the bean must have at least one create () method, -ejbcreate () but can have a CREATE () method with multiple different parameters.
There must be the same method definition (the number of parameters), and the EJBCREATE () method returns a persistent object management of a container management.
Returns a main key value for a container management persistence. However, the type returned in the corresponding Create () method of Home is the Remote interface
Home-> javax.ejb.ejbhome
Remote-> javax.rmi.remote
SessionBean must implement javax.ejb.sessionBean
two.
Defined Remote Class
Each Enterprise JavaBean must have a REMOTE interface, and the Remote interface defines the logical operation that the application specifies customer calls.
This is some public methods called by the customer, usually implemented by JavaBean.
Enteprise JavaBean customers are not directly accessed, but accessed through the Remote interface.
Public interface ejbobject extends ajva.rmi.remote
{
// Allows you to get a related HOME interface.
Public ejbhome getejbhome () throws java.rmi.remoteexception;
// For entity beans, use getPrimaryKey (); method to get the primary key value of Bean
Public Object getPrimaryKey () throws java.rmi.remoteException;
// remove () can delete an Enterpise Javabean
Public void remove () throws java.rmi.remoteException, java.rmi.removeexception
/ / Return to a persistent handle of an Enterprise JavaBean instance
Public Handle GetHandle () throws java.rmi.remoteException;
// Allow you to compare if Enterprise Javabean is the same
Boolean isidentical (EJBobejct P) throws java.rmi.RemoteException;}
The Remote method must be public and throw java.rim.remoteException
3. Define the HOME interface
Enterprise JavaBean interface is in charge of the lifecycle of the bean. Provides Enterprise JavaBean objects (also instances for Enterprise Javabean)
Create (), FIN (), Remove () method
The HOME interface must define one or more CREATE () methods. Each such method must be named CREATE, his parameters,
Whether it is type or quantity, it must correspond to the EJBCREATE () method in the bean class.
If it is the home interface of the entity bean, the find () method is also included.
Each HOME interface extends the Javax.ejb.ejbHome interface, and the following code shows the definition of the Javax.ejb.ebHome interface.
Public Interface Ejbhome Extends Java.ami.Remote ()
{
// This is an instance of Enterprise JavaBean through a handle
Void Remove (Handle Handle) throws java.rmi.RemoteException, RemoveException
// Second is an instance of an Enterprise JavaBean by deleting a primary key
Void Remove (Object Primaryker) throws java.rmi.RemoteException, RemoveException
/ / Return to the metadata interface of the Enterprise Javabeand object, this interface allows customers to get metadata information for Enterprise Javabean
Ejbmetadate getejbmetadata () throws remoteexception;
// Provide a method of obtaining a javax.ejb.ejbHome interface, Home class, Remote interface, and primary key.
HOMEHANDLE GETHOMEHANDLE () THROWS RemoteException;
}
Since the Home interface includes definitions of one or more CREATE () methods. Become a plant, a factory, which defines the following naming regulations for each Create () method, EJB.
1 His return value is the Remote Interface Type of the Session Bean
2 Method's name can only be crete ()
3 Each ejbcreate () method in the session bean class must have a create () corresponding to it, and the type and quantity of the parameters must also be consistent
4 Must throw java.rmi.RemoteException and javax.rmi.createException exception
5 CREATE () method parameters are used to initialize new session bean objects
The following is a different create () method of a session bean object
Public interface addhome extends javax.ejb.ejbhome {
Add create () throws java.rmi.RemoteException, Javax.ejb.createException;
Add Create (Profile PreferredProfile)
Throws java.rmi.RemoteException, javax.ehrows java.rmi.RemoteException, RemoveException
Ejbmetata getejbmetadata () THROWS RemoteException
HOMEHANDLE GETHOMEHANDLE () THROWS RemoteException;
HOME interface for session bean
As we said, a session bean has only one customer. This means that when a customer creates a session, this session bean is a customer created.
existing.
The Create () method of the HOME interface of the session bean, the EJB specification defines the definition of one or more Create () methods
1 His return value is the Remote Interface Type of the Session Bean
2 Method's name can only be crete ()
3 Each ejbcreate () method in the session bean class must have a create () corresponding to it, and the type and quantity of the parameters must also be consistent
4 Must throw java.rmi.RemoteException and javax.rmi.createException exception
5 CREATE () method parameters are used to initialize new session bean objects
============================================================================================================================================================================================================= ============================================================================================================================================================================================================= =========
The HOME interface of the session bean does not define the finder method to locate the object, because the stateful session bean can only use his customers, if not a customer
The session bean created by yourself is not necessary to locate this session bean.
============================================================================================================================================================================================================= ============================================================================================================================================================================================================= =========
Home bean home interface
The entity bean is the same as the BEANDE HOME interface, but there is only a Finder () method,
Thus customers can locate and use entity beans objects, the Finder operation is necessary, because entity beans are existing for a long time, can be used by multiple customers, for most applications, the instance of entity beans exists , Customers only need to find a use to use it.
Define the primary key:
An Entity Bean HOME interface must provide a default Finder method: FinderByPrimaryKey, this method allows customers to pass primary key
To locate the entry bean method has only one unique parameter: That is the "primary key", the return value type of the method is the type of Remote interface of entity Beanz
The type of primary key extends any Java type of the Java Object type. In the Configuration Description, you must tell the container primary key.
* =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===========
According to the definition, the FindByPrimaryKey () method always returns a single Entity object, while other Finder () methods can return Entity objects.
set
* =========================================================================================================================================================================================== ============================================================================================================================================================================================================= ===========
Below is a FindByPrimary () method
FindbyPrimary (key)
Throws java.rmi.remoteexception.finderException;
You can also define other Finder () methods in the HOME interface, each of which must have a corresponding implementation in the Enterprise JavaBean class. Every Finder method must meet the following agreement
1 Return Type is the Remote Interface Type
2 must be started with the prefix, starting with the prefix EJBFIND in the entity bean class
3 Must throw java.rmi.RemoteException and javax.ejb.finderException
4 The throws clause in the HOME interface and the EJBCREATE () method of the entity bean class must also be opposite.