EJB design mode 4

zhaozj2021-02-11  154

Design mode 4

In the design mode 3 we see how to make the bean from Struct

The grouped water and all fields can be defined as a CMP field. Here, we can

Reduce the amount of code in further correcting the implementation of setData () and getData ().

We add a method for this Structure.

Value Object Code Snippet for Company

Public Class CompanyStruct IMPLEMENTS

Java.io.serializable {

Public Integer Comid;

Public String COMNAME;

Public String Comdescription;

Public TimeStamp MutationDate;

Public void copyfrom

Comid = struct.comid;

COMNAME = Struct.Comname;

COMDESCRIPTION = Struct.comDescription;

MutationDate = struct.mutationdate;

}

}

Since the entry bean is inherited from Struct, the implementation class in Bean

The same can be referenced in the CopyFrom () method, of course, it must be noted that

This CopyFrom () method is not a business method, it doesn't need to be in Bean

Remote interface is exposed to the caller.

Now, getData () and setData () methods can simplify further simplification.

Code snippet for an entry bean's getdata ()

Public companyStruct getdata () {

Companystruct result = new companyStruct ();

Result.copyfrom (this);

Return Result;

}

Here, THIS is incorporated into CopyFrom (). Because of ENTTITY Bean

Inheriting from Struct, so this entitty bean can be used as a

Struct is incorporated.

The EJB container does not agree with the THIS pointer as a parameter because of two controls

An instance of a BEAN in the thread can also cause a transaction conflict. But things

In fact, we did not violate this principle because we didn't

The reference to the BEAN transmits this and does not reference any ways that may cause a transaction conflict.

Code snippet for an entry bean's setdata ()

Public void setdata (Companystruct Struct) {

this.copyfrom (struct);

}

Similarly, the above method assigns the value of the Stru to ENTTITY Bean.

This implementation is an Entity Bean that maps to have a lot of columns.

The advantage of the method is that the code of the bean implements the class is very simple. This setting

The meter is greatly enhanced to make the code and its streamline, readability and maintainability.

All modifications to any database only need to modify the Struct as the base class, while

Don't need to modify the BEAN's code. Separate this change from struct,

The deployment descriptor needs to be modified when the CMP field changes. This makes it

It is better to adapt to the design changes.

Here, there is still no relationship between the bean, which will be solved in the design mode 5.

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

New Post(0)