[Original] Java Tips: Distributed JTABLES Processing [1] Summary
When a tens of thousands of rows or more lines are displayed, it takes a quick response and display. To achieve this purposes, you can use a special TableModel, this mode only from the server from the server when a data is needed, so fewer data is downloaded. To better improve efficiency, row data can acquire 50 rows each time and store it on the client for future use. The following article will explain how to write such a distributed table and use its advantages.
Jeremy Dickson
In the age of data being driven, it is a standard job that shows tens of thousands of lines. The data that makes up the table is generally obtained from the remote database, which is quite difficult: Do you only download a Table data, or only the first block of request data? If the user is just interested in the beginning, but the program downloads all the data before the user is used, which will cause the user to wait longer, and disgust it. In a web search, a block of data is usually downloaded, for example in Google, the size of the block is the result of 10 pages. In any case, in some cases, you may need to display this data in a table, but start data to the user started. As a suggestion, you may need a column data, unit query, and data editing of electronic TABLE. Due to the JTable a flexible design, when optimizing downloading data, you can have a rich user interface.
Note: You can download this article, address: http://www.javaworld.com/javaworld/javatips/jw-javatip137.html? # Resources # Resources
Distributed storage TableModel
JTABLE is based on Model-View-Controller design mode. In this mode, the composition data source is separated from the visual part, and the control portion is also clearly divided into three modules (see http://www.javaworld.com/javaworld/javatips/jw-javatip137.html?#resources# Resources). In a JTABLE instance, this mode consists of interface TableModel. This makes jtable have strong adaptation because of the data sources of any mode can be executed in TableModel, and TableModel in JTABLE, and Table on the screen. For example, you can create a table to display a variety of data, which may be a message queue from a file, a database, or using this method. In this trick, it can fully display the advantages of adaptability. JTable uses a lazy method from TableModel loading data: read data from MODEL only when needed, which is better than reading all data prior to display. When you need to display a special table unit on the display, JTABLE is a new data value from the new data value in its TableModel call method getValueat (int Row, Int Column). It is said that it is a lazy method because the data requirement can be started by any method. For example, place the data on the server and use a URL to return the data of this unit because XML. GetValueat () can be analyzed, returning to the XML of the JTABLE. In any case, the remote call is time consuming, why not bundle the requested multiple data units into a remote call and store the required additional data unit? If you request a row 0, column 0, you can call the servlet to return data from all 0 to 50 rows. This means that getValueat () is served for all data of all current visual table units. More data is obtained when the user downloads Table. In addition, the cache area of the appropriate line can be placed on the client. When the client download exceeds the appropriate line, the number of data that is not required to be required will be overwritten. If the customer rolls back to the table, the data can be obtained from the server when needed. Perform a certain number of classes and interfaces are defined for this distributed storage JTABLE. (Figure 1) Figure 1, a class for distributed storage of the Table mode established a special TableModel called DistributeTableModel. The TableModel interface method is implemented by completing all features of class DistributeTableClientCache, and class DistributedTableClientCache gets a large number of data from the data source and temporarily stored on the client. DistributedTableClientCache The DistributedTableClientCache object that uses the interface from the newly obtained all data. Through this interface, logically needs but distributed data, which turn these data into our habits and valid TableModel. For example, method getTableDescription () returns a number of object-rows and columns containing table description elements, and the type of column names and packets. Method Object [] RETRIEVEROWS (INT from, int to) throws an exception when processing the current data. As long as TableModel needs a row data that is not in the cache, the method RETRIEVEROWS () is called, and then a row of data is obtained.