Add, deletion, and modification of objects with object type attributes in distributed environments

zhaozj2021-02-16  69

Add, deletion, and modification of objects with object type attributes in distributed environments

1. Problem description

To discuss the problem, you must first discuss the problem. The following is a description we have to discuss. Note that we don't discuss the Marshal and Unmarshal problems when subject transmission, in summary, the object can be transmitted on the network (such as through RMI or WebServices, etc.).

1.1 problem

Sometimes the logical structure of the object is more complicated. It not only has the basic type of the character, the character string, but also contains the properties of the object type. For such objects in a distributed environment, the object is added, deleted, and modified. .

1.2 Various elements that need to be considered

For this issue, there are several aspects to consider [K1]

l From the perspective of business logic, since such objects are a unit that the application should process, the operation of the object should be atomic. From the perspective of user operation, it should provide the ability to operate the entire object in an interface, of course, including its lower object.

l If the server provides support, allow the client to control the transaction itself, then the client can guarantee the atomicization of the operation you do, but the server should maintain the status of this customer; and the client is between transactions (launched the transaction, but Not yet submitted or rolling) It is possible that the server has a certain complexity due to some reason to lose from the server.

l In general, in order to improve throughput and fault tolerance, the server should be as stateless.

l If the entire object information is packaged in a method call to the server, the object definition may be quite complex, or there are many redundancy (after analyzing one by one).

1.3 example

Here is an example, the Application object contains the lower object parameter, as shown below

Note This chart is only used to represent the relationship between the object, is not an accurate definition of an object.

1.4 difficult point

When such objects are added or deleted, the problem is not large. The problem is that after the user has modified the underlying nested object of the object, what should be changed to the server, and the server should extract the change information of the object and update the change to the database.

2. Optional solution

For this issue, we have the following implementation methods, and the following analysis is analyzed.

2.1 Split the operation of the object

We can split the operation of the object on the user interface. Each method calls only a part of the object, or is the basic information of the object, or the lower object. At this point, the object itself defines basic information, and the lower object is obtained by calling the server, as the following pseudo code (Java style):

// Parameter class definition

Class parameter {

Private string id;

PRIVATE STRING NAME;

Private string description;

/ / Omitted Getter and setter method

}

// Application class definition

Class Application {

Private string id;

PRIVATE STRING NAME;

Private string description;

PRIVATE STRING DEFINITION;

/ / Omitted Getter and setter method

}

// The method defined on the server, this is a slightly possible abnormality

..................

Public Application [] getApplications ();

Public void addapplication; public void updateApplication (Applicaton APP);

Public void deleteApplication (Application APP); // or only ID

Public parameter [] getParamForapp (String AppI);

Public AddParamToApp (String Appid, Parameter Param);

Public UpdateParamForapp (String AppID, Parameter Param); // May not be included in AppID

Public deleteParamFromapp (String Appid, Parameter Param); //

..................

2.1.1 Advantages

l Logic is clear, it is very simple to achieve, and each operation of the user can be reflected, and there will be inconsistent data inconsistency.

2.1.2 Disadvantages

l The large number of small particle size is defined on the server interface.

l Interaction with the server frequently, only a small amount of information is transmitted each time.

l Disconnecting a logical object to people, forcing users to do multiple operations, unfriendly.

2.2 Delete subordinates and then reinsert

Since the user is concerned with the results, we only guarantee that the state of the object is that the status of the object is the state of the user, and the user will not care about how we do it. So, we can define objects to meet its logic definition. When you need to update the object, only the basic information of the object is only available, and the next object is taken first, then remove all the next object, then re-generate it according to the incoming information. method. Such pseudo code:

// Parameter class definition

Class parameter {

Private string id;

PRIVATE STRING NAME;

Private string description;

/ / Omitted Getter and setter method

}

// Application class definition

Class Application {

Private string id;

PRIVATE STRING NAME;

Private string description;

PRIVATE STRING DEFINITION;

Private parameter [] Params

/ / Omitted Getter and setter method

}

/ / Defined on the server

..................

Public Application [] getApplications ();

Public Void Addapplication (Application APP);

Public Void UpdateApplication (Applicaton APP);

Public void deleteApplication (Application APP);

..................

With this method, the client temporarily maintains the state of the object changes, where the server side will be less, but the user's operation can not be reflected immediately, and the work that the user does not have the job is lost; for example, the system There is already a name for appone Apphan, and the user modifies a different Name property of an appropriate Application to AppONE, and makes many other modifications to this Application (such as adding a lot of parameters), if the business is not allowed to have the same name on the same name The system can give a hint when the user determines that it is submitted to the modification, tells the user that the name cannot be used, the user can change the name attribute to the appropriate value after the user can be submitted, which does not make other modifications made to Application Lost. 2.2.1 Advantages

l Keep the logical integrity of objects

l Logic is clear, simple, and similar to the object's modification and add objects.

