WEBLOGIC-based EJB study notes (2)

xiaoxiao2021-03-06  58

WEBLOGIC-based EJB study notes (2)

Advanced course for editing entity bean

1. How to develop a key class

The primary health class of EJB mainly uses the unique identifier in a persistent storage and EJB container.

Usually the field of the primary care class is directly mapped to the primary field in the database.

If the primary care is only consisting of a single entity bean field. And its data type is a basic Java class. If String, the Bean author does not have to develop a custom primary care class.

Just need to specify the name and master field of the class in the configuration descriptor

If the primitive is shot to a user-defined type, or mapping to multiple fields, the Bean author must write a customized core class.

The main health class must implement java.io.serializable, and include a master field.

For the CMP, the field name must match the corresponding primary field name in the entity bean, which will enable the EJB container to assign appropriate CMP fields to the corresponding fields in the primary care class.

2. Implement a Hashcode () method

The principle of the HashCode () method is to generate and return an integer using the mainfield, suitable for processing, and returns an integer. This generated integer is called a hash code, used as an index of the table.

For a given master, the return value of the HashCode () method should always be the same. Frequently: Perform "different or" operation.

3. Implement Equals () method

Correctly implementing the equals () method also requires certain skills. All the first lines of any equals () method should check if the transferred reference is "this", check Equals ()

Whether the method is targeted for your own calls. Usually: When the container has a master object, she wants to check if the primary object is existing in the data structure.

Next, the equals () method needs to check the type of the passed master class. If the primary care class is a Trunk (FINAL), you can use InstanceOf to make a simple check.

Otherwise, the passing parameters may be a subclass of a primary care. In this case, the equals () method must use getClass.Equals to ensure that the type of the class is matched.

It is recommended to use the ultimate class with the primary health class. (INSTANCEOF efficiency)

Finally, the equals () method needs to be a value of the object to be passed. If all values ​​are the same, the indicator is also the same.

Note: To compare the raycode first.

4 Inheritance and heterogeneity of entity beans

Entity Beans can utilize Java inheritance and heterogeneous characteristics.

5. Inherited restrictions

Although the EJB specification allows the inheritance between components, some subtle rules have restricted how to design and implement one inheritance EJB.

EJB rule requirements, the remote interface returned by the CREATE () method of the local interface cannot be a subclass, nor is it superclass. EjBreate () method of entity bean is also

Must return to the primary type, nor can it be a subclass, and it is not a superclass.

Similar FindByPrimaryKey () methods must use a primary type as a parameter to return a remote interface.

These requirements limit the implementation of the Bean author's inheritance.

6. Inheritance and heterogeneous design patterns

Note: Entity beans with inheritance and heterogeneity characteristics are important to determine which properties need to be used in general.

7. Inheritance of the interface

With the inheritance of the Bean class, the Bean author only needs business methods in one place, and other entity beans can share the methods in the class.

8 use multiple Bean classes

Create a basic interface for local and remote interfaces, not the only way to achieve heterogeneous shares. Another common practice is

Use equivalent local and remote interfaces, but use different Bean classes to implement the business methods.

This approach is similar to using an interface with several different implementations.

Benefits: Customers don't know or at all regardless of which implementation is being used, the client only operates the interface.

9. Entity Bean and Lock

Entity beans are not reusable or multi-threaded components, each entity bean instance does not have multi-threaded control.

The method in the primary bean class is not synchronized.

Entity bean instances cannot be multithreaded, so the EJB container must serve all container methods and business methods serially.

This means that when the business method is being executed, the EJB container cannot call other methods, such as the ejbpassivate () method.

Concurrent control:

One approach is to activate entity bean instances for each transaction. Concurrently processed by the access lock of the database. One way is that each masterwork only maintains an entity bean instance, so only one transaction can access entity beans. once

The previous transaction is submitted or rolled up to allow another transaction to use this entity bean instance.

Concurrent control strategy:

Database concurrency control:

Unless specifically, the default database should be used to control.

Row resistance concurrent control:

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

New Post(0)