EJB design mode 2

zhaozj2021-02-11  158

Design mode 2

In order to avoid the shortcomings of design model 1, we introduce the package

Value Object of the Entity Bean value field. Value Object,

In some languages, it is a structural type because they

Very similar to CORBA's structural type.

Value Object Code Snippet for Company

Public Class CompanyStruct IMPLEMENTS

Java.io.serializable {

Public Integer Comid; // Primary Key

Public String COMNAME;

Public String Comdescription;

Public java.sql.timestamp mutationdate;

}

Value Object Code Snippet for Employee

Public Class Employeestruct Implements

Java.io.serializable {

Public Integer Empid; // PRIMARY Key

Public Integer Comid; // Foreign Key

Public String EmpfirstName;

Public String Emplastname;

Public java.sql.timestamp mutationdate;

}

Now, the company and the ENTITY BEAN can use one of the above structural types.

A parameter of ejbcreate (). Since this structure encapsulates all fields of Entity

Value, Entity Bean only needs a getData () and setData () method.

Operate all fields.

Code snippet for an entry bean's create ()

Public Integer Ejbcreate (Companystruct Struct) Throws

CreateException {

this.comid = Struct.comID;

This.comName = struct.comName;

THIS.COMDESCRIPTION = Struct.ComDescription;

THIS.MUTATIONDATE = Struct.MutationDate;

Return NULL;

}

Code snippet for an entry bean's getdata ()

Public companyStruct getdata () {

Companystruct result = new companyStruct ();

Result.comID = this.comid;

Result.comName = this.comName;

Result.comDescription = this.comdescription;

Result.mutationdate = this.mutationDate;

Return Result;

}

Code snippet for an entry bean's setdata ()

Public void setdata (Companystruct Struct) {

This.comName = struct.comName;

THIS.COMDESCRIPTION = Struct.ComDescription;

THIS.MUTATIONDATE = STRUCT.MUTATIONDATE ;;

}

Use a separate GET () and set () method to operate different fields in the design mode 1.

In design mode 2, we avoid this situation and only need a remote call.

Yes. Now, only one transaction operates all the data through a remote call. In this way, we avoid most of the shortcomings of design model 1, in addition to establishing Bean

The relationship is outside the relationship.

Although setData () methods can assign all fields, Borland Appserver

Provides a smart update feature, only the modified field is rewriting

According to the library, if there is no field being modified, the EJBStore () method will be skipped.

The Borland Programmer Development Guide (EJB) has a more detailed description.

Similarly, there is such a repetitive code between Entity Beans and Struct, such as

Field declaration. This means that the modification of any database table structure can cause

Entity Beabn and Struct changes, which makes synchronous Entity and Struct become

Difficult up.

A small improvement can avoid this from a certain extent,

That is to call the setData () method in the ebcreate () method, which can eliminate one

Some redundant code.

Code snippet for an entry bean's create ()

Public Integer Ejbcreate (Companystruct Struct) Throws

CreateException {

this.comid = Struct.comID; // SET The PRIMARY Key

SetData (STRUCT); // This Removes Some Redundant Code

Return NULL;

}

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

New Post(0)