]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add method to DataSource for checking if data is in memory
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Tue, 12 Jul 2016 16:02:29 +0000 (19:02 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 14 Jul 2016 08:57:07 +0000 (08:57 +0000)
Change-Id: I7b14870a3eddb477e629f61691e060ea42325aea

server/src/main/java/com/vaadin/tokka/server/communication/data/DataCommunicator.java
server/src/main/java/com/vaadin/tokka/server/communication/data/DataSource.java
server/src/main/java/com/vaadin/tokka/server/communication/data/InMemoryDataSource.java

index dc957f6abdcddb694ae8c60ef644d253d7220483..e5d32696416a0cee102ea284d7a8c12c65ad0d8a 100644 (file)
@@ -215,7 +215,7 @@ public class DataCommunicator<T> extends AbstractExtension {
 
             Stream<T> rowsToPush;
 
-            if (getDataSource() instanceof InMemoryDataSource) {
+            if (getDataSource().isInMemory()) {
                 // We can safely request all the data when in memory
                 // FIXME: sorted and filter.
                 rowsToPush = getDataSource().apply(new Query()).skip(offset)
index 38a195e953c72fa7ea355d09b561283ae7643f5b..17f0355bd27ab02ebf253ae9d15a5a4ae17e66f1 100644 (file)
@@ -21,8 +21,6 @@ import java.util.Collection;
 import java.util.function.Function;
 import java.util.stream.Stream;
 
-import com.vaadin.tokka.event.Registration;
-
 /**
  * Minimal DataSource API for communication between the DataProvider and a back
  * end service.
@@ -45,6 +43,14 @@ public interface DataSource<T, SORT> extends Function<Query, Stream<T>>,
      */
     DataSource<T, SORT> sortingBy(SORT sortOrder);
 
+    /**
+     * Gets whether the DataSource content all available in memory or does it
+     * use some external backend.
+     * 
+     * @return {@code true} if all data is in memory; {@code false} if not
+     */
+    boolean isInMemory();
+
     /**
      * This method creates a new {@link InMemoryDataSource} from a given
      * Collection. The InMemoryDataSource creates a protective List copy of all
index 49ca85d403ce844cd54836d2049c5b6f30a6739a..b5dc0734c287a09b8d466536dfaf999fb4e91969 100644 (file)
@@ -72,4 +72,9 @@ public class InMemoryDataSource<T> implements DataSource<T, Comparator<T>> {
             Function<T, U> sortOrder) {
         return sortingBy(Comparator.comparing(sortOrder));
     }
+
+    @Override
+    public boolean isInMemory() {
+        return true;
+    }
 }