summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis <denis@vaadin.com>2017-01-25 09:36:29 +0200
committerGitHub <noreply@github.com>2017-01-25 09:36:29 +0200
commit6c6161caeb8d4524aba11fa7976366981e090e85 (patch)
tree3bac170fd710a0611f02ad752a23ebc1946849ef
parentdcb8271b50b9d76dd9c56af1f1621ed39072b229 (diff)
downloadvaadin-framework-6c6161caeb8d4524aba11fa7976366981e090e85.tar.gz
vaadin-framework-6c6161caeb8d4524aba11fa7976366981e090e85.zip
Use non-Generic SortOrder in Query. (#8239)
* Use non-Generic SortOrder in Query. Fixes #8215
-rw-r--r--server/src/main/java/com/vaadin/data/provider/AbstractBackEndDataProvider.java6
-rw-r--r--server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java6
-rw-r--r--server/src/main/java/com/vaadin/data/provider/DataCommunicator.java6
-rw-r--r--server/src/main/java/com/vaadin/data/provider/Query.java6
-rw-r--r--server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java48
-rw-r--r--server/src/main/java/com/vaadin/data/provider/Sort.java24
-rw-r--r--server/src/main/java/com/vaadin/data/provider/SortOrder.java1
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java21
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java6
-rw-r--r--server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java5
-rw-r--r--server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java12
-rw-r--r--server/src/test/java/com/vaadin/data/provider/ListDataProviderTest.java2
-rw-r--r--server/src/test/java/com/vaadin/data/provider/bov/DataProviderBoVTest.java4
13 files changed, 94 insertions, 53 deletions
diff --git a/server/src/main/java/com/vaadin/data/provider/AbstractBackEndDataProvider.java b/server/src/main/java/com/vaadin/data/provider/AbstractBackEndDataProvider.java
index 8da5d7a726..9b08bb8c1d 100644
--- a/server/src/main/java/com/vaadin/data/provider/AbstractBackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/AbstractBackEndDataProvider.java
@@ -33,7 +33,7 @@ import java.util.stream.Stream;
public abstract class AbstractBackEndDataProvider<T, F> extends
AbstractDataProvider<T, F> implements BackEndDataProvider<T, F> {
- private List<SortOrder<String>> sortOrders = new ArrayList<>();
+ private List<QuerySortOrder> sortOrders = new ArrayList<>();
private Query<T, F> mixInSortOrders(Query<T, F> query) {
if (sortOrders.isEmpty()) {
@@ -43,7 +43,7 @@ public abstract class AbstractBackEndDataProvider<T, F> extends
Set<String> sortedPropertyNames = query.getSortOrders().stream()
.map(SortOrder::getSorted).collect(Collectors.toSet());
- List<SortOrder<String>> combinedSortOrders = Stream
+ List<QuerySortOrder> combinedSortOrders = Stream
.concat(query.getSortOrders().stream(),
sortOrders.stream()
.filter(order -> !sortedPropertyNames
@@ -86,7 +86,7 @@ public abstract class AbstractBackEndDataProvider<T, F> extends
protected abstract int sizeInBackEnd(Query<T, F> query);
@Override
- public void setSortOrders(List<SortOrder<String>> sortOrders) {
+ public void setSortOrders(List<QuerySortOrder> sortOrders) {
this.sortOrders = Objects.requireNonNull(sortOrders,
"Sort orders cannot be null");
refreshAll();
diff --git a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
index f20b22fa17..36d875a21a 100644
--- a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
+++ b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java
@@ -37,12 +37,12 @@ public interface BackEndDataProvider<T, F> extends DataProvider<T, F> {
* sorting is also used to determine the ordering of items that are
* considered equal by the sorting defined in the query.
*
- * @see #setSortOrder(SortOrder)
+ * @see #setSortOrder(QuerySortOrder)
*
* @param sortOrders
* a list of sort orders to set, not <code>null</code>
*/
- void setSortOrders(List<SortOrder<String>> sortOrders);
+ void setSortOrders(List<QuerySortOrder> sortOrders);
/**
* Sets a single sort order to use as the default sorting for this data
@@ -59,7 +59,7 @@ public interface BackEndDataProvider<T, F> extends DataProvider<T, F> {
* a sort order to set, or <code>null</code> to clear any
* previously set sort orders
*/
- default void setSortOrder(SortOrder<String> sortOrder) {
+ default void setSortOrder(QuerySortOrder sortOrder) {
if (sortOrder == null) {
setSortOrders(Collections.emptyList());
} else {
diff --git a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
index 12fd323bc1..7b909b831d 100644
--- a/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
+++ b/server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
@@ -201,7 +201,7 @@ public class DataCommunicator<T, F> extends AbstractExtension {
private F filter;
private Comparator<T> inMemorySorting;
- private final List<SortOrder<String>> backEndSorting = new ArrayList<>();
+ private final List<QuerySortOrder> backEndSorting = new ArrayList<>();
private final DataCommunicatorClientRpc rpc;
public DataCommunicator() {
@@ -421,12 +421,12 @@ public class DataCommunicator<T, F> extends AbstractExtension {
}
/**
- * Sets the {@link SortOrder}s to use with backend sorting.
+ * Sets the {@link QuerySortOrder}s to use with backend sorting.
*
* @param sortOrder
* list of sort order information to pass to a query
*/
- public void setBackEndSorting(List<SortOrder<String>> sortOrder) {
+ public void setBackEndSorting(List<QuerySortOrder> sortOrder) {
backEndSorting.clear();
backEndSorting.addAll(sortOrder);
reset();
diff --git a/server/src/main/java/com/vaadin/data/provider/Query.java b/server/src/main/java/com/vaadin/data/provider/Query.java
index a4e0197d83..abf905658c 100644
--- a/server/src/main/java/com/vaadin/data/provider/Query.java
+++ b/server/src/main/java/com/vaadin/data/provider/Query.java
@@ -36,7 +36,7 @@ public class Query<T, F> implements Serializable {
private final int offset;
private final int limit;
- private final List<SortOrder<String>> sortOrders;
+ private final List<QuerySortOrder> sortOrders;
private final Comparator<T> inMemorySorting;
private final F filter;
@@ -83,7 +83,7 @@ public class Query<T, F> implements Serializable {
* @param filter
* filtering for fetching; can be null
*/
- public Query(int offset, int limit, List<SortOrder<String>> sortOrders,
+ public Query(int offset, int limit, List<QuerySortOrder> sortOrders,
Comparator<T> inMemorySorting, F filter) {
this.offset = offset;
this.limit = limit;
@@ -123,7 +123,7 @@ public class Query<T, F> implements Serializable {
*
* @return list of sort orders
*/
- public List<SortOrder<String>> getSortOrders() {
+ public List<QuerySortOrder> getSortOrders() {
return sortOrders;
}
diff --git a/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java b/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java
new file mode 100644
index 0000000000..ca8d743fae
--- /dev/null
+++ b/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data.provider;
+
+import com.vaadin.shared.data.sort.SortDirection;
+
+/**
+ * Sorting information for {@link Query}.
+ *
+ * @see Query
+ */
+public class QuerySortOrder extends SortOrder<String> {
+
+ /**
+ * Constructs sorting information for usage in a {@link Query}.
+ *
+ * @param sorted
+ * sorting information, usually field id
+ * @param direction
+ * sorting direction
+ */
+ public QuerySortOrder(String sorted, SortDirection direction) {
+ super(sorted, direction);
+ }
+
+ /**
+ * Gets sorting information.
+ *
+ * @return sorting entity, usually field id
+ */
+ @Override
+ public String getSorted() {
+ return super.getSorted();
+ }
+}
diff --git a/server/src/main/java/com/vaadin/data/provider/Sort.java b/server/src/main/java/com/vaadin/data/provider/Sort.java
index 303ee05f74..0655c7d0e4 100644
--- a/server/src/main/java/com/vaadin/data/provider/Sort.java
+++ b/server/src/main/java/com/vaadin/data/provider/Sort.java
@@ -35,16 +35,14 @@ public abstract class Sort implements Serializable {
* lists. When the sort order is ready to be passed on, calling
* {@link #build()} will create the list of sort orders
*
- * @param <S>
- * sort order data type
*
* @see Sort
* @see Sort#asc(Object)
* @see Sort#desc(Object)
* @see #build()
*/
- public static class SortBuilder<S> implements Serializable {
- private List<SortOrder<S>> sortOrder = new ArrayList<>();
+ public static class SortBuilder implements Serializable {
+ private List<QuerySortOrder> sortOrder = new ArrayList<>();
/**
* Constructs an empty SortBuilder.
@@ -59,7 +57,7 @@ public abstract class Sort implements Serializable {
* the object to sort by
* @return this sort builder
*/
- public SortBuilder<S> thenAsc(S by) {
+ public SortBuilder thenAsc(String by) {
return append(by, SortDirection.ASCENDING);
}
@@ -70,7 +68,7 @@ public abstract class Sort implements Serializable {
* the object to sort by
* @return this sort builder
*/
- public SortBuilder<S> thenDesc(S by) {
+ public SortBuilder thenDesc(String by) {
return append(by, SortDirection.DESCENDING);
}
@@ -84,8 +82,8 @@ public abstract class Sort implements Serializable {
*
* @return this sort builder
*/
- protected SortBuilder<S> append(S by, SortDirection direction) {
- sortOrder.add(new SortOrder<>(by, direction));
+ protected SortBuilder append(String by, SortDirection direction) {
+ sortOrder.add(new QuerySortOrder(by, direction));
return this;
}
@@ -95,7 +93,7 @@ public abstract class Sort implements Serializable {
*
* @return the unmodifiable sort order list
*/
- public List<SortOrder<S>> build() {
+ public List<QuerySortOrder> build() {
return Collections.unmodifiableList(sortOrder);
}
}
@@ -111,8 +109,8 @@ public abstract class Sort implements Serializable {
*
* @return the sort builder
*/
- public static <S> SortBuilder<S> asc(S by) {
- return new SortBuilder<S>().thenAsc(by);
+ public static SortBuilder asc(String by) {
+ return new SortBuilder().thenAsc(by);
}
/**
@@ -126,7 +124,7 @@ public abstract class Sort implements Serializable {
*
* @return the sort builder
*/
- public static <S> SortBuilder<S> desc(S by) {
- return new SortBuilder<S>().thenDesc(by);
+ public static SortBuilder desc(String by) {
+ return new SortBuilder().thenDesc(by);
}
}
diff --git a/server/src/main/java/com/vaadin/data/provider/SortOrder.java b/server/src/main/java/com/vaadin/data/provider/SortOrder.java
index 34e560e2d1..cb6a62668a 100644
--- a/server/src/main/java/com/vaadin/data/provider/SortOrder.java
+++ b/server/src/main/java/com/vaadin/data/provider/SortOrder.java
@@ -22,7 +22,6 @@ import com.vaadin.shared.data.sort.SortDirection;
/**
* Sorting information for one field.
*
- * @see Query
* @param <T>
* the type of the sorting information, usually a String (field id)
* or a {@link java.util.Comparator}.
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index ae78d5486b..b3410c57f0 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -47,6 +47,7 @@ import com.vaadin.data.ValueProvider;
import com.vaadin.data.provider.DataCommunicator;
import com.vaadin.data.provider.DataProvider;
import com.vaadin.data.provider.Query;
+import com.vaadin.data.provider.QuerySortOrder;
import com.vaadin.data.provider.SortOrder;
import com.vaadin.event.ConnectorEvent;
import com.vaadin.event.ContextClickEvent;
@@ -122,8 +123,8 @@ import elemental.json.JsonValue;
* @param <T>
* the grid bean type
*/
-public class Grid<T> extends AbstractListing<T>
- implements HasComponents, HasDataProvider<T>, SortNotifier<Grid.Column<T, ?>> {
+public class Grid<T> extends AbstractListing<T> implements HasComponents,
+ HasDataProvider<T>, SortNotifier<Grid.Column<T, ?>> {
@Deprecated
private static final Method COLUMN_REORDER_METHOD = ReflectTools.findMethod(
@@ -787,8 +788,8 @@ public class Grid<T> extends AbstractListing<T>
private String userId;
/**
- * Constructs a new Column configuration with given renderer and
- * value provider.
+ * Constructs a new Column configuration with given renderer and value
+ * provider.
*
* @param valueProvider
* the function to get values from items
@@ -1078,14 +1079,14 @@ public class Grid<T> extends AbstractListing<T>
public Column<T, V> setSortProperty(String... properties) {
Objects.requireNonNull(properties, "Sort properties can't be null");
sortOrderProvider = dir -> Arrays.stream(properties)
- .map(s -> new SortOrder<>(s, dir));
+ .map(s -> new QuerySortOrder(s, dir));
return this;
}
/**
* Sets the sort orders when sorting this column. The sort order
- * provider is a function which provides {@link SortOrder} objects to
- * describe how to sort by this column.
+ * provider is a function which provides {@link QuerySortOrder} objects
+ * to describe how to sort by this column.
*
* @param provider
* the function to use when generating sort orders with the
@@ -1107,7 +1108,7 @@ public class Grid<T> extends AbstractListing<T>
* the sorting direction
* @return stream of sort orders
*/
- public Stream<SortOrder<String>> getSortOrder(SortDirection direction) {
+ public Stream<QuerySortOrder> getSortOrder(SortDirection direction) {
return sortOrderProvider.apply(direction);
}
@@ -2772,7 +2773,7 @@ public class Grid<T> extends AbstractListing<T>
}
/**
- * Sort this Grid in user-specified {@link SortOrder} by a column.
+ * Sort this Grid in user-specified {@link QuerySortOrder} by a column.
*
* @param column
* a column to sort against
@@ -3200,7 +3201,7 @@ public class Grid<T> extends AbstractListing<T>
getDataCommunicator().setInMemorySorting(comparator);
// Back-end sort properties
- List<SortOrder<String>> sortProperties = new ArrayList<>();
+ List<QuerySortOrder> sortProperties = new ArrayList<>();
sortOrder.stream().map(
order -> order.getSorted().getSortOrder(order.getDirection()))
.forEach(s -> s.forEach(sortProperties::add));
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java b/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java
index 046719e978..79cc9d4a4d 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java
@@ -17,7 +17,7 @@ package com.vaadin.ui.components.grid;
import java.util.stream.Stream;
-import com.vaadin.data.provider.SortOrder;
+import com.vaadin.data.provider.QuerySortOrder;
import com.vaadin.server.SerializableFunction;
import com.vaadin.shared.data.sort.SortDirection;
import com.vaadin.ui.Grid.Column;
@@ -32,7 +32,7 @@ import com.vaadin.ui.Grid.Column;
*/
@FunctionalInterface
public interface SortOrderProvider
- extends SerializableFunction<SortDirection, Stream<SortOrder<String>>> {
+ extends SerializableFunction<SortDirection, Stream<QuerySortOrder>> {
/**
* Generates the sort orders when rows are sorted by a column.
@@ -43,6 +43,6 @@ public interface SortOrderProvider
* @return sort information
*/
@Override
- public Stream<SortOrder<String>> apply(SortDirection sortDirection);
+ public Stream<QuerySortOrder> apply(SortDirection sortDirection);
}
diff --git a/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java b/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
index e2f5211d00..b91a6fe3af 100644
--- a/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
+++ b/server/src/test/java/com/vaadin/data/provider/BackendDataProviderTest.java
@@ -61,8 +61,9 @@ public class BackendDataProviderTest extends
}
@Override
- protected void setSortOrder(List<SortOrder<String>> sortOrder,
+ protected void setSortOrder(List<QuerySortOrder> sortOrder,
Comparator<StrBean> comp) {
getDataProvider().setSortOrders(sortOrder);
}
-}
+
+} \ No newline at end of file
diff --git a/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java b/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java
index 0aa9bb80ba..ebdcdd105c 100644
--- a/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java
+++ b/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java
@@ -2,7 +2,6 @@ package com.vaadin.data.provider;
import static org.junit.Assert.assertTrue;
-import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
@@ -49,25 +48,20 @@ public abstract class DataProviderTestBase<D extends DataProvider<StrBean, Seria
return dataProvider;
}
- protected abstract void setSortOrder(List<SortOrder<String>> sortOrder,
+ protected abstract void setSortOrder(List<QuerySortOrder> sortOrder,
Comparator<StrBean> comp);
private Query<StrBean, SerializablePredicate<StrBean>> createQuery(
- List<SortOrder<String>> sortOrder, Comparator<StrBean> comp) {
+ List<QuerySortOrder> sortOrder, Comparator<StrBean> comp) {
return createQuery(sortOrder, comp, null);
}
private Query<StrBean, SerializablePredicate<StrBean>> createQuery(
- List<SortOrder<String>> sortOrder, Comparator<StrBean> comp,
+ List<QuerySortOrder> sortOrder, Comparator<StrBean> comp,
SerializablePredicate<StrBean> filter) {
return new Query<>(0, Integer.MAX_VALUE, sortOrder, comp, filter);
}
- private Query<StrBean, SerializablePredicate<StrBean>> createQuery(
- SerializablePredicate<StrBean> filter) {
- return createQuery(Collections.emptyList(), null, filter);
- }
-
// Tests start here.
@Test
diff --git a/server/src/test/java/com/vaadin/data/provider/ListDataProviderTest.java b/server/src/test/java/com/vaadin/data/provider/ListDataProviderTest.java
index 7e32449628..1ffa444f50 100644
--- a/server/src/test/java/com/vaadin/data/provider/ListDataProviderTest.java
+++ b/server/src/test/java/com/vaadin/data/provider/ListDataProviderTest.java
@@ -218,7 +218,7 @@ public class ListDataProviderTest
}
@Override
- protected void setSortOrder(List<SortOrder<String>> sortOrder,
+ protected void setSortOrder(List<QuerySortOrder> sortOrder,
Comparator<StrBean> comp) {
SerializableComparator<StrBean> serializableComp = comp::compare;
getDataProvider().setSortComparator(serializableComp);
diff --git a/server/src/test/java/com/vaadin/data/provider/bov/DataProviderBoVTest.java b/server/src/test/java/com/vaadin/data/provider/bov/DataProviderBoVTest.java
index cecb6bf511..b8d659fc47 100644
--- a/server/src/test/java/com/vaadin/data/provider/bov/DataProviderBoVTest.java
+++ b/server/src/test/java/com/vaadin/data/provider/bov/DataProviderBoVTest.java
@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import com.vaadin.data.provider.DataProvider;
-import com.vaadin.data.provider.SortOrder;
+import com.vaadin.data.provider.QuerySortOrder;
import com.vaadin.shared.data.sort.SortDirection;
/**
@@ -133,7 +133,7 @@ public class DataProviderBoVTest {
// First callback fetches items based on a query
query -> {
List<PersonService.PersonSort> sortOrders = new ArrayList<>();
- for (SortOrder<String> queryOrder : query.getSortOrders()) {
+ for (QuerySortOrder queryOrder : query.getSortOrders()) {
PersonService.PersonSort sort = personService
.createSort(
// The name of the sorted property