* Use non-Generic SortOrder in Query.
Fixes #8215
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()) {
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
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();
* 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
* 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 {
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() {
}
/**
- * 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();
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;
* @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;
*
* @return list of sort orders
*/
- public List<SortOrder<String>> getSortOrders() {
+ public List<QuerySortOrder> getSortOrders() {
return sortOrders;
}
--- /dev/null
+/*
+ * 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();
+ }
+}
* 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.
* 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);
}
* 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);
}
*
* @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;
}
*
* @return the unmodifiable sort order list
*/
- public List<SortOrder<S>> build() {
+ public List<QuerySortOrder> build() {
return Collections.unmodifiableList(sortOrder);
}
}
*
* @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);
}
/**
*
* @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);
}
}
/**
* 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}.
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;
* @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(
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
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
* 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);
}
}
/**
- * 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
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));
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;
*/
@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.
* @return sort information
*/
@Override
- public Stream<SortOrder<String>> apply(SortDirection sortDirection);
+ public Stream<QuerySortOrder> apply(SortDirection sortDirection);
}
}
@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
import static org.junit.Assert.assertTrue;
-import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
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
}
@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);
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;
/**
// 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