tailieunhanh - Patterns in JavaTM, Volume 3 Java Enterprise Java Enterprise Design Patterns phần 10

Ví dụ mã cho các mô hình Retrieval Lazy là một tổ chức lớp học được đặt tên đó là từ một khuôn khổ sử dụng các lớp mô hình tổ chức kinh doanh realworld. Tổ chức lớp học công cộng mở rộng thực hiện TaxExemptIDOwner PhysicalEntity, | 442 Chapter Nine CODE EXAMPLE The code example for the Lazy Retrieval pattern is a class named Organization that is from a framework that uses the class to model real-world business organizations. public class Organization extends PhysicalEntity implements TaxExemptIDOwner PersistablelF TransactionCommittedListener . The entity that is responsible for the accounts items measurements etc. that this organization uses. private ResponsibleEntity responsibleEntity This Organization class has an attribute called responsibleEntity. Its responsibleEntity attribute is managed using the Lazy Retrieval pattern. When objects responsible for the persistence of Organization objects retrieve an Organization object they do not set its responsibleEntity attribute. Instead they set an Organization object s responsibleEntityId attribute to the object identifier of the object that is the value of the Organization object s responsibleEntity attribute. If responsibleEntity is null and idIsSet is true then use this id to fetch the ResponsibleEntity object that will be its value. private long responsibleEntityId If an attribute of an object is another object then the natural way to indicate that the value of the attribute has not been set is for its value to be null. Because responsibleEntityId is a long there is no natural way to indicate that the value of responsibleEntityId has not been set. One way of indicating that the value of responsibleEntityId has not been set is to reserve a value such as -1 for that purpose. If you have to assume that every possible value of responsibleEntityId may be used then reserving a value is not an acceptable solution. The Organization class uses a separate boolean variable called responsibleIdIsSet to indicate that the value of responsibleEntityId has not been set. true when an ID is passed to the setResponsibleEntity method. private boolean responsibleIdIsSet false Database Patterns 443 Return the responsible organization that governs this entity or .

TỪ KHÓA LIÊN QUAN