click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r794699 - in /incubator/click/trunk/click/examples/src/org/apache/click/examples: page/table/LargeDatasetDemo.java service/CustomerService.java
Date Thu, 16 Jul 2009 14:46:57 GMT
Author: sabob
Date: Thu Jul 16 14:46:57 2009
New Revision: 794699

URL: http://svn.apache.org/viewvc?rev=794699&view=rev
Log:
added sorting to large dataset demo

Modified:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/LargeDatasetDemo.java
    incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/LargeDatasetDemo.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/LargeDatasetDemo.java?rev=794699&r1=794698&r2=794699&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/LargeDatasetDemo.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/page/table/LargeDatasetDemo.java
Thu Jul 16 14:46:57 2009
@@ -46,10 +46,19 @@
     private CustomerService customerService;
 
     public LargeDatasetDemo() {
-        table = new Table();
+        table = new Table() {
+
+            /**
+             * Sorting must be done on Database, so we override Table build in
+             * sorting to do nothing.
+             */
+            protected void sortRowList() {
+            }
+        };
 
         // Setup customers table
         table.setClass(Table.CLASS_ITS);
+        table.setSortable(true);
 
         Column column = new Column("name");
         column.setWidth("140px;");
@@ -89,7 +98,8 @@
         table.setRowList(dataProvider);
 
         // Retrieve customers given the firstRow, lastRow and pageSize
-        List customers = getCustomers(table.getFirstRow(), table.getLastRow(), table.getPageSize());
+        List customers = getCustomers(table.getFirstRow(), table.getPageSize(),
+            table.getSortedColumn(), table.isSortedAscending());
 
         // Add the customers to the table dataProvider
         dataProvider.addAll(customers);
@@ -138,7 +148,7 @@
         }
 
         /**
-         * Always return the total number of rows even the number of entries
+         * Always return the total number of rows even if the number of entries
          * are less.
          */
         public int size() {
@@ -152,11 +162,12 @@
         return customerService.getNumberOfCustomers();
     }
 
-    private List<Customer> getCustomers(int from, int to, int pageSize) {
+    private List<Customer> getCustomers(int from, int pageSize, String sortedColumn,
+        boolean ascending) {
         // Below we retrieve only those customers between the from and to
         // args. In a real application one would use an ORM or JDBC to only
         // retrieve the needed rows
-        return customerService.getCustomersForPage(from, pageSize);
+        return customerService.getCustomersForPage(from, pageSize, sortedColumn, ascending);
     }
 
 }

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java?rev=794699&r1=794698&r2=794699&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
(original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
Thu Jul 16 14:46:57 2009
@@ -198,22 +198,18 @@
     }
 
     @SuppressWarnings("unchecked")
-    public List<Customer> getCustomersForPage(int offset, int pageSize) {
-        List list = getCustomers();
+    public List<Customer> getCustomersForPage(int offset, int pageSize,
+        String sortColumn, boolean ascending) {
 
-        List pageList = new ArrayList(pageSize);
-        for (int i = 0; i < pageSize; i++) {
-            // Increment row index with the offset
-            int rowIndex = offset + i;
-
-            // Guard against rowIndex that moves past the end of the list
-            if (rowIndex >= list.size()) {
-                break;
-            }
-            pageList.add(list.get(rowIndex));
+        SelectQuery query = new SelectQuery(Customer.class);
+        if (sortColumn != null) {
+            query.addOrdering(sortColumn, ascending);
         }
+        query.setFetchOffset(offset);
+        query.setFetchLimit(pageSize);
+        List list = performQuery(query);
 
-        return pageList;
+        return list;
     }
 
     @SuppressWarnings("unchecked")



Mime
View raw message