Principles and Design of Client/Server datasets

Source: Internet
Author: User

Client Dataset / Principles and Design of server-side DatasetsRecently, a relatively large project was developed, mainly using ActiveX controls for underlying operations, using JavaScript For logical control and processing, and Ajax for interaction between the server and the client, in actual applications, it is found that the access efficiency to the database by using Ajax is far from meeting the requirements of the system. Therefore, the Client/Server dataset is designed and developed. Ajax Implementation PrincipleBefore introducing my design, I would like to briefly introduce the principles of Ajax and the reasons for its low efficiency. Basically, Ajax uses Microsoft's XMLHTTP technology to access a remote path asynchronously and return page results. From this point, we can see that for a database access operation, the Ajax method may consume at least the following two types of performance: one is to access the remote path, and the other is to transmit data to the remote path, it takes a certain amount of time. Second, it takes some time to return the page results and data from the remote end to the client. In addition, parsing the page also consumes performance. DWR Implementation PrincipleDWR is a framework of Ajax. The reason for DWR is that my system development chooses DWR to implement Ajax functions. The benefit of DWR is that some Java classes can be mapped into a JavaScript Object, so that Java classes can be easily used in JavaScript. DWR is the Ajax framework, so its implementation principle should be the same as Ajax, But it encapsulates the remote access and PAGE result parsing part. The general principle is this: Write a Java class. After configuring the Java class mapped to the data of dwr in the dwr configuration file, DWR will automatically generate the desired JavaScript code, when accessing JavaScript Functions, the system will call DWR's remote path. After some processing, the remote path will call the corresponding Java class method, then, the result of calling this method is returned to the client, and the client then encapsulates the data and returns the result to JavaScript data with similar results as Java. Dojo IntroductionDojo is a JS tool set. It is an object-oriented JS framework (which can be better reflected in widgets). It is divided into multiple modules based on functions, and each module is divided into multiple packages, you can import different packages as needed, similar to Java. To put it bluntly, Dojo makes JavaScript look like an object-oriented language. It is easier to develop large projects with classes and methods. The Client/Server dataset adopts the dojo framework to implement classes and methods, making it easier to use. Client dataset Introduction  I. Traditional Ajax Reasons for low access efficiencyTraditional access methods are inefficient because downloading data from the server to the client is slow, especially for database access. If the returned data contains hundreds or even thousands of data entries, DWR is used, it takes a long time to download data from the server to the client. From the traditional submit method to jump to a servlet, and then return page data (such as the query function), because the query is implemented on the server, the client generally only returns single page data, so the comparison is faster. Ii. reasons why the client dataset is requiredWhy not use the server-side method to execute most of the queries on the server and then return only a small amount of final data? This requires a detailed analysis of the specific situation. Generally, a simple system should use the method described above, and it does not require the effort to develop a client dataset. For the system I mentioned above, because Javascript is mainly used for development (rather than Java), database access is frequent. If Ajax is frequently used to access the server, the performance will inevitably be affected. The DWR method is used. Because Java classes are called directly, some methods originally return a large amount of data. If the transformation is hard, only a small amount of data is returned for specific needs, the reusability and maintainability of methods will be greatly reduced. This will only result in writing specific required methods for each database method, in some cases, it is difficult to return the required data. Iii. Principles of client-side DatasetsIn this case, we think of the client dataset in the dephi language. It is an implementation method that satisfies the needs of frequent data access. In addition, it adopts a unified query access method, greatly reducing the number of query methods, this makes data query almost irrelevant to specific Java classes. Now let's talk about the implementation principle. Its implementation principle is to download all the tables that require a large amount of Access to the client and save them when logging on to the system (the method of storing the array data is used here, (consistent with DWR). When you need to access database data, you can directly access the data on the client, which reduces the interaction between the client and the server. Iv. Client dataset MethodThe client-side dataset adopts a design method unrelated to a specific table to develop a javascript class called clientdataset. The main method is as follows: setdata: This method is used to set data. By default, a new clientdataset is used, an empty dataset is generated. Only after this method is called can field information and data be set based on the information in the data. Locate: This is used to locate the first data that meets the condition. When you pass in the field name and field value (multiple values), the system queries the dataset and finds out the first data fieldbyname that meets the input condition: generally, after you call the locate method to locate a data item, you can call this method and pass in the field name to return the value of this field. Setfilter: sets the filter condition. Call this method to pass in the filter fields and Field Values. Then, the dataset is filtered Based on the Data conditions and the filtered dataset is returned. Setisfiltered: This method is called. If it is set to true, the filter is performed. If it is set to false, the filter is canceled. First: Go to the first data record of the dataset prior: Go to the first data record of the currently located data next: Go to the current data record position, go to the next data record last: Go to the last data record of the dataset EOF: determine whether the current position is the end position of the dataset (that is, the last data) Server Dataset  I. reasons why a server dataset is requiredWhen using the client dataset, You need to download all the datasets to the client during system logon. If the dataset has a large amount of data, you need to consume a large amount of data during logon. Starting from this, we designed a server-side dataset. Ii. Principles of server-side DatasetsWhen the server starts, the server downloads the required dataset to the server. Currently, arraylist is used to save a dataset and map is used to manage the dataset; implement a servicedataset class (Java class) to manage datasets (without storing data ). When a user logs on to the system, the servicedataset required by the user is saved in the cache. Because servicedataset only stores information such as the positioning of the user's datasets, it does not actually store the data. Therefore, the server dataset allows all users to share a dataset. After each user logs on, the private servicedataset is maintained. In the access data set, the system first accesses the Java class through DWR, and then accesses the data from the Java class, and returns it to JavaScript. Iii. Method of server DatasetThe server-side dataset has the same method as the client-side dataset. Iv. Benefits of server-side DatasetsFrom the above implementation method, you may feel that the efficiency of this method does not seem to be faster than directly using DWR to access the database. In fact, the efficiency of these two methods should be almost the same. However, it reduces the use of many query methods and achieves consistent access to datasets. In addition, after the server dataset and client dataset are encapsulated together, the two methods are almost transparent to developers and adopt the same method, methods can be exchanged at any time, which will be described later. Encapsulate client and server DatasetsBecause the client data set and server data set have the same method, the data access method is different. Then, we can encapsulate them into a unified class, but only specify the data access method during initialization. When calling a method, we can follow the specified access method, different implementations are called respectively. The advantage of doing so is that these two methods are transparent to developers. When one of the developers initializes the data set and changes the access method, the access method of the entire data set will change, the Code does not need to be changed.

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.