Develop Enterprise JavaBeans

zhaozj2021-02-16  61

Develop Enterprise JavaBeans

CHINAComputerworld

Java (2001-11-01 23:06:39)

Now, from the following aspects, introduce the development of Enterprise Bean:

The main key steps for developing EJBs. How to use JBuilder. Use other development tools outside JBuilder. How to develop a detailed detail of EneterPrise Beans. The current development program is limited.

The main steps of developing EJB:

In general, the entire development step (development, configuration, assembly) includes the following aspects:

Development: First, you must define three classes: Bean class itself, bean's local (HOME) and remote) interface class.

Configuration: The configuration includes generating a configuration descriptor - this is an XML file that declares the attribute of Enterprise Bean, binds the bean's class file (including the stub file and the Skeleton file). Finally, put these configurations in a JAR file. It is also necessary to define environmental properties in the configurator.

Assembly application: Includes Enterprise Beans to the Server server to test the connection of each layer. The programmapper combines several Enterprise Beans with other components (servlet, applet, script, etc.). Combine into a complete application. Or combine several Enterprise Beans into a complex ENTERPRISE BEAN.

Manage Enterprise Bean.

Second, use JBuilder:

JBuilder and EJB Container are seamlessly connected. JBuilder and Inprise application servers include all the tools for developing and configuring Enterprise Beans, and the required libraries:

Run and manage the container of Enterprise Bean.

Name service.

Transaction service.

Java database.

Develop the API required for Enterprise Beans.

A enhanced Java-to-IIOP compiler, support type, and RMI signals.

JBuilder also provides a tool and wizard for fast development applications Enterprise Beans. By simple and intuitive steps, the wizard helps you build an Enterprise Bean. I set some default values, generated the template of the bean. Only, we can add our own application logic.

JBuilder also provides an EJB interface generation wizard. The wizard generates a Remote interface and a Home interface based on the public method of Enterprise Bean. JBuilder also provides a wizard of a configurator to help us build an XML descriptor file step by step. And generate the Stubs to a JAR file.

Third, using an integrated environment outside JBuilder:

If you use other integrated environments (IDEs). To determine the container tools that integrated analog environment IDE. Also verify that the IDE supports the corresponding version of the EJB specification, and it is necessary to determine if it is correctly supporting the EJB API.

To determine the version of the JD to the supported EJB container. You can determine the version of the support JDK supported by the EJB container by checking the installation instructions of the Inprise.

When configuring Enterprise Beans, you must use the tools provided by the INPRISE application server. These tools can edit and modify the INPRISE configuration descriptor provided by third-party agents. It is also possible to verify the configuration descriptor to verify the source code of the bean.

Fourth, Enterprise Beans Development:

This section we mainly discuss the provider of Enterprise Beans to develop the Enterprise Bean must complete. These tasks include:

Define and write Enterprise Bean class: This is the implementation of the Enterprise Bean internal application logic. Write the remote Remote interface class for Enterprise Bean.

Write the local Home interface class for Enterprise Beans.

Description Primary key, primary key class is only required for Entity Beans. Specify the name of the primary key in the Configuration Descriptor of Enterprise Bean.

The Enterprise Beans provider defines the remote (HOME) interface, which implements the Enterprise Bean class itself. The client invoke Enterprise Bean implementation interfaces in the Remote Interface. The HOME interface provides a way to generate and locate the Remote interface instance.

In the implementation of the Enterprise Bean itself, there is no formal connection between the local home interface, and the remote Remote interface (such as inheritance relationship). However, the method in three classes must be observed in the specification defined in EJB. For example: You declare an application method or application logic in Enterprise Bean. This method is also declared in the Remote interface of Beans, then these two places must be the same name. There must be at least one crete () method in the implementation of the bean: ejbcreate (). However, there can be multiple CREATE () methods with different parameters. In the Home interface, you must also have the same method definition (the number of parameters is the same). EjbcReate () method returns a persistent object for container management. They all returns a host key value for container management persistence. However, the type of return value in the corresponding CREATE () method of Home is the Remote interface.

Note: The EJBCREATE () method of the implementation of the entity bean is a bit different. Entity beans may not define the ejbcreate () method. If the entity is applied to the database only through the application or through the database management program, the entity bean omits the EJBCREATE () method. The value returned by EJBCREATE () is the primary key type. If the EJBCREATE () method is the method of managing persistence of persistence, its return value is NULL type. If the entity bean implements the persistence of bean management, the EJBCREATE () method is the primary key type. In the future, we will discuss them in detail.

