com.vaadin.data.provider.Query类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(149)

本文整理了Java中com.vaadin.data.provider.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:com.vaadin.data.provider.Query
类名称:Query

Query介绍

[英]Immutable query object used to request data from a backend. Contains index limits, sorting and filtering information.
[中]用于从后端请求数据的不可变查询对象。包含索引限制、排序和筛选信息。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public int size(Query<T, F> t) {
  return dataProvider.size(new Query<>(t.getOffset(), t.getLimit(),
      t.getSortOrders(), t.getInMemorySorting(), getFilter(t)));
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Sets a CallbackDataProvider using the given fetch items callback and a
 * size callback.
 * <p>
 * This method is a shorthand for making a {@link CallbackDataProvider} that
 * handles a partial {@link com.vaadin.data.provider.Query Query} object.
 *
 * @param fetchItems
 *            a callback for fetching items
 * @param sizeCallback
 *            a callback for getting the count of items
 *
 * @see CallbackDataProvider
 * @see #setDataProvider(DataProvider)
 */
public void setDataProvider(FetchItemsCallback<T> fetchItems,
    SerializableToIntFunction<String> sizeCallback) {
  setDataProvider(new CallbackDataProvider<>(
      q -> fetchItems.fetchItems(q.getFilter().orElse(""),
          q.getOffset(), q.getLimit()),
      q -> sizeCallback.applyAsInt(q.getFilter().orElse(""))));
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public Stream<T> fetch(Query<T, SerializablePredicate<T>> query) {
  Stream<T> stream = getFilteredStream(query);
  Optional<Comparator<T>> comparing = Stream
      .of(query.getInMemorySorting(), sortOrder)
      .filter(c -> c != null)
      .reduce((c1, c2) -> c1.thenComparing(c2));
  if (comparing.isPresent()) {
    stream = stream.sorted(comparing.get());
  }
  return stream.skip(query.getOffset()).limit(query.getLimit());
}

代码示例来源:origin: jpos/jPOS-EE

@Override
public DataProvider getDataProvider() {
  Map<String,Boolean> orders = new HashMap<>();
  DataProvider dataProvider = DataProvider.fromCallbacks(
      (CallbackDataProvider.FetchCallback) query -> {
        int offset = query.getOffset();
        int limit = query.getLimit();
        for (Object o : query.getSortOrders()) {
          QuerySortOrder order = (QuerySortOrder) o;
          orders.put(order.getSorted(), order.getDirection() == SortDirection.DESCENDING);
        }
        User user = (User) query.getFilter().orElse(null);
        try {
          return getAll(offset,limit,orders,user);
        } catch (Exception e) {
          getApp().getLog().error(e);
          return null;
        }
      },
      (CallbackDataProvider.CountCallback) query -> {
        User user = (User) query.getFilter().orElse(null);
        try {
          return getItemCount(user);
        } catch (Exception e) {
          getApp().getLog().error(e);
          return 0;
        }
      });
  return (ConfigurableFilterDataProvider<Consumer,Void,User>) dataProvider.withConfigurableFilter();
}

代码示例来源:origin: com.haulmont.cuba/cuba-web

@Override
public Stream<T> fetch(Query<T, SerializablePredicate<T>> query) {
  if (dataGridItems.getState() == BindingState.INACTIVE) {
    return Stream.empty();
  }
  return dataGridItems.getItems()
      .skip(query.getOffset())
      .limit(query.getLimit());
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Sets a CallbackDataProvider using the given fetch items callback and a
 * size callback.
 * <p>
 * This method is a shorthand for making a {@link CallbackDataProvider} that
 * handles a partial {@link Query} object.
 *
 * @param fetchItems
 *            a callback for fetching items
 * @param sizeCallback
 *            a callback for getting the count of items
 *
 * @see CallbackDataProvider
 * @see #setDataProvider(DataProvider)
 */
public void setDataProvider(FetchItemsCallback<T> fetchItems,
    SerializableSupplier<Integer> sizeCallback) {
  internalSetDataProvider(
      new CallbackDataProvider<>(
          q -> fetchItems.fetchItems(q.getSortOrders(),
              q.getOffset(), q.getLimit()),
          q -> sizeCallback.get()));
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Fetch all items from the given data provider.
 *
 * @since 8.1
 * @param dataProvider
 *            the data provider to fetch from
 * @return all items in this data provider
 */
private Stream<T> fetchAll(DataProvider<T, ?> dataProvider) {
  return dataProvider.fetch(new Query<>());
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
  protected F getFilter(Query<T, C> query) {
    return query.getFilter().map(filterConverter).orElse(null);
  }
};

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin

query.getFilter().ifPresent(f -> filters.add(f));
sorts.addAll((query.getSortOrders() == null) ? Collections.emptyList()
    : query.getSortOrders().stream().map(o -> sortFromOrder(o))
        .flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty())
        .collect(Collectors.toList()));

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin

@Override
public QuerySort getQuerySort() {
  List<QuerySort> sorts = getDataProviderQuery().map(q -> q.getSortOrders())
      .orElse(Collections.emptyList()).stream().map(o -> sortFromOrder(o))
      .flatMap(o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty()).collect(Collectors.toList());
  return sorts.isEmpty() ? null : QuerySort.of(sorts);
}

代码示例来源:origin: jpos/jPOS-EE

@Override
public DataProvider getDataProvider() {
  Map<String,Boolean> orders = new HashMap<>();
  DataProvider dataProvider = DataProvider.fromCallbacks(
      (CallbackDataProvider.FetchCallback) query -> {
        int offset = query.getOffset();
        int limit = query.getLimit();
        for (Object o : query.getSortOrders()) {
          QuerySortOrder order = (QuerySortOrder) o;
          orders.put(order.getSorted(), order.getDirection() == SortDirection.DESCENDING);
        }
        DateRange dateRange = (DateRange) query.getFilter().orElse(null);
        try {
          return getAll(offset,limit,orders,defaultJournalId,dateRange);
        } catch (Exception e) {
          getApp().getLog().error(e);
          return null;
        }
      },
      (CallbackDataProvider.CountCallback) query -> {
        DateRange dateRange = (DateRange) query.getFilter().orElse(null);
        try {
          return getItemCount(defaultJournalId,dateRange);
        } catch (Exception e) {
          getApp().getLog().error(e);
          return 0;
        }
      });
  return (ConfigurableFilterDataProvider<GLTransaction,Void,DateRange>) dataProvider.withConfigurableFilter();
}

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin

@Override
protected Stream<ITEM> fetchFromBackEnd(Query<ITEM, QueryFilter> query) {
  getDataSource().setDataProviderQuery(query);
  if (query.getLimit() == Integer.MAX_VALUE) {
    return getAllItems().stream();
  }
  return getItemsByIndex(query.getOffset(), query.getLimit()).stream();
}

代码示例来源:origin: jpos/jPOS-EE

public DataProvider getParentDataProvider() {
  Map<String,Boolean> orders = new HashMap<>();
  DataProvider dataProvider = DataProvider.fromCallbacks(
      (CallbackDataProvider.FetchCallback) query -> {
        int offset = query.getOffset();
        int limit = query.getLimit();
        Iterator it = query.getSortOrders().iterator();
        while (it.hasNext()) {
          QuerySortOrder order = (QuerySortOrder) it.next();
          orders.put(order.getSorted(),order.getDirection() == SortDirection.DESCENDING);
        }
        try {
          return getPossibleParents(offset,limit,orders);
        } catch (Exception e) {
          getApp().getLog().error(e);
          return null;
        }
      },
      (CallbackDataProvider.CountCallback<Account, Void>) query -> {
        try {
          return getPossibleParentsCount();
        } catch (Exception e) {
          getApp().getLog().error(e);
          return 0;
        }
      });
  return dataProvider;
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Fetches a list of items from the DataProvider.
 *
 * @param offset
 *            the starting index of the range
 * @param limit
 *            the max number of results
 * @return the list of items in given range
 *
 * @since 8.1
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<T> fetchItemsWithRange(int offset, int limit) {
  return (List<T>) getDataProvider().fetch(new Query(offset, limit,
      backEndSorting, inMemorySorting, filter))
      .collect(Collectors.toList());
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
protected SerializablePredicate<T> getFilter(Query<T, C> query) {
  return query.getFilter().map(filterConverter).orElse(null);
}

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public Stream<T> fetch(Query<T, F> t) {
  return dataProvider.fetch(new Query<>(t.getOffset(), t.getLimit(),
      t.getSortOrders(), t.getInMemorySorting(), getFilter(t)));
}

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin

query.getFilter().ifPresent(f -> filters.add(f));
  final List<QuerySort> sorts = new LinkedList<>();
  List<QuerySortOrder> orders = query.getSortOrders();
  if (orders != null && !orders.isEmpty()) {
    orders.forEach(o -> sorts.add(fromOrder(getPropertySet(), o)));
if (query.getLimit() < Integer.MAX_VALUE) {
  q.limit(query.getLimit());
  q.offset(query.getOffset());

代码示例来源:origin: com.holon-platform.vaadin/holon-vaadin

@Override
protected Stream<ITEM> fetchFromBackEnd(Query<ITEM, QueryFilter> query) {
  return getDataProvider().load(getConfiguration(query), query.getOffset(), query.getLimit());
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * Writes the data source items to a design. Hierarchical select components
 * should override this method to only write the root items.
 *
 * @param design
 *            the element into which to insert the items
 * @param context
 *            the DesignContext instance used in writing
 */
protected void writeItems(Element design, DesignContext context) {
  internalGetDataProvider().fetch(new Query<>())
      .forEach(item -> writeItem(design, item, context));
}

代码示例来源:origin: com.vaadin/vaadin-server

private Stream<T> getFilteredStream(
    Query<T, SerializablePredicate<T>> query) {
  Stream<T> stream = backend.stream();
  // Apply our own filters first so that query filters never see the items
  // that would already have been filtered out
  if (filter != null) {
    stream = stream.filter(filter);
  }
  stream = query.getFilter().map(stream::filter).orElse(stream);
  return stream;
}

相关文章