Some ideas on solving critical site data and status data without persistent data

Source: Internet
Author: User

Bsscriticalcompiler design description (draft) (Overview)
-Some Ideas on solving critical site data and status data without the need for persistent data
Bearocean 2008-06-04


1. Definition of key data
2. bsscriticalcompiler
2.1. Basic Ideas/design objectives
2.1.1. criticaldata centralized definition
2.1.2. XML-based Description
2.1.3. Support both compile-time and runtime policies
3. Conclusion

 

1. Definition of key data
Some data items with minor changes usually appear in the site system.
The reason for this data will not be changed frequently is:
(1) This type of data is not required to be modified as required.
(2) This type of data is involved in the system logic on a large scale. Modifications will lead to large-scale restructuring of the system. To modify this type of data, this will lead) rebuild is required for the previous data from the Controller to the logic layer and from the database.

We usually extract two key attributes from this type of data: displayname and value, which actually mean enumeration or key-value pairs.
Common examples of such data:
Gender information, such:
Displayname: Male value: 1 (that is, the display layer shows male. In the internal logic and database, we usually store 1 to indicate that a user is male)
Displayname: female value: 2

Country/region information, such:
Displayname: China Value: 1
Displayname: US value: 2
Displayname: France value: 3
....

Status information. For example, the status of a user can be expressed:
Displayname: Activate value: 1
Displayname: Pause value: 2
Displayname: Disable value: 3
....


Such data is often hard-coded in the system, such
Display layer. The following code is displayed on the user registration page:

1 <input type = "select">
2 <option value = "1"> male </option>
3 <option value = "2"> female </option>
4 </input>

This code is also displayed on the user editing page.

For status information, such code may appear in our common logic encoding.

1if (user. State = 1 ){
2 // The user status is activated and the execution logic is
3} else if (user. State = 2 ){
4 // The user status is paused. Activate the service first.
5} else if (user. State = 3 ){
6 // execution prohibition Logic
7 }...

For country and region data, we often store them in databases.
However, if there is no need to modify, add, or delete country or region data, such data is not necessarily stored in the database.

In general, this type of data (especially the status code) is usually the key support of the entire system.
We generally do not recommend modifying this type of data in practice.
Imagine that in the system, the Code indicating the user's activation status is (INT) 1 in the database and displayed as "Activate" on the page ".
However, if we have a requirement (whether this requirement is reasonable or not), the activation code is indicated by 2, and the activation is not displayed on the page, but "normal operation" is displayed ". Where should we modify it:

Show all pages of user information
User add page
User status modification page
Modify the encoding logic of the user status (activation logic is changed to set the user status to 2)
User data stored in the past 1-> 2
....

This is a nightmare.
If you do not mention changes to such data.
Only consider adding a new State: displayname: overdue value = 4 (the system will always expand)
We find that the following parts need to be modified:
User add page
User editing page
Modify the encoding logic of the user status (add the arrears logic)
....

It is still a nightmare, and with the developer's memory, how can we ensure that all the relevant modifications have been completed during code modification? For example, we may ignore the modifications to a page.

In the past, there was a profound lesson.
When developing an HR site, we hardcoded the education level data in the system because the education level is relatively fixed.
Similar:

1 <input type = "select" name = "education" id = "education">
2 <option value = "1"> Technical Secondary School </option>
3 <option value = "2"> Senior </option>
4 <option value = "3"> technical schools </option>
5 <option value = "4"> Junior College </option>
6 <option value = "5"> undergraduate </option>
7 <option value = "6"> Bachelor's Degree </option>
8 <option value = "7"> master </option>
9 .....
10 <option value = "10"> PhD </option>
11 </input>

Such code is distributed across more than 10 pages.
When the customer proposed to add a post-doctoral program "value = 11", we began to look for more than 10 pages. In fact, it is very painful.

There is no uniform definition for this type of data. Let's define it as criticaldata)
Key data often has the following features in Web systems:
A) It does not need to be stored in the database.
B) usually participate in a large number of Logic
C) It is usually not the same, but it is very troublesome to modify/Add.
E) The common expressions in code are hard-coded/or static variables.

2. bsscriticalcompiler
The development of bsscriticalcompiler mainly proposes an idea to solve the above problems.
This enhances the scalability of the system and makes the code more elegant.

2.1. Basic Ideas/design objectives
2.1.1. criticaldata centralized definition

As described in the preceding section.
Key data definitions of the system are usually distributed in various places of the system, which is the cause of reduced scalability.
We hope there is a way to centralize the definition of key data.

2.1.2. XML-based Description
When defining critical, developers do not need to develop code directly, but write a group of XML files that are easier to read. Key data is defined and described by this set of XML files. Bsscriticalcompiler completes the specific encoding conversion or runtime dependency.
The XML description file is similar to the following:

1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <dataset id = "sex">
3 <item displayname = "" value = "1" type = "int"/>
4 <item displayname = "male" value = "2" type = "int"/>
5 </dataset>

2.1.3. Support both compile-time and runtime policies
2.1.3.1. compile-time policy

The idea of a policy during compilation is similar to model driven development)
The specific process is shown in:
 
Use this method to define the XML Key data definition file for developers.
Then, criticalcompiler is called to convert the XML Key data definition file into a more reasonable and convenient Key Data Definition source code. (Java initially considers a group of interfaces containing static variables ).
The developer depends on the generated criticaldata definition in the system. Avoid hard coding as much as possible.
If the demand changes, repeat the above process.
2.1.3.2. runtime Policy
The runtime architecture is supported as another option. Compared with the compile-time policy, the XML definition file is exactly the same as the parsing process. However, the difference is that criticalcompiler does not generate source code when parsing/compiling XML on the website (the specific time should be the website startup time. The developer code can reference key data with the dependency on criticalcomiler runtime Lib.
The biggest advantage is that you do not need to recompile the entire project to modify XML. You only need to re-deploy the XML file to the appropriate folder path and restart the web service.
As shown in:
 
3. Conclusion:
In general, this model is very simple and mainly aimed at centralized control of key data, enhancing code scalability and maintainability, and serving as an XML document defining key data, it can be used as a part of the source code (metadata ). it can also be used as a document.
This idea can be used to determine whether the LIB can actually reduce the reconstruction cost caused by web modifications. It cannot be determined yet. At present, it is mainly used as a design/practice approach.
The Java-based ct rt module is expected to complete the model this week.
In addition, this document does not involve the call description of bsscriticalcomiler. It only serves as the document and overview of ideas.

Bearocean 2008-06-04
I found that cnblogs is better than csdn blogs... But I haven't done. Net for a long time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.