The Entereprise Bean provider defines the semantics of Enterprise Beans. The task of the container is to combine the Home interface, Remote interface, and Enterprise Beans. It is guaranteed that the Remote interface and the bean implementation class are corresponding when compiling and runtime.

Enterprise Bean inheritance:

Enterprise Bean implements classes, Remote interfaces, and HOME interfaces inherited from different base classes. The HOME interface is inherited from javax.ejb.ejbhome. The REMOTE interface is inherited from javax.ejb.ejbObject. The base class of the Remote and Home interface is javax.rmi.remote.

A session bean must realize the base class javax.ejb.sessionBean. The entity bean must realize the base class javax.ejb.entiybean. These EJB base classes are inherited from Javax.ejb.EnterpriseBean. Javax.ejb.EnterpriseBean is inherited from java.io.serializable.

The figure below shows the relationships between them. Here, CartBean can be an entity bean or a session bean. Its home interface is CartHome, the Remote interface is Cart. (slightly)

REMOTE interface:

Every Enterprise Bean must have a Remote interface. The Remote Interface defines the logical operation that the application specifies the customer call. These are some of the procedures (development, configuration, assembly) including the following aspects:

Development: First, you must define three classes: Bean class itself, bean's local (HOME) and remote) interface class.

Configuration: The configuration includes generating a configuration descriptor - this is an XML file that declares the attribute of Enterprise Bean, binds the bean's class file (including the stub file and the Skeleton file). Finally, put these configurations in a JAR file. It is also necessary to define environmental properties in the configurator.

Assembly application: Includes Enterprise Beans to the Server server to test the connection of each layer. The programmapper combines several Enterprise Beans with other components (servlet, applet, script, etc.). Combine into a complete application. Or combine several Enterprise Beans into a complex ENTERPRISE BEAN.

EJBHOME base class:

Each HOME interface extends the Javax.ejb.ejbHome interface. The following code shows the definition of the javax.ejb.ejbhome interface:

Package javax.ejb;

Public Interface Ejbhome Extends Java.rmi.Remote () {

Void Remove (Handle Handle) throws java.rmi.RemoteException, RemoveException

Void Remove (Object PrimaryKey) throws java.rmi.remoteException, RemoveException;

Ejbmetadata getejbmetadata () throws remoteException;

HOMEHANDLE GETHOMEHANDLE () THROWS RemoteException;

}

Here, two remove () methods are provided to delete instances of Enterprise Beans. The first Remove method is to remove an instance of an Enterprise Bean through a handle. The second REMOVE method deletes an instance of an Enterprise Bean through a primary key.

In numerous Enterprise Bean instances, the handle is uniquely identified an instance. A handle has the same lifetime as the Enterprise Bean it references. Considering an entity object, the customer can re-obtain an instance of the corresponding Enterprise Bean through a handle. A handle can correspond to multiple instances of an Enterprise Bean object. For example, even if the host where the Enterprise Bean object is located, or the ENTERPRISE BEAN object moves between different machines, the handle is still valid. The handle here is a Serialized handle, a reference to a CORBA object serialized with characters in CORBA.

The second REMOVE operation in the EJBHOME interface determines the Enterprise Bean to be deleted through its primary key. The primary key can be any type of the Java Object class, however, you must implement Java serializable interface. The primary key is the main method of identifying the entity bean. Typically, the primary key is a keyword in the database, uniquely defining data represented by entity beans. Method GeTejbMetadata () returns the Metadata interface of the Enterprise Bean object. This interface allows customers to get metadata information for Enterprise Beans. When developing tools to compile link applications, or when configuring tools to configure, Metadata information may be used. Javax.ejb.ejbmetata interface provides a method of obtaining a javax.ejb.ejbhome interface, home class, remote interface, and a primary key. A iSSSSON () method is also provided to determine that the object in which this HOME interface is session bean or an entity bean. The isStateLessSession () method indicates that this session bean is status or stateless. The following code shows the code for the defined section of the javax.eb.ejbmetadata interface.

Public Javax.ejb;

Public interface ejbmetata {

Ejbhome getEjbhome ();

Class gethomeInterfaceClass ();

Class GetRemoteInterfaceClass ();

Class getPrimaryKeyClass ();

Boolean issession ();

Boolean isStateLesssSession ();

}

HOME interface for session beans:

