}
@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);
}
/**
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));
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);
}
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);
}
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;
*
* @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
*/
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.
}
@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);
* return the full size.
*/
@Override
- public int size(Query t) {
+ public int size(Query query) {
return backend.size();
}
private static class TestDataSource extends AbstractDataSource<Object> {
@Override
- public Stream<Object> apply(Query t) {
+ public Stream<Object> fetch(Query t) {
return null;
}
@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)));
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
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());
@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());
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());
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());
.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());
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());
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",
@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",
}));
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);
}));
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);
}));
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);
}));
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);
}));
addComponent(new Button("Remove first", event -> {
- List<String> list = dataSource.apply(null)
+ List<String> list = dataSource.fetch(null)
.collect(Collectors.toList());
list.remove(0);
}));
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);
}));
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);
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) {
}
@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);
}
}
});
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() {