EJB Development Process

Source: Internet
Author: User

Generally, a complete EJB-based Distributed Computing structure consists of six roles.
1. EJB component provider (Enterprise JavaBean provider)
Provides the remote and home interfaces for defining ejbs, compiling EJB classes for executing business logic, and providing the deployment style of ejbs.
 
2. Application aggreger)
For example, JSP and Servlet

3. deployer)

4. EJB Server Provider)

5. EJB container provider

6. System Administrator)

Define and compile the Enterprise JavaBean class: This is the implementation of the internal application logic of Enterprise JavaBean.
Compile the remote interface for Enterprise JavaBean
Compile the local home interface of Enterprise JavaBean
Description: primary key class (only required for entity Java Bean ). In the configuration descriptor of Enterprise JavaBean, you must specify the name of the primary key.
I.
Enterprise JavaBean provides the definition remote interface and local (home) interface to implement the Enterprise JavaBean class,
The remote interface defines an interface for the customer to call the application logic functions implemented by Enterprise JavaBean.
Bean must have at least one create () method,-ejbcreate (), but it can have multiple create () methods with different parameters.
The same method definition (the same number of parameters) must also be available in the home interface. The ejbcreate () method returns a Persistent Object of container management.
All return a primary key value for container management persistence. However, in the corresponding create () method of home, the returned type is the remote interface.

Home-> javax. EJB. ejbhome
Remote-> javax. RMI. Remote

Sessionbean must implement javax. EJB. sessionbean

II.
Defined remote class
Each Enterprise JavaBean must have a remote interface, which defines the logical operations that the application requires the customer to call.
This is a public method called by the customer, which is usually implemented by JavaBean.

The client of Enteprise JavaBean does not directly access the bean, but accesses the bean through the remote interface.

Public interface ejbobject extends ajva. RMI. Remote
{
// You can obtain a related home interface.
Public ejbhome getejbhome () throws java. RMI. RemoteException;
// For the Entity Bean, use the getprimarykey (); method to obtain the bean's primary key value
Public object getprimarykey () throws java. RMI. RemoteException;
// Remove () can delete an enterpise JavaBean
Public void remove () throws java. RMI. RemoteException, java. RMI. removeexception
// Returns the persistent handle of an Enterprise JavaBean instance.
Public handle gethandle () throws java. RMI. RemoteException;
// Allow you to compare whether Enterprise JavaBean is the same
Boolean isidentical (ejbobejct p) throws java. RMI. RemoteException;
}

The remote method must be public and Java. Rim. RemoteException is thrown.

3. Define the home interface
 
The Enterprise JavaBean interface controls the bean lifecycle. Enterprise JavaBean object (also an instance for Enterprise JavaBean) is provided)
The create (), FIN (), remove () Methods
The home interface must define one or more create () methods. Every such method must be named "CREATE", its parameters,
Both the type and quantity must correspond to the ejbcreate () method in the bean class.
 
If the home interface of the object bean also contains the find () method
Each home interface extends the javax. EJB. ejbhome interface. The following code shows the definition of the javax. EJB. ejbhome interface.
 
Public interface ejbhome extends java. ami. Remote ()
{
// You can use a handle to delete an Enterprise JavaBean instance.
Void remove (handle) throws java. RMI. RemoteException, removeexception;
// The second is to delete an Enterprise JavaBean instance by deleting the primary key.
Void remove (Object primaryker) throws java. RMI. RemoteException, removeexception;
// Returns the metadata interface of the enterprise javabeand object. This interface allows the customer to obtain the metadata information of the Enterprise JavaBean.
Ejbmetadate getejbmetadata () throws RemoteException;
// Provides methods to obtain the javax. EJB. ejbhome interface, home class, remote interface, and primary key.
Homehandle gethomehandle () throws RemoteException;
}
 
Because the home interface includes the definition of one or more create () methods. The factory that becomes a session bean. For every create () method, EJB defines the following naming rules:
1. The returned value is the remote interface type of the Session Bean.
2. The method name can only be create ()
3. Each ejbcreate () method in the Session Bean class must have a create () method corresponding to it, and the parameter type and quantity must be consistent.
4. java. RMI. RemoteException and javax. RMI. createexception must be thrown.
5. Parameters of the CREATE () method are used to initialize the new session bean object.

The following are different create () methods for 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;
Ejbmetadata getejbmetadata () throws RemoteException
Homehandle gethomehandle () throws RemoteException;
}

Home interface of Session Bean
As we have said before, a session bean has only one customer. This means that when a customer creates a session, this session bean is created for this customer.
Exist.
The create () method of the home interface of the Session Bean. The EJB specification defines one or more create () methods.
1. The returned value is the remote interface type of the Session Bean.
2. The method name can only be create ()
3. Each ejbcreate () method in the Session Bean class must have a create () method corresponding to it, and the parameter type and quantity must be consistent.
4. java. RMI. RemoteException and javax. RMI. createexception must be thrown.
5. Parameters of the CREATE () method are used to initialize the new session bean object.

========================================================== ========================================================== ======================================

The home interface of the Session Bean does not define the finder method to locate the object, because stateful session beans can only be used by customers who create them.
It is unnecessary or not allowed to locate a session bean created by yourself.

========================================================== ========================================================== ==================================

Home interface of object Bean
The object bean is the same as the beande home interface, but there is only one more finder () method,
In this way, the customer can locate and use the object of the entity bean, and the operations of the finder are required, because the Entity Bean exists for a long time and can be
Multiple customers use it. For most applications, the Entity Bean instance exists. The customer only needs to find one for use.
 

Define the primary key:
The home interface of an entity bean must provide a default finder method: finderbyprimarykey, which allows the customer to pass the primary key
The Entity Bean method has only one unique parameter: the "primary key". The Return Value Type of the method is the remote interface type of the object beanz.
The type of the primary key extends any Java type of the Java object type. In the configuration descriptor, you must tell the container the type of the primary key.
 
* ===================================================== ========================================================== ====================================
 
According to the definition, the findbyprimarykey () method always returns a single entity object, while other finder () methods can return
Set
 
* ===================================================== ========================================================== ====================================

The following is a findbyprimary () method.
Findbyprimary (key)
Throws java. RMI. RemoteException. finderexception;

The home interface can also define other finder () methods. Each finder () method must have a corresponding implementation in the Enterprise JavaBean class.
Each finder method must comply with the following conventions:

1. The return type is the remote interface type.
2. It must start with "find" and start with "ejbfind" in the object Bean class.
3. java. RMI. RemoteException and javax. EJB. finderexception must be thrown.
4. The throws clause in the home interface must be opposite to the throws clause in the ejbcreate () method of the object Bean class.


Live in the ideal and fly freely

 

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.