summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2016-11-21 14:54:05 +0200
committerHenri Sara <hesara@vaadin.com>2016-11-21 14:54:05 +0200
commitdd907e839d2a3f2da2ce04d59b4e9e94cc7a634f (patch)
treeca570f89005e80e3c9df7b6f83b5297f4a3b3ce6 /server
parent848feaaf30762204cb4d9c7bf8b76fbb8bb675da (diff)
downloadvaadin-framework-dd907e839d2a3f2da2ce04d59b4e9e94cc7a634f.tar.gz
vaadin-framework-dd907e839d2a3f2da2ce04d59b4e9e94cc7a634f.zip
Add filter type parameter for Query
Change-Id: If9554c67900cc854e3ba6912fefad19e043b1d62
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java16
-rw-r--r--server/src/main/java/com/vaadin/server/data/Query.java37
2 files changed, 29 insertions, 24 deletions
diff --git a/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java b/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
index 89a780248f..8d267f1230 100644
--- a/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/server/data/BackEndDataProvider.java
@@ -30,8 +30,8 @@ import com.vaadin.server.SerializableFunction;
*/
public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
- private final SerializableFunction<Query, Stream<T>> request;
- private final SerializableFunction<Query, Integer> sizeCallback;
+ private final SerializableFunction<Query<?>, Stream<T>> request;
+ private final SerializableFunction<Query<?>, Integer> sizeCallback;
/**
* Constructs a new DataProvider to request data from an arbitrary back end
@@ -42,8 +42,9 @@ public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
* @param sizeCallback
* function that return the amount of data in back end for query
*/
- public BackEndDataProvider(SerializableFunction<Query, Stream<T>> request,
- SerializableFunction<Query, Integer> sizeCallback) {
+ public BackEndDataProvider(
+ SerializableFunction<Query<?>, Stream<T>> request,
+ SerializableFunction<Query<?>, Integer> sizeCallback) {
Objects.requireNonNull(request, "Request function can't be null");
Objects.requireNonNull(sizeCallback, "Size callback can't be null");
this.request = request;
@@ -68,13 +69,14 @@ public class BackEndDataProvider<T> extends AbstractDataProvider<T> {
* directions
* @return new data provider with modified sorting
*/
- public BackEndDataProvider<T> sortingBy(List<SortOrder<String>> sortOrders) {
+ public BackEndDataProvider<T> sortingBy(
+ List<SortOrder<String>> sortOrders) {
return new BackEndDataProvider<>(query -> {
List<SortOrder<String>> queryOrder = new ArrayList<>(
query.getSortOrders());
queryOrder.addAll(sortOrders);
- return request.apply(new Query(query.getLimit(), query.getOffset(),
- queryOrder, query.getFilters()));
+ return request.apply(new Query<>(query.getLimit(),
+ query.getOffset(), queryOrder, query.getFilter()));
}, sizeCallback);
}
diff --git a/server/src/main/java/com/vaadin/server/data/Query.java b/server/src/main/java/com/vaadin/server/data/Query.java
index 863bf1e140..3762039a72 100644
--- a/server/src/main/java/com/vaadin/server/data/Query.java
+++ b/server/src/main/java/com/vaadin/server/data/Query.java
@@ -18,20 +18,23 @@ package com.vaadin.server.data;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
+import java.util.Optional;
/**
- * Query object used to request data from a backend. Contains index limits,
- * sorting and filtering information.
+ * Immutable query object used to request data from a backend. Contains index
+ * limits, sorting and filtering information.
+ *
+ * @param <F>
+ * filter type
*
* @since 8.0
*/
-public class Query implements Serializable {
+public class Query<F> implements Serializable {
private final int offset;
private final int limit;
private final List<SortOrder<String>> sortOrders;
- private final Set<Object> filters;
+ private final F filter;
/**
* Constructs a Query for all rows from 0 to {@link Integer#MAX_VALUE}
@@ -41,21 +44,21 @@ public class Query implements Serializable {
offset = 0;
limit = Integer.MAX_VALUE;
sortOrders = Collections.emptyList();
- filters = Collections.emptySet();
+ filter = null;
}
/**
* Constructs a Query for all rows from 0 to {@link Integer#MAX_VALUE} with
* filtering.
*
- * @param filters
- * set of back end filters
+ * @param filter
+ * back end filter of a suitable type for the data provider
*/
- public Query(Set<Object> filters) {
+ public Query(F filter) {
offset = 0;
limit = Integer.MAX_VALUE;
sortOrders = Collections.emptyList();
- this.filters = filters;
+ this.filter = filter;
}
/**
@@ -68,15 +71,15 @@ public class Query implements Serializable {
* fetched item count
* @param sortOrders
* sorting order for fetching
- * @param filters
+ * @param filter
* filtering for fetching
*/
public Query(int offset, int limit, List<SortOrder<String>> sortOrders,
- Set<Object> filters) {
+ F filter) {
this.offset = offset;
this.limit = limit;
this.sortOrders = sortOrders;
- this.filters = filters;
+ this.filter = filter;
}
/**
@@ -110,11 +113,11 @@ public class Query implements Serializable {
}
/**
- * Gets the filters for items to fetch.
+ * Gets the filter for items to fetch.
*
- * @return set of filters
+ * @return optional filter
*/
- public Set<Object> getFilters() {
- return filters;
+ public Optional<F> getFilter() {
+ return Optional.ofNullable(filter);
}
}