In the front we said, a session bean has only one customer. That is to say, when a customer creates a session bean, this session bean exists for this creation of its customers (here, we refer to a stateful session bean. Current session beans because they don't keep The state of the session, so you can multiple customers).

Since the Home interface includes a definition of one or more Create () methods, it becomes a factory for session beans. For each Create () method, the EJB specification defines the following naming conventions:

Its return value is the type of Remote interface of the session bean.

The name of the method can only be CREATE ().

Every ejbcreate () method in the session bean class must have a CREATE () corresponding.

The type and quantity of the parameters of each CREATE () method must correspond to the EJBCREATE () method in the session bean class.

Methods must throw java.rmi.RemoteException.

Methods must throw javax.rmi.createexeption.

The parameter of the CREATE () method is used to initialize the new session bean object.

The following code shows the different CREATE () methods of a session bean object, where the parts must be displayed:

Public interface atmhome extends javax.ejb.ejbhome {

ATM Create () throws java.rmi.remoteException, javax.ejb.createException;

ATM Create (Profile PreferredProfile)

Throws Java.rmi.Remoteexeption, Javax.ehrows Java.rmi.RemoteException, RemoveException

Ejbmetadata getejbmetadata () throws remoteException;

HOMEHANDLE GETHOMEHANDLE () THROWS RemoteException;

Here, two remove () methods are provided to delete instances of Enterprise Beans. The first Remove method is to remove an instance of an Enterprise Bean through a handle. The second REMOVE method deletes an instance of an Enterprise Bean through a primary key.

In numerous Enterprise Bean instances, the handle is uniquely identified an instance. A handle has the same lifetime as the Enterprise Bean it references. Considering an entity object, the customer can re-obtain an instance of the corresponding Enterprise Bean through a handle. A handle can correspond to multiple instances of an Enterprise Bean object. For example, even if the host where the Enterprise Bean object is located, or the ENTERPRISE BEAN object moves between different machines, the handle is still valid. The handle here is a Serialized handle, a reference to a CORBA object serialized with characters in CORBA. The second REMOVE operation in the EJBHOME interface determines the Enterprise Bean to be deleted through its primary key. The primary key can be any type of the Java Object class, however, you must implement Java serializable interface. The primary key is the main method of identifying the entity bean. Typically, the primary key is a keyword in the database, uniquely defining data represented by entity beans.

Method GeTejbMetadata () returns the Metadata interface of the Enterprise Bean object. This interface allows customers to get metadata information for Enterprise Beans. When developing tools to compile link applications, or when configuring tools to configure, Metadata information may be used. Javax.ejb.ejbmetata interface provides a method of obtaining a javax.ejb.ejbhome interface, home class, remote interface, and a primary key. A iSSSSON () method is also provided to determine that the object in which this HOME interface is session bean or an entity bean. The isStateLessSession () method indicates that this session bean is status or stateless. The following code shows the code for the defined section of the javax.eb.ejbmetadata interface.

Public Javax.ejb;

Public interface ejbmetata {

Ejbhome getEjbhome ();

Class gethomeInterfaceClass ();

Class GetRemoteInterfaceClass ();

Class getPrimaryKeyClass ();

Boolean issession ();

Boolean isStateLesssSession ();

}

HOME interface for session beans:

In the front we said, a session bean has only one customer. That is to say, when a customer creates a session bean, this session bean exists for this creation of its customers (here, we refer to a stateful session bean. Current session beans because they don't keep The state of the session, so you can multiple customers).

Since the Home interface includes a definition of one or more Create () methods, it becomes a factory for session beans. For each Create () method, the EJB specification defines the following naming conventions:

Its return value is the type of Remote interface of the session bean.

The name of the method can only be CREATE ().

Every ejbcreate () method in the session bean class must have a CREATE () corresponding.

The type and quantity of the parameters of each CREATE () method must correspond to the EJBCREATE () method in the session bean class. Methods must throw java.rmi.RemoteException.

Methods must throw javax.rmi.createexeption.

The parameter of the CREATE () method is used to initialize the new session bean object.

The following code shows the different CREATE () methods of a session bean object, where the parts must be displayed:

Public interface atmhome extends javax.ejb.ejbhome {

ATM Create () throws java.rmi.remoteException, javax.ejb.createException;

ATM Create (Profile PreferredProfile)

Throws Java.rmi.Remoteexeption, Javax.ehrows Java.rmi.RemoteException, RemoveException

Ejbmetadata getejbmetadata () throws remoteException;

HOMEHANDLE GETHOMEHANDLE () THROWS RemoteException;

}

Here, two remove () methods are provided to delete instances of Enterprise Beans. The first Remove method is to remove an instance of an Enterprise Bean through a handle. The second REMOVE method deletes an instance of an Enterprise Bean through a primary key.

In numerous Enterprise Bean instances, the handle is uniquely identified an instance. A handle has the same lifetime as the Enterprise Bean it references. Considering an entity object, the customer can re-obtain an instance of the corresponding Enterprise Bean through a handle. A handle can correspond to multiple instances of an Enterprise Bean object. For example, even if the host where the Enterprise Bean object is located, or the ENTERPRISE BEAN object moves between different machines, the handle is still valid. The handle here is a Serialized handle, a reference to a CORBA object serialized with characters in CORBA.

The second REMOVE operation in the EJBHOME interface determines the Enterprise Bean to be deleted through its primary key. The primary key can be any type of the Java Object class, however, you must implement Java serializable interface. The primary key is the main method of identifying the entity bean. Typically, the primary key is a keyword in the database, uniquely defining data represented by entity beans.

Method GeTejbMetadata () returns the Metadata interface of the Enterprise Bean object. This interface allows customers to get metadata information for Enterprise Beans. When developing tools to compile link applications, or when configuring tools to configure, Metadata information may be used. Javax.ejb.ejbmetata interface provides a method of obtaining a javax.ejb.ejbhome interface, home class, remote interface, and a primary key. A iSSSSON () method is also provided to determine that the object in which this HOME interface is session bean or an entity bean. The isStateLessSession () method indicates that this session bean is status or stateless. The following code shows the code for the defined section of the javax.eb.ejbmetadata interface.

Public Javax.ejb;

Public interface ejbmetata {

Ejbhome getEjbhome ();

Class gethomeInterfaceClass ();

Class getRemoteInterfaceClass (); Class getPrimaryKeyClass ();

Boolean issession ();

Boolean isStateLesssSession ();

}

HOME interface for session beans:

In the front we said, a session bean has only one customer. That is to say, when a customer creates a session bean, this session bean exists for this creation of its customers (here, we refer to a stateful session bean. Current session beans because they don't keep The state of the session, so you can multiple customers).

Since the Home interface includes a definition of one or more Create () methods, it becomes a factory for session beans. For each Create () method, the EJB specification defines the following naming conventions:

Its return value is the type of Remote interface of the session bean.

The name of the method can only be CREATE ().

Every ejbcreate () method in the session bean class must have a CREATE () corresponding.

The type and quantity of the parameters of each CREATE () method must correspond to the EJBCREATE () method in the session bean class.

Methods must throw java.rmi.RemoteException.

Methods must throw javax.rmi.createexeption.

The parameter of the CREATE () method is used to initialize the new session bean object.

The following code shows the different CREATE () methods of a session bean object, where the parts must be displayed:

Public interface atmhome extends javax.ejb.ejbhome {

ATM Create () throws java.rmi.remoteException, javax.ejb.createException;

ATM Create (Profile PreferredProfile)

Throws java.rmi.Remoteexeption, Javax.ejb.createException;

}

Note that the HOME interface of the session bean does not define the Finder method to locate the object. Because a stateful session bean just uses customers to create its customers. If you are not a session bean you create yourself, it is not necessary to locate such a session bean.

Home interface:

Like the HOME interface of the session bean, the Home interface of the entity bean provides a method for CREATE (). In addition, the entity

The Bean's Home interface also provides a Finder method, so that customers can locate and use entity beans objects. The Finder operation is necessary because the entity bean is living for a long time and can be used by multiple customers. For most applications, the instance of entity beans exists, and the customer only needs to be used to use it.

A HOME interface of an Entity Bean must provide a default Finder method: FinderbyPrimary (PrimaryKey). This method allows customers to locate Entity Beans through the primary key. The method has only one unique parameter: master key. The return value type of the method is the type of Remote interface of the entity bean. The type of primary key can be any Java type that extends the Java Object type. In the configuration descriptor, you must tell the type of the main key of the container. Note that according to the definition, the FindByPrimaryKey () method always returns a single Entity object. And other Finder () methods can return the collection of Entity objects.

Below is the definition of the FindByPrimaryKey () method:

FindbyPrimaryKey ( Key) THROWS JAVA.RMI.RemoteException, FINDEREXCEPTION;

The HOME interface can also define a different finder () method. Each Finder () method must have a corresponding implementation in the Enterprise Bean class. Every Finder method must meet the following agreement.

The type of return value is the Remote Interface type, or the Finder method can return more than one Entity object, or a collection type of the Remote interface as the content type. A effective Java collection type is a java.util.enumerative interface (JDK1.1 specification) or java.util.collection interface (Java 2 specification).

The Finder method always starts with the prefixed. Inside the entity bean class begins with the prefix EJBFIND.

The java.rmi.RemoteException exception must be thrown.

You must throw javax.ejb.findEREXCEPTION exception. The throws clause of the Throws clause in the Home interface and the EJBCREATE () method of the entity bean class must also correspond.

转载请注明原文地址:https://www.9cbs.com/read-17604.html

New Post(0)