]> source.dussan.org Git - vaadin-framework.git/commitdiff
Do not derive DataSource from Function and replace apply method #307.
authorDenis Anisimov <denis@vaadin.com>
Mon, 3 Oct 2016 06:44:17 +0000 (09:44 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 3 Oct 2016 09:07:17 +0000 (09:07 +0000)
Change-Id: Ic0587e75c9a50c802a64673b1db0b8828b37889c

server/src/main/java/com/vaadin/server/data/BackEndDataSource.java
server/src/main/java/com/vaadin/server/data/DataCommunicator.java
server/src/main/java/com/vaadin/server/data/DataSource.java
server/src/main/java/com/vaadin/server/data/ListDataSource.java
server/src/test/java/com/vaadin/server/data/AbstractDataSourceTest.java
server/src/test/java/com/vaadin/server/data/datasource/ListDataSourceTest.java
server/src/test/java/com/vaadin/ui/AbstractListingTest.java
uitest/src/main/java/com/vaadin/tests/components/listselect/ListSelectAddRemoveItems.java
uitest/src/main/java/com/vaadin/tests/data/DummyData.java
uitest/src/main/java/com/vaadin/tests/layouts/MovingComponentsWhileOldParentInvisible.java

index e0cfc8f48b5fb94f1726e91b6eb4411247a88bf2..c792ebd23ef9abd2b68478eaee2dfa1f05089f51 100644 (file)
@@ -50,13 +50,13 @@ public class BackEndDataSource<T> extends AbstractDataSource<T> {
     }
 
     @Override
-    public Stream<T> apply(Query t) {
-        return request.apply(t);
+    public Stream<T> fetch(Query query) {
+        return request.apply(query);
     }
 
     @Override
-    public int size(Query t) {
-        return sizeCallback.apply(t);
+    public int size(Query query) {
+        return sizeCallback.apply(query);
     }
 
     /**
index 5fc11bb15d804c64c46540c7a7f800db4e2905e3..8238777c649e10a38c1916525b83ef816a5d628e 100644 (file)
@@ -228,7 +228,7 @@ public class DataCommunicator<T> extends AbstractExtension {
         if (initial || reset) {
             int dataSourceSize;
             if (getDataSource().isInMemory() && inMemoryFilter != null) {
-                dataSourceSize = (int) getDataSource().apply(new Query())
+                dataSourceSize = (int) getDataSource().fetch(new Query())
                         .filter(inMemoryFilter).count();
             } else {
                 dataSourceSize = getDataSource().size(new Query(filters));
@@ -244,7 +244,7 @@ public class DataCommunicator<T> extends AbstractExtension {
 
             if (getDataSource().isInMemory()) {
                 // We can safely request all the data when in memory
-                rowsToPush = getDataSource().apply(new Query());
+                rowsToPush = getDataSource().fetch(new Query());
                 if (inMemoryFilter != null) {
                     rowsToPush = rowsToPush.filter(inMemoryFilter);
                 }
@@ -254,7 +254,7 @@ public class DataCommunicator<T> extends AbstractExtension {
                 rowsToPush = rowsToPush.skip(offset).limit(limit);
             } else {
                 Query query = new Query(offset, limit, backEndSorting, filters);
-                rowsToPush = getDataSource().apply(query);
+                rowsToPush = getDataSource().fetch(query);
             }
             pushData(offset, rowsToPush);
         }
index f767f60cf081fa2f0cef7cc8011daea5089ee66b..c4042ecc11482e9ce25595faf6640017bc21a88d 100644 (file)
@@ -18,7 +18,6 @@ package com.vaadin.server.data;
 import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.function.Function;
 import java.util.stream.Stream;
 
 import com.vaadin.shared.Registration;
@@ -37,8 +36,7 @@ import com.vaadin.shared.Registration;
  *
  * @since 8.0
  */
-public interface DataSource<T>
-        extends Function<Query, Stream<T>>, Serializable {
+public interface DataSource<T> extends Serializable {
 
     /**
      * Gets whether the DataSource content all available in memory or does it
@@ -57,6 +55,16 @@ public interface DataSource<T>
      */
     int size(Query t);
 
+    /**
+     * Fetches data from this DataSource using given {@code query}.
+     * 
+     * @param query
+     *            given query to request data
+     * @return the result of the query request: a stream of data objects, not
+     *         {@code null}
+     */
+    Stream<T> fetch(Query query);
+
     /**
      * Refreshes all data based on currently available data in the underlying
      * provider.
index 64b7c03cb11a1eaf5b8e212ac0f27631e1812850..1e2724dc5bc621e08f3058f94347327e06ea0737 100644 (file)
@@ -63,7 +63,7 @@ public class ListDataSource<T> extends AbstractDataSource<T> {
     }
 
     @Override
-    public Stream<T> apply(Query query) {
+    public Stream<T> fetch(Query query) {
         Stream<T> stream = backend.stream();
         if (sortOrder != null) {
             stream = stream.sorted(sortOrder);
@@ -117,7 +117,7 @@ public class ListDataSource<T> extends AbstractDataSource<T> {
      * return the full size.
      */
     @Override
-    public int size(Query t) {
+    public int size(Query query) {
         return backend.size();
     }
 
index 4898869743fdcf00c5e9760e2340e576b968fdf7..187f8e0d77e2b69e95053ee562bd79aa172cc42c 100644 (file)
@@ -31,7 +31,7 @@ public class AbstractDataSourceTest {
 
     private static class TestDataSource extends AbstractDataSource<Object> {
         @Override
-        public Stream<Object> apply(Query t) {
+        public Stream<Object> fetch(Query t) {
             return null;
         }
 
index a6dcc77474e8fbd75732556ab6d757b08c748c4c..a428858a42fcc983c6b233a34c61b540522049c2 100644 (file)
@@ -29,7 +29,7 @@ public class ListDataSourceTest {
     @Test
     public void testListContainsAllData() {
         List<StrBean> list = new LinkedList<>(data);
-        dataSource.apply(new Query())
+        dataSource.fetch(new Query())
                 .forEach(str -> assertTrue(
                         "Data source contained values not in original data",
                         list.remove(str)));
@@ -42,7 +42,7 @@ public class ListDataSourceTest {
         Comparator<StrBean> comp = Comparator.comparing(StrBean::getValue)
                 .thenComparing(StrBean::getRandomNumber)
                 .thenComparing(StrBean::getId);
-        List<StrBean> list = dataSource.sortingBy(comp).apply(new Query())
+        List<StrBean> list = dataSource.sortingBy(comp).fetch(new Query())
                 .collect(Collectors.toList());
 
         // First value in data is { Xyz, 10, 100 } which should be last in list
@@ -63,7 +63,7 @@ public class ListDataSourceTest {
     public void testDefatulSortWithSpecifiedPostSort() {
         Comparator<StrBean> comp = Comparator.comparing(StrBean::getValue)
                 .thenComparing(Comparator.comparing(StrBean::getId).reversed());
-        List<StrBean> list = dataSource.sortingBy(comp).apply(new Query())
+        List<StrBean> list = dataSource.sortingBy(comp).fetch(new Query())
                 // The sort here should come e.g from a Component
                 .sorted(Comparator.comparing(StrBean::getRandomNumber))
                 .collect(Collectors.toList());
@@ -91,7 +91,7 @@ public class ListDataSourceTest {
     @Test
     public void testDefatulSortWithFunction() {
         List<StrBean> list = dataSource.sortingBy(StrBean::getValue)
-                .apply(new Query()).collect(Collectors.toList());
+                .fetch(new Query()).collect(Collectors.toList());
 
         Assert.assertEquals("Sorted data and original data sizes don't match",
                 data.size(), list.size());
@@ -114,7 +114,7 @@ public class ListDataSourceTest {
         data.set(0, bean);
         dataSource.refreshAll();
 
-        List<StrBean> list = dataSource.apply(query)
+        List<StrBean> list = dataSource.fetch(query)
                 .collect(Collectors.toList());
         StrBean first = list.get(0);
         Assert.assertEquals(bean.getValue(), first.getValue());
@@ -133,7 +133,7 @@ public class ListDataSourceTest {
         bean.setValue("foo");
         dataSource.refreshAll();
 
-        List<StrBean> list = dataSource.apply(query)
+        List<StrBean> list = dataSource.fetch(query)
                 .collect(Collectors.toList());
         StrBean first = list.get(0);
         Assert.assertEquals("foo", first.getValue());
@@ -153,7 +153,7 @@ public class ListDataSourceTest {
                 .sortingBy(Comparator.comparing(StrBean::getId));
         dSource.refreshAll();
 
-        List<StrBean> list = dSource.apply(query).collect(Collectors.toList());
+        List<StrBean> list = dSource.fetch(query).collect(Collectors.toList());
         StrBean first = list.get(0);
         Assert.assertEquals(bean.getValue(), first.getValue());
         Assert.assertEquals(bean.getRandomNumber(), first.getRandomNumber());
@@ -172,7 +172,7 @@ public class ListDataSourceTest {
         data.add(0, bean);
         dataSource.refreshAll();
 
-        List<StrBean> list = dataSource.apply(query)
+        List<StrBean> list = dataSource.fetch(query)
                 .collect(Collectors.toList());
         StrBean first = list.get(0);
         Assert.assertEquals(bean.getValue(), first.getValue());
index bbe0fd01aa25065179de19dd8c94d1579012e3a9..585dce1f5e1e876516e337e153593e64a325185e 100644 (file)
@@ -70,7 +70,7 @@ public class AbstractListingTest {
     public void testSetItemsWithCollection() {
         listing.setItems(items);
         List<String> list = new LinkedList<>(items);
-        listing.getDataSource().apply(new Query()).forEach(
+        listing.getDataSource().fetch(new Query()).forEach(
                 str -> Assert.assertTrue("Unexpected item in data source",
                         list.remove(str)));
         Assert.assertTrue("Not all items from list were in data source",
@@ -80,7 +80,7 @@ public class AbstractListingTest {
     @Test
     public void testSetItemsWithVarargs() {
         listing.setItems(ITEM_ARRAY);
-        listing.getDataSource().apply(new Query()).forEach(
+        listing.getDataSource().fetch(new Query()).forEach(
                 str -> Assert.assertTrue("Unexpected item in data source",
                         items.remove(str)));
         Assert.assertTrue("Not all items from list were in data source",
index cd2e8ad1f47a496807f21fc86ddc65d018bbb7ff..d78025bf4cf14bb72290968248c565d2ba291cba 100644 (file)
@@ -50,7 +50,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Add first", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.add(0, "first");
             dataSource = new ListDataSource<>(list);
@@ -59,7 +59,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Add middle", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.add(list.size() / 2, "middle");
             dataSource = new ListDataSource<>(list);
@@ -68,7 +68,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Add last", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.add("last");
             dataSource = new ListDataSource<>(list);
@@ -77,7 +77,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Swap", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             Collections.swap(list, 0, list.size() - 1);
             dataSource = new ListDataSource<>(list);
@@ -87,7 +87,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Remove first", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.remove(0);
 
@@ -98,7 +98,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Remove middle", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.remove(list.size() / 2);
             dataSource = new ListDataSource<>(list);
@@ -107,7 +107,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
         }));
 
         addComponent(new Button("Remove last", event -> {
-            List<String> list = dataSource.apply(null)
+            List<String> list = dataSource.fetch(null)
                     .collect(Collectors.toList());
             list.remove(list.size() - 1);
 
@@ -121,7 +121,7 @@ public class ListSelectAddRemoveItems extends AbstractTestUIWithLog {
 
     private void logContainer() {
         StringBuilder b = new StringBuilder();
-        List<String> list = dataSource.apply(null).collect(Collectors.toList());
+        List<String> list = dataSource.fetch(null).collect(Collectors.toList());
         for (int i = 0; i < list.size(); i++) {
             Object id = list.get(i);
             if (i != 0) {
index 8b4083d834c248198b9db82f2f7a4ff5ed27ec8c..917eb39bbd70228a655e8e380c683c40b0a0c6f4 100644 (file)
@@ -34,9 +34,9 @@ public class DummyData extends AbstractTestUIWithLog {
         }
 
         @Override
-        public Stream<String> apply(Query query) {
+        public Stream<String> fetch(Query query) {
             log("Backend request #" + (count++));
-            return super.apply(query);
+            return super.fetch(query);
         }
     }
 
index 5aee3a2f15674ba4d8841addb88778453bdd5edf..910265696f6e9226cfdf69099919b458de13e41c 100644 (file)
@@ -53,7 +53,7 @@ public class MovingComponentsWhileOldParentInvisible extends TestBase {
         });
 
         componentContainerSelect.setValue(componentContainerSelect
-                .getDataSource().apply(new Query()).iterator().next());
+                .getDataSource().fetch(new Query()).iterator().next());
         Button but1 = new Button("Move in and out of component container",
                 new Button.ClickListener() {