2.2.2 Disadvantages

l Although there will be a large number of small particle size methods, many redundant information may be transmitted online. For example, only one of the DESCRIPTION properties of a 10 paramater in an application, the actual modification may only have more than a dozen bytes, but the information of the entire object is transmitted online.

l The intensive operations for the database may greatly reduce the application's throughput. If the object type is more attribute, the object nested hierarchy is relatively deep (that is, the database involves multiple tables in the database), the server locks multiple tables when the database is operated, other access requests for related tables (possibly from other Client or other applications) is blocked, resulting in a significant reduction in efficiency.

l In a particular case, this method may cause complex processing or simply incapable, for example, if there is any other place in the app references Parameter objects, the foreign key is generally defined in the database. At this time, the update of parameter is reasonable. However, the deletion of Parameter will fail so that the update operation fails.

2.3 Marking all related objects increase, delete, and changing status

We can mark the current state of all related objects, providing a 'mode of incremental update. At present, there are data operation controls provided in many development environments, generally have Batch mode, which can cache data for data, and then update to the database at a real commit, take PowerBuilder's DataWindow as an example, there are four buffers inside. (Primary , deleded, etc.), and each line data corresponding to the status record (New, Modified, etc.), we can also use a similar way. Such pseudo code:

Class parameter {

Private string id;

PRIVATE STRING NAME;

Private string description;

Private int status; // 0: None, 1: New; 2: Modified, 3: Deleted ETC.

/ / Omitted Getter and setter method

.......................... ...

/ * Use this method to get xml format string which indexDate information of this Object

@return a XML Format String.

* /

Public string getchangeinfo () {

}

}

// Application class definition

Class Application {Private String ID;

PRIVATE STRING NAME;

Private string description;

PRIVATE STRING DEFINITION;

Private parameter [] Params

Private parameter [] deletedParams

PRIVATE INT Status;

/ / Omitted Getter and setter method

.......................

/ * Use this method to get XML Format String Which Indicate Update Information Of this Object, Here The Information include Information of Subordinate Classes.

@return a XML Format String.

* /

Public string getchangeinfo () {

..................................

}

}

/ / Defined on the server

..................

Public Application [] getApplications ();

Public Void Addapplication (Application APP);

Public void UpdateApplication (String ChangeInfo;

Public void deleteApplication (Application APP);

..................

With this method, the definition of the object will be complex, because the object is able to indicate that there are those underlying objects being deleted, the object definition in the above example is only used, not the best definition method, for example, you can Defining another array specially stores modified Parameter et al.

Note the definition of the UpdateApplication method on the server. At this time, we can also pass a string of XML format, which indicate updated information of the object; in fact, we can certainly pass an Application object, so we will not The second method does not work, because the server can get those underlying objects from the object, those that really should be deleted. But if only a simple property of a lower object is modified, the passing of the entire object will still bring considerable redundancy. A preferred method is to pass only the necessary modification information, for information that has no changed lower object, it is not only transferred online, where it is assumed to be implemented using XML. An example of an XML is given below:

Note that the status indicated by this Application's Status refers to its basic information, and if Status is 0, it does not mean that the underlying object of the Application object has not changed. The discussion of the discuss will change, each has a clever different, and the definition of marking information and the definition of XML's Schema has a lot of flexibility.

2.3.1 Advantages

l Keep the logical integrity of objects

l There is almost no redundancy information (here almost 'is because XML tag itself is redundant information, although the amount of data is small)

l no need to operate

l If the object definition is more complex (such as defining a Prameter's raw data array), the user can even return to the object with the server without the server interaction.

l Flexible, greatly elastic, and scalability is relatively strong.

2.3.2 Disadvantages

l It is relatively complicated to implement, and there is a big bigger mistake.

3. Conclusion

Ok, analyze it, it's time to conclusion, our conclusion is that there is no conclusion ^ _ ^ called mode is also a solution for a particular problem. There have been so many classic patterns, if I just need to write a 'Hello, World' program, I will still use the pattern, that is, the above methods, we should decide to make specific choices according to the specific situation of your hand. That one.

In general, now we work in the hands, the priority is relatively short, flat, fast, we need to make things as soon as possible, so we should prefer the second method in the case of conditions permit. For the disadvantage of this method, if the size of the application is large enough, we can overcome the performance of network bandwidth and database server hardware by requesting network bandwidth and database server hardware. ^ _ ^

The third method is the most elegant solution. If you are a perfectionist, or if you want to cultivate your own scientist's quality, you can prefer this method. This method should only be used if we will use the second method that cannot be accepted using the second method.

The first method breaks the integrity of the object itself, which may be annoyed 'God', in general, not advocated, but in some application mode, it is possible to use this way, and the user has also The operating mode is often, for example, the user interface is a browser-based thin client, then this time does not have to hesitate, use this method.

End of this document

[K1] pressure factor

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

New Post(0)