In general applications, when you need to use table to present data to end users, the consistency of the display ordering of the data in the table greatly affects the customer experience. You typically want implementations such as multiple query results showing the same order, inserting data above the original data, and so on.
The ADF provides developers with two levels of sorting, namely database-level sorting and memory-level (in-memory) sorting. The two sorting methods need to be used at the same time to get the proper sorting effect.
(using the Employees table in Oracle sample database HR as an example)
Sort data sources
To edit Vo's query, set the order by field, where the manager as the sort field needs to be aware that the sort here is only for sorting from the data source when the data is picked, and when the Insert/delete operation is made to VO, the modification does not immediately commit to the database, but is stored in the eo/ Vo, this causes this sort method to be invalid for data that does not exist in the database for entity rows, and why the In-memory ordering method is required.
The query pattern for
vo (View Object's SQL mode)
should first understand the query pattern of VO before starting the in-memory sort of vo. A VO in the
ADF has the default query pattern for the following query mode
viewobject.query_mode_scan_database_tables
Vo. In this mode, VO retrieves data from the database every time executequery
viewobject.query_mode_scan_view_rows
Retrieves data that already exists in the row set of Vo. Allow In-memory Filtering
viewobject.query_mode_scan_entity_rows
To retrieve data stored in the EO cache using VO in this query mode
The
can use the Setquerymode () method to set the VO query mode. A query pattern can be set individually or using Java or (|) Set up multiple query modes. For example
setquerymode (Viewobject.query_mode_scan_database_tables | viewobject.query_mode_scan_entity_rows)
When multiple query modes are set, duplicate rows are automatically skipped. After the
has set the query mode, the query mode setting takes effect when the ExecuteQuery () method is executed.
In-mamory sort
Use the Setsortby () method to sort the run-time in-memory for VO. The input parameters of the Setsortby () method are similar to the ORDER BY clause in SQL, but the difference is that the column name is replaced with the attribute name on VO. For example
Setsortby ("ManagerID desc, EmployeeId");
Depending on the setting of the query mode, when ExecuteQuery () is executed, Setsortby () is automatically converted to the appropriate sorting method. When using database retrieval, Setsortby is converted to an ORDER BY clause, and when the In-memory query is used, the Setsortby is converted to a Sortcriteria object.
Examples of Use:
vo.setSortBy("ManagerId");
vo.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
vo.executeQuery();
You only need to execute the statement as you insert data to complete the in-memory sorting function.
Sorting Methods for custom VO
When the required sorting method is more complex, using Setsortby to set the collation cannot meet the requirements, you can override Vo by overriding the public void Sortrows (row[] rows) method and public Comparator Getrowcomparator () method to achieve the purpose. The Sortrows method is the sort method that is executed when the in-memory is sorted; The Getrowcomparater method returns a comparator type object that is called by the VO's CompareTo () method.
reprinted from: http://blog.csdn.net/ice_cuijin/article/details/16842401
Oracle ADF vo Ordering and VO query mode